1
0
mirror of https://github.com/robertkrimen/otto synced 2025-10-05 19:19:10 +08:00

[#148] Added test parser to set mode

This commit is contained in:
wolfgarnet 2016-01-12 10:17:29 +01:00
parent 3903251f9a
commit 8cd2f8fd93
2 changed files with 6 additions and 1 deletions

View File

@ -34,7 +34,7 @@ func displayStatements(statements []ast.Statement) {
func TestParser_comments(t *testing.T) {
tt(t, func() {
test := func(source string, chk interface{}) (*_parser, *ast.Program) {
parser, program, err := testParse(source)
parser, program, err := testParseWithMode(source, StoreComments)
is(firstErr(err), chk)
// Check unresolved comments

View File

@ -22,6 +22,10 @@ func firstErr(err error) error {
var matchBeforeAfterSeparator = regexp.MustCompile(`(?m)^[ \t]*---$`)
func testParse(src string) (parser *_parser, program *ast.Program, err error) {
return testParseWithMode(src, 0)
}
func testParseWithMode(src string, mode Mode) (parser *_parser, program *ast.Program, err error) {
defer func() {
if tmp := recover(); tmp != nil {
switch tmp := tmp.(type) {
@ -37,6 +41,7 @@ func testParse(src string) (parser *_parser, program *ast.Program, err error) {
}
}()
parser = newParser("", src)
parser.mode = mode
program, err = parser.parse()
return
}