MCPcopy Create free account
hub / github.com/z7zmey/php-parser / TestPrinterPrintFile

Function TestPrinterPrintFile

printer/printer_test.go:19–71  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

17)
18
19func TestPrinterPrintFile(t *testing.T) {
20 o := bytes.NewBufferString("")
21
22 p := printer.NewPrinter(o)
23 p.Print(&node.Root{
24 Stmts: []node.Node{
25 &stmt.Namespace{
26 NamespaceName: &name.Name{
27 Parts: []node.Node{
28 &name.NamePart{Value: "Foo"},
29 },
30 },
31 },
32 &stmt.Class{
33 Modifiers: []node.Node{&node.Identifier{Value: "abstract"}},
34 ClassName: &name.Name{
35 Parts: []node.Node{
36 &name.NamePart{Value: "Bar"},
37 },
38 },
39 Extends: &stmt.ClassExtends{
40 ClassName: &name.Name{
41 Parts: []node.Node{
42 &name.NamePart{Value: "Baz"},
43 },
44 },
45 },
46 Stmts: []node.Node{
47 &stmt.ClassMethod{
48 Modifiers: []node.Node{&node.Identifier{Value: "public"}},
49 MethodName: &node.Identifier{Value: "greet"},
50 Stmt: &stmt.StmtList{
51 Stmts: []node.Node{
52 &stmt.Echo{
53 Exprs: []node.Node{
54 &scalar.String{Value: "'Hello world'"},
55 },
56 },
57 },
58 },
59 },
60 },
61 },
62 },
63 })
64
65 expected := `<?php namespace Foo;abstract class Bar extends Baz{public function greet(){echo 'Hello world';}}`
66 actual := o.String()
67
68 if expected != actual {
69 t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
70 }
71}
72
73func TestPrinterPrintFileInlineHtml(t *testing.T) {
74 o := bytes.NewBufferString("")

Callers

nothing calls this directly

Calls 3

PrintMethod · 0.95
NewPrinterFunction · 0.92
StringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…