-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathc_parser_test.go
More file actions
47 lines (45 loc) · 1.54 KB
/
Copy pathc_parser_test.go
File metadata and controls
47 lines (45 loc) · 1.54 KB
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
43
44
45
46
47
package codegraph
import (
"context"
"fmt"
"strings"
"testing"
"time"
)
// +link=https://github.com/odvcencio/gotreesitter/pull/1291
// +case=`Long C statement lists preserve complete function declarations through strict parsing`
func TestCLongStatementListDeclarations(t *testing.T) {
// Cross the parser's former 4096-depth conflict cutoff and verify that
// the declaration spans the complete body, rather than a partial tree.
var source strings.Builder
source.WriteString("void entry(void) {\n")
for i := range 8192 {
fmt.Fprintf(&source, "emit(\"x\", %d);\n", i)
}
source.WriteString("}\n")
entryEnd := source.Len() - 1
g, report, err := Build(context.Background(), "long-c", []Document{
{Path: "generated.c", Content: []byte(source.String())},
}, Options{ParseTimeout: 10 * time.Second})
if err != nil {
t.Fatal(err)
}
// C currently has declaration extraction only. Keep that coverage gap
// separate from the parser correctness this case exercises.
if !hasDiagnostic(report, "unsupported_resolution") {
t.Fatal(report)
}
for _, diagnostic := range report.Diagnostics {
if diagnostic.Code != "unsupported_resolution" {
t.Fatalf("unexpected diagnostic: %+v", diagnostic)
}
}
functions := g.Find("generated.c", Function, "")
if len(functions) != 1 {
t.Fatalf("got %d functions, want entry", len(functions))
}
got := functions[0]
if got.Name != "entry" || got.Location.StartByte != 0 || got.Location.EndByte != entryEnd {
t.Fatalf("incomplete function: %+v, location=%+v; want span 0..%d", got, got.Location, entryEnd)
}
}