-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparser_test.go
56 lines (47 loc) · 990 Bytes
/
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
package parser
import (
"testing"
"io/ioutil"
"encoding/json"
"fmt"
)
func TestParser(t *testing.T) {
samples := []string{
"quote",
"comma",
"folding",
"indent",
"line",
"parentheses",
"spaces",
"unfolding",
"demo",
"html",
"slash",
}
for _, sample := range(samples) {
cirruFile := fmt.Sprintf("./cirru/%s.cirru", sample)
jsonFile := fmt.Sprintf("./json/%s.json", sample)
b, _ := ioutil.ReadFile(cirruFile)
b2, _ := ioutil.ReadFile(jsonFile)
gotAst := ExampleNewParser(b)
wantedAst := string(b2)
if gotAst != wantedAst {
println(sample, "\t-- not matching, break:")
println(gotAst)
return
} else {
println(sample, "\t-- matches")
}
}
}
func ExampleNewParser(b []byte) string {
p := NewParser()
p.Filename("_")
for _, c := range b {
p.Read(rune(c))
}
p.Complete()
content, _ := json.MarshalIndent(p.ToTree(), "", " ")
return string(content)
}