diff options
Diffstat (limited to 'src/lib/go/parser_test.go')
-rw-r--r-- | src/lib/go/parser_test.go | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/src/lib/go/parser_test.go b/src/lib/go/parser_test.go new file mode 100644 index 000000000..715d464db --- /dev/null +++ b/src/lib/go/parser_test.go @@ -0,0 +1,47 @@ +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package parser + +import ( + "ast"; + "os"; + "parser"; + "testing"; +) + + +func TestParse0(t *testing.T) { + // test nil []bytes source + var src []byte; + prog, ok := Parse(src, nil, 0); + if ok { + t.Errorf("parse should have failed"); + } +} + + +func TestParse1(t *testing.T) { + // test string source + src := `package main import "fmt" func main() { fmt.Println("Hello, World!") }`; + prog, ok := Parse(src, nil, 0); + if !ok { + t.Errorf("parse failed"); + } +} + +func TestParse2(t *testing.T) { + // test io.Read source + filename := "parser_test.go"; + src, err := os.Open(filename, os.O_RDONLY, 0); + defer src.Close(); + if err != nil { + t.Errorf("cannot open %s (%s)\n", filename, err.String()); + } + + prog, ok := Parse(src, nil, 0); + if !ok { + t.Errorf("parse failed"); + } +} |