summaryrefslogtreecommitdiff
path: root/lib/btrfs/btrfsvol/addr_test.go
blob: ad9d60d6767cf929707fdeaa304444d92167f32e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// Copyright (C) 2022  Luke Shumaker <lukeshu@lukeshu.com>
//
// SPDX-License-Identifier: GPL-2.0-or-later

package btrfsvol_test

import (
	"fmt"
	"testing"

	"github.com/stretchr/testify/assert"

	"git.lukeshu.com/btrfs-progs-ng/lib/btrfs/btrfsvol"
)

func TestAddrFormat(t *testing.T) {
	t.Parallel()
	type TestCase struct {
		InputAddr btrfsvol.LogicalAddr
		InputFmt  string
		Output    string
	}
	addr := btrfsvol.LogicalAddr(0x3a41678000)
	testcases := map[string]TestCase{
		"v":   {InputAddr: addr, InputFmt: "%v", Output: "0x0000003a41678000"},
		"s":   {InputAddr: addr, InputFmt: "%s", Output: "0x0000003a41678000"},
		"q":   {InputAddr: addr, InputFmt: "%q", Output: `"0x0000003a41678000"`},
		"x":   {InputAddr: addr, InputFmt: "%x", Output: "3a41678000"},
		"d":   {InputAddr: addr, InputFmt: "%d", Output: "250205405184"},
		"neg": {InputAddr: -1, InputFmt: "%v", Output: "-0x000000000000001"},
	}
	for tcName, tc := range testcases {
		tc := tc
		t.Run(tcName, func(t *testing.T) {
			t.Parallel()
			actual := fmt.Sprintf(tc.InputFmt, tc.InputAddr)
			assert.Equal(t, tc.Output, actual)
		})
	}
}