-
Notifications
You must be signed in to change notification settings - Fork 1
/
token_test.go
87 lines (76 loc) · 1.78 KB
/
token_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
package thrifter
import (
"testing"
"text/scanner"
)
func TestIsNumber_int(t *testing.T) {
isFloat, isInt := IsNumber(`123`)
if got, want := isInt, true; got != want {
t.Errorf("got [%v] want [%v]", got, want)
}
if got, want := isFloat, false; got != want {
t.Errorf("got [%v] want [%v]", got, want)
}
}
func TestIsNumber_float0(t *testing.T) {
isFloat, isInt := IsNumber(`123.123`)
if got, want := isInt, false; got != want {
t.Errorf("got [%v] want [%v]", got, want)
}
if got, want := isFloat, true; got != want {
t.Errorf("got [%v] want [%v]", got, want)
}
}
func TestIsNumber_float1(t *testing.T) {
isFloat, isInt := IsNumber(`0.123`)
if got, want := isInt, false; got != want {
t.Errorf("got [%v] want [%v]", got, want)
}
if got, want := isFloat, true; got != want {
t.Errorf("got [%v] want [%v]", got, want)
}
}
func TestIsNumber_invalidFloat(t *testing.T) {
isFloat, isInt := IsNumber(`.123`)
if got, want := isInt, false; got != want {
t.Errorf("got [%v] want [%v]", got, want)
}
if got, want := isFloat, false; got != want {
t.Errorf("got [%v] want [%v]", got, want)
}
}
func TestGenTokenHash(t *testing.T) {
hash1 := GenTokenHash(&Token{
Type: T_COMMENT,
Raw: "// asdasd",
Value: " asdasd",
Pos: scanner.Position{
Line: 1,
Column: 1,
},
})
hash2 := GenTokenHash(&Token{
Type: T_COMMENT,
Raw: "// asdasd",
Value: " asdasd",
Pos: scanner.Position{
Line: 1,
Column: 1,
},
})
hash3 := GenTokenHash(&Token{
Type: T_COMMENT,
Raw: "// asdasd",
Value: " asdasd",
Pos: scanner.Position{
Line: 3,
Column: 1,
},
})
if got, want := hash1, hash2; got != want {
t.Errorf("got [%v] want [%v]", got, want)
}
if got, want := hash1, hash3; got == want {
t.Errorf("got [%v] want [%v]", got, want)
}
}