-
Notifications
You must be signed in to change notification settings - Fork 2
/
parser_test.go
50 lines (42 loc) · 888 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
package spiker_test
import (
"io/ioutil"
"testing"
"github.com/shockerli/spiker"
)
var srcTests = []string{
"testdata/assign.src",
"testdata/collect.src",
"testdata/function.src",
"testdata/operator.src",
"testdata/value.src",
}
func readFile(file string) string {
if src, err := ioutil.ReadFile(file); err == nil {
return string(src)
}
return ""
}
func BenchmarkStatements(b *testing.B) {
src := readFile("testdata/collect.src")
b.ResetTimer()
for n := 0; n < b.N; n++ {
lexer := spiker.NewLexer(src)
p := spiker.Parser{Lexer: lexer}
if _, err := p.Statements(); err != nil {
b.Log(err)
b.Fail()
}
}
}
func TestParser_Statements(t *testing.T) {
for _, file := range srcTests {
src := readFile(file)
lexer := spiker.NewLexer(src)
p := spiker.Parser{Lexer: lexer}
if _, err := p.Statements(); err != nil {
t.Log(err)
t.Fail()
}
}
}