move scan and parse tests to eval
This commit is contained in:
parent
4fb02ed30b
commit
5c4b21406b
34
eval_test.go
34
eval_test.go
@ -2,10 +2,10 @@ package main
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// These inputs are used in scan and parse tests.
|
||||
var gEvalTests = []struct {
|
||||
inp string
|
||||
toks []string
|
||||
@ -360,6 +360,38 @@ var gEvalTests = []struct {
|
||||
},
|
||||
}
|
||||
|
||||
func TestScan(t *testing.T) {
|
||||
for _, test := range gEvalTests {
|
||||
s := newScanner(strings.NewReader(test.inp))
|
||||
|
||||
for _, tok := range test.toks {
|
||||
if s.scan(); s.tok != tok {
|
||||
t.Errorf("at input '%s' expected '%s' but scanned '%s'", test.inp, tok, s.tok)
|
||||
}
|
||||
}
|
||||
|
||||
if s.scan() {
|
||||
t.Errorf("at input '%s' unexpected '%s'", test.inp, s.tok)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestParse(t *testing.T) {
|
||||
for _, test := range gEvalTests {
|
||||
p := newParser(strings.NewReader(test.inp))
|
||||
|
||||
for _, expr := range test.exprs {
|
||||
if p.parse(); !reflect.DeepEqual(p.expr, expr) {
|
||||
t.Errorf("at input '%s' expected '%s' but parsed '%s'", test.inp, expr, p.expr)
|
||||
}
|
||||
}
|
||||
|
||||
if p.parse(); p.expr != nil {
|
||||
t.Errorf("at input '%s' unexpected '%s'", test.inp, p.expr)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSplitKeys(t *testing.T) {
|
||||
inps := []struct {
|
||||
s string
|
||||
|
@ -1,23 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestParse(t *testing.T) {
|
||||
for _, test := range gEvalTests {
|
||||
p := newParser(strings.NewReader(test.inp))
|
||||
|
||||
for _, expr := range test.exprs {
|
||||
if p.parse(); !reflect.DeepEqual(p.expr, expr) {
|
||||
t.Errorf("at input '%s' expected '%s' but parsed '%s'", test.inp, expr, p.expr)
|
||||
}
|
||||
}
|
||||
|
||||
if p.parse(); p.expr != nil {
|
||||
t.Errorf("at input '%s' unexpected '%s'", test.inp, p.expr)
|
||||
}
|
||||
}
|
||||
}
|
22
scan_test.go
22
scan_test.go
@ -1,22 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestScan(t *testing.T) {
|
||||
for _, test := range gEvalTests {
|
||||
s := newScanner(strings.NewReader(test.inp))
|
||||
|
||||
for _, tok := range test.toks {
|
||||
if s.scan(); s.tok != tok {
|
||||
t.Errorf("at input '%s' expected '%s' but scanned '%s'", test.inp, tok, s.tok)
|
||||
}
|
||||
}
|
||||
|
||||
if s.scan() {
|
||||
t.Errorf("at input '%s' unexpected '%s'", test.inp, s.tok)
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user