-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparser_test.go
More file actions
40 lines (37 loc) · 926 Bytes
/
parser_test.go
File metadata and controls
40 lines (37 loc) · 926 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package parser
import (
"testing"
)
func TestParseJavaHelloWorld(t *testing.T) {
src := []byte(`public class Hello { public static void main(String[] args) { System.out.println("hi"); } }`)
tree, err := Parse(LanguageJava, src)
if err != nil {
t.Fatal(err)
}
defer tree.Close()
if tree.Root == nil {
t.Fatal("Root is nil")
}
root := tree.Root.RootNode()
if root.HasError() {
t.Fatalf("parse had errors: %s", root.String())
}
if root.Type() != "program" {
t.Fatalf("root type = %q, want \"program\"", root.Type())
}
}
func TestParsePythonHelloWorld(t *testing.T) {
src := []byte("def hi():\n print('hi')\n")
tree, err := Parse(LanguagePython, src)
if err != nil {
t.Fatal(err)
}
defer tree.Close()
root := tree.Root.RootNode()
if root.HasError() {
t.Fatalf("parse errors: %s", root.String())
}
if root.Type() != "module" {
t.Fatalf("root type = %q, want \"module\"", root.Type())
}
}