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

Function TestPrinterPrintIfExpression

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

Source from the content-addressed store, hash-verified

3718}
3719
3720func TestPrinterPrintIfExpression(t *testing.T) {
3721 o := bytes.NewBufferString("")
3722
3723 p := printer.NewPrinter(o)
3724 p.Print(&stmt.If{
3725 Cond: &expr.Variable{
3726 VarName: &node.Identifier{Value: "a"},
3727 },
3728 Stmt: &stmt.Expression{
3729 Expr: &expr.Variable{
3730 VarName: &node.Identifier{Value: "b"},
3731 },
3732 },
3733 ElseIf: []node.Node{
3734 &stmt.ElseIf{
3735 Cond: &expr.Variable{
3736 VarName: &node.Identifier{Value: "c"},
3737 },
3738 Stmt: &stmt.StmtList{
3739 Stmts: []node.Node{
3740 &stmt.Expression{
3741 Expr: &expr.Variable{
3742 VarName: &node.Identifier{Value: "d"},
3743 },
3744 },
3745 },
3746 },
3747 },
3748 &stmt.ElseIf{
3749 Cond: &expr.Variable{
3750 VarName: &node.Identifier{Value: "e"},
3751 },
3752 Stmt: &stmt.Nop{},
3753 },
3754 },
3755 Else: &stmt.Else{
3756 Stmt: &stmt.Expression{
3757 Expr: &expr.Variable{
3758 VarName: &node.Identifier{Value: "f"},
3759 },
3760 },
3761 },
3762 })
3763
3764 expected := `if($a)$b;elseif($c){$d;}elseif($e);else $f;`
3765 actual := o.String()
3766
3767 if expected != actual {
3768 t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
3769 }
3770}
3771
3772func TestPrinterPrintIfStmtList(t *testing.T) {
3773 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…