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

Function TestPrintFile

printer/pretty_printer_test.go:18–84  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 3

PrintMethod · 0.95
NewPrettyPrinterFunction · 0.92
StringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…