-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgo_test.go
More file actions
42 lines (38 loc) · 1008 Bytes
/
go_test.go
File metadata and controls
42 lines (38 loc) · 1008 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
41
42
package parser
import "testing"
func TestParseGo_RootIsSourceFile(t *testing.T) {
src := []byte("package main\nfunc main() {}\n")
tree, err := Parse(LanguageGo, 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() != "source_file" {
t.Fatalf("root type = %q, want \"source_file\"", root.Type())
}
}
func TestParseByName_Go(t *testing.T) {
tree, err := ParseByName("go", []byte("package x\n"))
if err != nil {
t.Fatal(err)
}
defer tree.Close()
if tree.Root.RootNode().Type() != "source_file" {
t.Fatal("unexpected root type")
}
// "golang" alias should work too.
tree2, err := ParseByName("golang", []byte("package x\n"))
if err != nil {
t.Fatal(err)
}
defer tree2.Close()
}
func TestLanguageFromExtension_Go(t *testing.T) {
if got := LanguageFromExtension(".go"); got != LanguageGo {
t.Errorf("LanguageFromExtension(.go) = %v, want LanguageGo", got)
}
}