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:
parent
3903251f9a
commit
8cd2f8fd93
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user