MCPcopy Create free account
hub / github.com/adhocteam/pushup / TestCodeGenFromNode

Function TestCodeGenFromNode

codegen_test.go:9–50  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

7)
8
9func TestCodeGenFromNode(t *testing.T) {
10 tests := []struct {
11 node node
12 want string
13 }{
14 {
15 node: &nodeElement{
16 tag: tag{name: "div", attrs: []*attr{{name: stringPos{string: "id"}, value: stringPos{string: "foo"}}}},
17 startTagNodes: []node{
18 &nodeLiteral{str: "<div "},
19 &nodeLiteral{str: "id=\""},
20 &nodeLiteral{str: "foo"},
21 &nodeLiteral{str: "\">"},
22 },
23 children: []node{&nodeLiteral{str: "bar"}},
24 },
25 want: `io.WriteString(w, "<div ")
26io.WriteString(w, "id=\"")
27io.WriteString(w, "foo")
28io.WriteString(w, "\">")
29io.WriteString(w, "bar")
30io.WriteString(w, "</div>")
31`,
32 },
33 }
34
35 for _, test := range tests {
36 t.Run("", func(t *testing.T) {
37 page, err := newPageFromTree(&syntaxTree{nodes: []node{test.node}})
38 if err != nil {
39 t.Fatalf("new page from tree: %v", err)
40 }
41 g := newPageCodeGen(page, projectFile{}, "")
42 g.lineDirectivesEnabled = false
43 g.genNode(test.node)
44 got := g.bodyb.String()
45 if diff := cmp.Diff(test.want, got); diff != "" {
46 t.Errorf("expected code gen diff (-want +got):\n%s", diff)
47 }
48 })
49 }
50}
51
52func TestRouteForPage(t *testing.T) {
53 tests := []struct {

Callers

nothing calls this directly

Calls 4

newPageFromTreeFunction · 0.85
newPageCodeGenFunction · 0.85
genNodeMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected