Debian Codegraph @

example/calc/calc_test.go

raw symbols SCIP
1 package calc
2
3 import (
4 "testing"
5
6 "github.com/goccmack/gocc/example/calc/lexer"
7 "github.com/goccmack/gocc/example/calc/parser"
8 )
9
10 type TI struct {
11 src string
12 expect int64
13 }
14
15 var testData = []*TI{
16 {"1 + 1", 2},
17 {"1 * 1", 1},
18 {"1 + 2 * 3", 7},
19 }
20
21 func Test1(t *testing.T) {
22 p := parser.NewParser()
23 for _, ts := range testData {
24 s := lexer.NewLexer([]byte(ts.src))
25 sum, err := p.Parse(s)
26 if err != nil {
27 t.Error(err)
28 }
29 if sum != ts.expect {
30 t.Errorf("Error: %s = %d. Expected %d\n", ts.src, sum, ts.expect)
31 }
32 }
33 }