package muesli import ( _ "strings" "testing" ) func HelperFailOnErrors(ast Ast, expected int, test *testing.T) { if ast.IsNone() { test.Errorf("Parse failed, %d parse errors expected", expected) } errors := ast.Errors() if len(errors) != expected { test.Log("Parse errors:\n") for _, err := range errors { test.Logf("%s\n", err.String()) } test.Errorf("There were %d parse errors, %d expected", len(errors), expected) } } func HelperParseAndFailOnErrors(prog string, expected int, parsefunc func(*Parser) Ast, test *testing.T) { parser := NewParserFromString(prog) parser.SetLogger(&testLogger{}) ast := parsefunc(parser) HelperFailOnErrors(ast, expected, test) ast.Display() } func TestParser(test *testing.T) { com := `puts "hello" say ( add 5 10 ) .` parser := NewParserFromString(com) ast := parser.Parse() ast.Display() } func TestParser2(test *testing.T) { com := `puts "hello" say ( add 5 10 ) .` HelperParseAndFailOnErrors(com, 0, (*Parser).Parse, test) } func TestParenthesis(test *testing.T) { HelperParseAndFailOnErrors(`( add 5 10 ) `, 0, (*Parser).Parse, test) // HelperParseAndFailOnErrors(`( add 5 10 ) `, 0, (*Parser).ParseParenthesis, test) // HelperParseAndFailOnErrors(`add 5 10 `, 0, (*Parser).ParseCommand, test) } func TestParseLexerDesignFile(test *testing.T) { parser, err := NewParserFromFilename("design_muesli.muesli") if err != nil { test.Errorf("Error parsingfile : %s", err) return } parser.SetLogger(&testLogger{}) ast := parser.Parse() ast.Display() }