-
Notifications
You must be signed in to change notification settings - Fork 4
/
bitarray_format_test.go
97 lines (84 loc) · 4.17 KB
/
bitarray_format_test.go
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// Copyright (c) 2021 Hirotsuna Mizuno. All rights reserved.
// Use of this source code is governed by the MIT license that can be found in
// the LICENSE file.
package bitarray_test
import (
"fmt"
"testing"
"github.com/tunabay/go-bitarray"
)
func TestBitArray_Format_sprintf(t *testing.T) {
ba := bitarray.MustParse("0000-1111 0101-0000 1010-1111 1001-0")
tcs := [][]string{
{"%b", "00001111010100001010111110010"},
{"%s", "00001111010100001010111110010"},
{"%v", "00001111010100001010111110010"},
{"% b", "00001111 01010000 10101111 10010"},
{"%#b", "0000-1111 0101-0000 1010-1111 1001-0"},
{"%# b", "0000-1111 0101-0000 1010-1111 1001-0"},
{"%q", `"00001111010100001010111110010"`},
{"% q", `"00001111 01010000 10101111 10010"`},
{"%#q", `"0000-1111 0101-0000 1010-1111 1001-0"`},
{"%o", "0365025744"},
{"% o", "03650257 44"},
{"%+o", "0365025744(pad=1)"},
{"%+ o", "03650257 44 (pad=1)"},
{"% +o", "03650257 44 (pad=1)"},
{"%#o", "0365-0257 44"},
{"%#+o", "0365-0257 44 (pad=1)"},
{"%x", "0f50af90"},
{"%X", "0F50AF90"},
{"% x", "0f50af90"},
{"%#x", "0f50 af90"},
{"%+x", "0f50af90(pad=3)"},
{"%#+x", "0f50 af90 (pad=3)"},
{"[%50b]", "[ 00001111010100001010111110010]"},
{"[%-50b]", "[00001111010100001010111110010 ]"},
{"[% 50b]", "[ 00001111 01010000 10101111 10010]"},
{"[% -50b]", "[00001111 01010000 10101111 10010 ]"},
{"[%#50b]", "[ 0000-1111 0101-0000 1010-1111 1001-0]"},
{"[%#-50b]", "[0000-1111 0101-0000 1010-1111 1001-0 ]"},
{"[%50q]", `[ "00001111010100001010111110010"]`},
{"[%-50q]", `["00001111010100001010111110010" ]`},
{"[% 50q]", `[ "00001111 01010000 10101111 10010"]`},
{"[% -50q]", `["00001111 01010000 10101111 10010" ]`},
{"[%#50q]", `[ "0000-1111 0101-0000 1010-1111 1001-0"]`},
{"[%#-50q]", `["0000-1111 0101-0000 1010-1111 1001-0" ]`},
{"[%50x]", "[ 0f50af90]"},
{"[%-50x]", "[0f50af90 ]"},
{"[%#50x]", "[ 0f50 af90]"},
{"[%#-50x]", "[0f50 af90 ]"},
{"[%#+50x]", "[ 0f50 af90 (pad=3)]"},
{"[%#+-50x]", "[0f50 af90 (pad=3) ]"},
{"[%50o]", "[ 0365025744]"},
{"[%-50o]", "[0365025744 ]"},
{"[% 50o]", "[ 03650257 44]"},
{"[% -50o]", "[03650257 44 ]"},
{"[%#50o]", "[ 0365-0257 44]"},
{"[%#-50o]", "[0365-0257 44 ]"},
{"[%+50o]", "[ 0365025744(pad=1)]"},
{"[%+-50o]", "[0365025744(pad=1) ]"},
{"[% +50o]", "[ 03650257 44 (pad=1)]"},
{"[% +-50o]", "[03650257 44 (pad=1) ]"},
{"[%#+50o]", "[ 0365-0257 44 (pad=1)]"},
{"[%#+-50o]", "[0365-0257 44 (pad=1) ]"},
// errors
{"%z", `%!z(BitArray="0000-1111 0101-0000 1010-1111 1001-0")`}, // unknown verb z
{"%m", `%!m(BitArray="0000-1111 0101-0000 1010-1111 1001-0")`}, // unknown verb m
{"%010b", `%!b(ERROR: unsupported flag 0)`}, // 0 flag for b
{"%010s", `%!s(ERROR: unsupported flag 0)`}, // 0 flag for s
{"%010q", `%!q(ERROR: unsupported flag 0)`}, // 0 flag for q
{"%010o", `%!o(ERROR: unsupported flag 0)`}, // 0 flag for o
{"%010x", `%!x(ERROR: unsupported flag 0)`}, // 0 flag for x
{"%010X", `%!X(ERROR: unsupported flag 0)`}, // 0 flag for X
{"%#v", `%!v(ERROR: unsupported flag #)`}, // # flag for v
}
for _, tc := range tcs {
s := fmt.Sprintf(tc[0], ba)
if s != tc[1] {
t.Errorf("unexpected output for %q", tc[0])
t.Logf(" got: %q", s)
t.Logf("want: %q", tc[1])
}
}
}