-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparse_internal_test.go
More file actions
67 lines (52 loc) · 1.45 KB
/
parse_internal_test.go
File metadata and controls
67 lines (52 loc) · 1.45 KB
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
/*
Szerszam argument library: szargs.
Copyright (C) 2025 Leslie Dancsecs
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package szargs
import (
"testing"
"github.com/dancsecs/sztestlog"
)
func TestArgs_IntBase(t *testing.T) {
chk := sztestlog.CaptureNothing(t)
defer chk.Release()
const (
base2 = 2
base8 = 8
base10 = 10
base16 = 16
)
tst := func(rawStr, clnStr string, base int) {
t.Helper()
s, b := intBase(rawStr)
chk.Str(s, clnStr)
chk.Int(b, base)
}
// Base2
tst("0B1", "1", base2)
tst("0b101", "101", base2)
// Base8
tst("0O7", "7", base8)
tst("0o123", "123", base8)
// Base8 - Single leading 0.
tst("00", "0", base8)
tst("01", "1", base8)
tst("0b", "b", base8)
// Base10
tst("0", "0", base10)
tst("1", "1", base10)
tst("123456", "123456", base10)
// Base16
tst("0Xa", "a", base16)
tst("0xabc", "abc", base16)
}