|
@@ -6,6 +6,10 @@ import (
|
|
)
|
|
)
|
|
|
|
|
|
func HelperFailOnErrors(ast * Ast, expected int, test *testing.T) {
|
|
func HelperFailOnErrors(ast * Ast, expected int, test *testing.T) {
|
|
|
|
+ if ast == nil {
|
|
|
|
+ test.Errorf("Parse failed, AST is nil.")
|
|
|
|
+ return
|
|
|
|
+ }
|
|
if ast.IsNone() {
|
|
if ast.IsNone() {
|
|
test.Errorf("Parse failed, %d parse errors expected", expected)
|
|
test.Errorf("Parse failed, %d parse errors expected", expected)
|
|
}
|
|
}
|
|
@@ -21,11 +25,20 @@ func HelperFailOnErrors(ast * Ast, expected int, test *testing.T) {
|
|
|
|
|
|
func HelperParseAndFailOnErrors(prog string, expected int,
|
|
func HelperParseAndFailOnErrors(prog string, expected int,
|
|
parsefunc func(*Parser) *Ast, test *testing.T) {
|
|
parsefunc func(*Parser) *Ast, test *testing.T) {
|
|
|
|
+ defer func(){
|
|
|
|
+ err := recover()
|
|
|
|
+ if err != nil {
|
|
|
|
+ test.Errorf("Parse error: %s", err)
|
|
|
|
+ }
|
|
|
|
+ }()
|
|
|
|
+
|
|
parser := NewParserFromString(prog)
|
|
parser := NewParserFromString(prog)
|
|
parser.SetLogger(&testLogger{})
|
|
parser.SetLogger(&testLogger{})
|
|
ast := parsefunc(parser)
|
|
ast := parsefunc(parser)
|
|
HelperFailOnErrors(ast, expected, test)
|
|
HelperFailOnErrors(ast, expected, test)
|
|
- ast.Display()
|
|
|
|
|
|
+ if ast != nil {
|
|
|
|
+ ast.Display()
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
func TestParser(test *testing.T) {
|
|
func TestParser(test *testing.T) {
|
|
@@ -33,7 +46,9 @@ func TestParser(test *testing.T) {
|
|
say ( add 5 10 ) .`
|
|
say ( add 5 10 ) .`
|
|
parser := NewParserFromString(com)
|
|
parser := NewParserFromString(com)
|
|
ast := parser.Parse()
|
|
ast := parser.Parse()
|
|
- ast.Display()
|
|
|
|
|
|
+ if ast != nil {
|
|
|
|
+ ast.Display()
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
func TestParser2(test *testing.T) {
|
|
func TestParser2(test *testing.T) {
|
|
@@ -70,7 +85,9 @@ func TestParseDesignFile(test *testing.T) {
|
|
}
|
|
}
|
|
parser.SetLogger(&testLogger{})
|
|
parser.SetLogger(&testLogger{})
|
|
ast := parser.Parse()
|
|
ast := parser.Parse()
|
|
- ast.Display()
|
|
|
|
|
|
+ if ast != nil {
|
|
|
|
+ ast.Display()
|
|
|
|
+ }
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|