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

Function TestPrintStmtForeachExpr

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

Source from the content-addressed store, hash-verified

3154}
3155
3156func TestPrintStmtForeachExpr(t *testing.T) {
3157 o := bytes.NewBufferString("")
3158
3159 p := printer.NewPrettyPrinter(o, " ")
3160 p.Print(&stmt.Namespace{
3161 Stmts: []node.Node{
3162 &stmt.Foreach{
3163 Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}},
3164 Key: &expr.Variable{VarName: &node.Identifier{Value: "k"}},
3165 Variable: &expr.Variable{VarName: &node.Identifier{Value: "v"}},
3166 Stmt: &stmt.Expression{Expr: &scalar.String{Value: "'bar'"}},
3167 },
3168 },
3169 })
3170
3171 expected := `namespace {
3172 foreach ($a as $k => $v)
3173 'bar';
3174}`
3175 actual := o.String()
3176
3177 if expected != actual {
3178 t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
3179 }
3180}
3181
3182func TestPrintStmtForeachNop(t *testing.T) {
3183 o := bytes.NewBufferString("")

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…