-
Notifications
You must be signed in to change notification settings - Fork 0
/
parser_test.go
118 lines (113 loc) · 2.08 KB
/
parser_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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
package igc
import (
"fmt"
"testing"
"github.com/alecthomas/assert/v2"
)
func TestAtoi(t *testing.T) {
for _, tc := range []struct {
dataStr string
expected int
expectedErr string
}{
{
dataStr: "",
expectedErr: `"": syntax error`,
},
{
dataStr: "1",
expected: 1,
},
{
dataStr: "12",
expected: 12,
},
{
dataStr: "-",
expectedErr: `"-": syntax error`,
},
{
dataStr: "-1",
expected: -1,
},
{
dataStr: "12",
expected: 12,
},
} {
t.Run(tc.dataStr, func(t *testing.T) {
actual, actualErr := atoi([]byte(tc.dataStr))
assert.Equal(t, tc.expected, actual)
assert.EqualError(t, actualErr, tc.expectedErr)
})
}
}
func TestIntPow(t *testing.T) {
for _, tc := range []struct {
x int
y int
expected int
}{
{x: 1, y: 0, expected: 1},
{x: 1, y: 1, expected: 1},
{x: 1, y: 2, expected: 1},
{x: 2, y: 0, expected: 1},
{x: 2, y: 1, expected: 2},
{x: 2, y: 2, expected: 4},
{x: 2, y: 3, expected: 8},
{x: 3, y: 0, expected: 1},
{x: 3, y: 1, expected: 3},
{x: 3, y: 2, expected: 9},
{x: 3, y: 3, expected: 27},
} {
t.Run(fmt.Sprintf("intPow(%d, %d)", tc.x, tc.y), func(t *testing.T) {
assert.Equal(t, tc.expected, intPow(tc.x, tc.y))
})
}
}
func TestReservedCharacters(t *testing.T) {
for c, expected := range map[byte]bool{
'\r': true,
'\n': true,
' ': false,
'!': true,
'"': false,
'#': false,
'$': true,
'%': false,
'&': false,
'\'': false,
'(': false,
')': false,
'0': false,
'9': false,
':': false,
';': false,
'<': false,
'=': false,
'>': false,
'?': false,
'@': false,
'A': false,
'Z': false,
'[': false,
'\\': true,
']': false,
'^': true,
'_': false,
'`': false,
'a': false,
'z': false,
'{': false,
'|': false,
'}': false,
'~': true,
'*': true,
'\x80': true,
'\xff': true,
} {
t.Run(string(c), func(t *testing.T) {
assert.Equal(t, expected, invalidCharsRx.MatchString(string(c)))
})
}
}