move scan and parse tests to eval
This commit is contained in:
1 parent
4fb02ed30b
commit
5c4b21406b
3 files changed
+33
-46
No files matched your search
+33
-1
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user