forked from gookit/goutil
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtokens_test.go
43 lines (37 loc) · 1.2 KB
/
tokens_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
package textscan_test
import (
"testing"
"github.com/gookit/goutil/strutil/textscan"
"github.com/gookit/goutil/testutil/assert"
)
func TestAddKind(t *testing.T) {
nk := textscan.Kind(99)
assert.False(t, textscan.HasKind(nk))
textscan.AddKind(nk, "Kind99")
assert.True(t, textscan.HasKind(nk))
assert.Eq(t, "Kind99", textscan.KindString(nk))
assert.Panics(t, func() {
textscan.AddKind(nk, "Kind99")
})
}
func TestNewStringToken(t *testing.T) {
tok := textscan.NewStringToken(textscan.TokKey, "key2")
assert.False(t, tok.HasMore())
assert.NoErr(t, tok.ScanMore(nil))
assert.Err(t, tok.MergeSame(nil))
assert.True(t, tok.IsValid())
assert.True(t, textscan.IsKindToken(textscan.TokKey, tok))
assert.Eq(t, textscan.TokKey.String(), tok.Kind().String())
assert.Eq(t, "key2", tok.Value())
assert.Eq(t, "key2", tok.String())
}
func TestNewEmptyToken(t *testing.T) {
tok := textscan.NewEmptyToken()
assert.False(t, tok.HasMore())
assert.NoErr(t, tok.ScanMore(nil))
assert.Err(t, tok.MergeSame(nil))
assert.False(t, tok.IsValid())
assert.True(t, textscan.IsKindToken(textscan.TokInvalid, tok))
assert.Eq(t, textscan.TokInvalid.String(), tok.Kind().String())
assert.Eq(t, "<Invalid>", tok.String())
}