From 5c4b21406bad200a02db8d3fc35661df747a77b5 Mon Sep 17 00:00:00 2001 From: Gokcehan Date: Sun, 17 Sep 2017 15:05:29 +0300 Subject: [PATCH] move scan and parse tests to eval --- eval_test.go | 34 +++++++++++++++++++++++++++++++++- parse_test.go | 23 ----------------------- scan_test.go | 22 ---------------------- 3 files changed, 33 insertions(+), 46 deletions(-) delete mode 100644 parse_test.go delete mode 100644 scan_test.go diff --git a/eval_test.go b/eval_test.go index 1a15a7b..cfbb65b 100644 --- a/eval_test.go +++ b/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 diff --git a/parse_test.go b/parse_test.go deleted file mode 100644 index 970f6b7..0000000 --- a/parse_test.go +++ /dev/null @@ -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) - } - } -} diff --git a/scan_test.go b/scan_test.go deleted file mode 100644 index e8785f5..0000000 --- a/scan_test.go +++ /dev/null @@ -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) - } - } -}