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

Function TestPrinterPrintStmtSwitch

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

Source from the content-addressed store, hash-verified

4124}
4125
4126func TestPrinterPrintStmtSwitch(t *testing.T) {
4127 o := bytes.NewBufferString("")
4128
4129 p := printer.NewPrinter(o)
4130 p.Print(&stmt.Switch{
4131 Cond: &expr.Variable{
4132 VarName: &node.Identifier{Value: "var"},
4133 },
4134 CaseList: &stmt.CaseList{
4135 Cases: []node.Node{
4136 &stmt.Case{
4137 Cond: &scalar.String{Value: "'a'"},
4138 Stmts: []node.Node{
4139 &stmt.Expression{Expr: &expr.Variable{
4140 VarName: &node.Identifier{Value: "a"},
4141 }},
4142 },
4143 },
4144 &stmt.Case{
4145 Cond: &scalar.String{Value: "'b'"},
4146 Stmts: []node.Node{
4147 &stmt.Expression{Expr: &expr.Variable{
4148 VarName: &node.Identifier{Value: "b"},
4149 }},
4150 },
4151 },
4152 },
4153 },
4154 })
4155
4156 expected := `switch($var){case 'a':$a;case 'b':$b;}`
4157 actual := o.String()
4158
4159 if expected != actual {
4160 t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
4161 }
4162}
4163
4164func TestPrinterPrintStmtThrow(t *testing.T) {
4165 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…