-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprog_test.go
53 lines (42 loc) · 977 Bytes
/
prog_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
package bcl_test
import (
"bytes"
"io"
"reflect"
"testing"
"github.com/wkhere/bcl"
)
func testDumpLoad(input []byte, t *testing.T) {
t.Helper()
prog, err := bcl.Parse(input, "input", bcl.OptOutput(io.Discard))
if err != nil {
t.Errorf("parse error: %v", err)
return
}
b := new(bytes.Buffer)
err = prog.Dump(b)
if err != nil {
t.Errorf("dump error: %v", err)
}
prog2, err := bcl.LoadProg(b, "input", bcl.OptOutput(io.Discard))
if err != nil {
t.Errorf("load error: %v", err)
}
if !reflect.DeepEqual(prog2, prog) {
t.Errorf("progs not equal")
}
}
func TestBasicDumpLoad(t *testing.T) {
testDumpLoad(basicInput, t)
}
func benchDumpLoad(input []byte, b *testing.B) {
prog, _ := bcl.Parse(input, "input", bcl.OptOutput(io.Discard))
for i := 0; i < b.N; i++ {
buf := new(bytes.Buffer)
prog.Dump(buf)
bcl.LoadProg(buf, "input", bcl.OptOutput(io.Discard))
}
}
func BenchmarkBasicDumpLoad(b *testing.B) {
benchDumpLoad(basicInput, b)
}