move scan and parse tests to eval

This commit is contained in:
Gokcehan 2017-09-17 15:05:29 +03:00
parent 4fb02ed30b
commit 5c4b21406b
3 changed files with 33 additions and 46 deletions

View File

@ -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

View File

@ -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)
}
}
}

View File

@ -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)
}
}
}