-
Notifications
You must be signed in to change notification settings - Fork 0
/
scanner_test.go
69 lines (61 loc) · 1.52 KB
/
scanner_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
package lit
import (
"bytes"
"testing"
)
func TestScanner(t *testing.T) {
source := []byte(`# test source
echo hello
` + "```foo bar" + `
echo world
` + "```")
tokens := Scanner(source)
if len(tokens) != 5 {
t.Errorf("tokens length not equal (has: %v must: 5)", len(tokens))
}
if tokens[0].Type != "DOC" {
t.Error("token Type not DOC")
}
if tokens[0].Decl != "" {
t.Error("token Decl not empty")
}
if !bytes.Equal(tokens[0].Value, []byte("# test source")) {
t.Errorf("token Value not equal (%s)", tokens[1].Value)
}
if tokens[1].Type != "CODE" {
t.Error("token Type not CODE")
}
if tokens[1].Decl != "" {
t.Error("token Decl not empty")
}
if !bytes.Equal(tokens[1].Value, []byte("echo hello")) {
t.Errorf("token Value not equal (%s)", tokens[1].Value)
}
if tokens[2].Type != "CODESIGN" {
t.Error("token Type not CODESIGN")
}
if tokens[2].Decl != "bar" {
t.Error("token Decl not bar")
}
if !bytes.Equal(tokens[2].Value, []byte("```foo bar")) {
t.Errorf("token Value not equal (%s)", tokens[2].Value)
}
if tokens[3].Type != "CODE" {
t.Error("token Type not CODE")
}
if tokens[3].Decl != "" {
t.Error("token Type not equal")
}
if !bytes.Equal(tokens[3].Value, []byte("echo world")) {
t.Errorf("token Value not equal (%s)", tokens[3].Value)
}
if tokens[4].Type != "CODESIGN" {
t.Error("token Type not CODESIGN")
}
if tokens[4].Decl != "" {
t.Error("token Type not equal")
}
if !bytes.Equal(tokens[4].Value, []byte("```")) {
t.Errorf("token Value not equal (%s)", tokens[4].Value)
}
}