From 8db7bed06505569c1b41a338b5131cfd5c9d1f28 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sun, 26 Jun 2022 20:25:27 -0600 Subject: tidy up which package things are in --- pkg/btrfs/btrfsvol/addr_test.go | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 pkg/btrfs/btrfsvol/addr_test.go (limited to 'pkg/btrfs/btrfsvol/addr_test.go') diff --git a/pkg/btrfs/btrfsvol/addr_test.go b/pkg/btrfs/btrfsvol/addr_test.go new file mode 100644 index 0000000..83af1ac --- /dev/null +++ b/pkg/btrfs/btrfsvol/addr_test.go @@ -0,0 +1,36 @@ +package btrfsvol_test + +import ( + "fmt" + "testing" + + "github.com/stretchr/testify/assert" + + "lukeshu.com/btrfs-tools/pkg/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": TestCase{InputAddr: addr, InputFmt: "%v", Output: "0x0000003a41678000"}, + "s": TestCase{InputAddr: addr, InputFmt: "%s", Output: "0x0000003a41678000"}, + "q": TestCase{InputAddr: addr, InputFmt: "%q", Output: `"0x0000003a41678000"`}, + "x": TestCase{InputAddr: addr, InputFmt: "%x", Output: "3a41678000"}, + "d": TestCase{InputAddr: addr, InputFmt: "%d", Output: "250205405184"}, + "neg": TestCase{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) + }) + } +} -- cgit v1.2.3-2-g168b