MCPcopy
hub / github.com/BishopFox/jsluice / TestCollapsedString

Function TestCollapsedString

tree_test.go:11–45  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

9)
10
11func TestCollapsedString(t *testing.T) {
12 cases := []struct {
13 JS []byte
14 Expected string
15 }{
16 {[]byte(`"./login.php?redirect="+url`), "./login.php?redirect=EXPR"},
17 {[]byte(`'/path/'+['one', 'two', 'three'].join('/')`), "/path/EXPR"},
18 {[]byte(`someVar`), "EXPR"},
19 }
20
21 parser := sitter.NewParser()
22 parser.SetLanguage(javascript.GetLanguage())
23
24 for i, c := range cases {
25 t.Run(strconv.Itoa(i), func(t *testing.T) {
26 tree := parser.Parse(nil, c.JS)
27 root := NewNode(tree.RootNode(), c.JS)
28
29 // Example tree:
30 // program
31 // expression_statement
32 // binary_expression
33 // left: string ("./login.php?redirect=")
34 // right: identifier (url)
35 //
36 // We want the binary_expression to pass to CollapsedString, which is
37 // the first Named Child of the first Named Child of the root node.
38 actual := root.NamedChild(0).NamedChild(0).CollapsedString()
39
40 if actual != c.Expected {
41 t.Errorf("want %s for CollapsedString(%s), have: %s", c.Expected, c.JS, actual)
42 }
43 })
44 }
45}

Callers

nothing calls this directly

Calls 4

NamedChildMethod · 0.95
NewNodeFunction · 0.85
RootNodeMethod · 0.80
CollapsedStringMethod · 0.80

Tested by

no test coverage detected