(t *testing.T)
| 16 | ) |
| 17 | |
| 18 | func TestPrintFile(t *testing.T) { |
| 19 | expected := `<?php |
| 20 | namespace Foo; |
| 21 | abstract 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) |
nothing calls this directly
no test coverage detected
searching dependent graphs…