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

Function TestPrinterPrintStmtTry

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

Source from the content-addressed store, hash-verified

4361}
4362
4363func TestPrinterPrintStmtTry(t *testing.T) {
4364 o := bytes.NewBufferString("")
4365
4366 p := printer.NewPrinter(o)
4367 p.Print(&stmt.Try{
4368 Stmts: []node.Node{
4369 &stmt.Expression{Expr: &expr.Variable{
4370 VarName: &node.Identifier{Value: "a"},
4371 }},
4372 },
4373 Catches: []node.Node{
4374 &stmt.Catch{
4375 Types: []node.Node{
4376 &name.Name{Parts: []node.Node{&name.NamePart{Value: "Exception"}}},
4377 &name.FullyQualified{Parts: []node.Node{&name.NamePart{Value: "RuntimeException"}}},
4378 },
4379 Variable: &expr.Variable{
4380 VarName: &node.Identifier{Value: "e"},
4381 },
4382 Stmts: []node.Node{
4383 &stmt.Expression{Expr: &expr.Variable{
4384 VarName: &node.Identifier{Value: "b"},
4385 }},
4386 },
4387 },
4388 },
4389 Finally: &stmt.Finally{
4390 Stmts: []node.Node{
4391 &stmt.Nop{},
4392 },
4393 },
4394 })
4395
4396 expected := `try{$a;}catch(Exception|\RuntimeException$e){$b;}finally{;}`
4397 actual := o.String()
4398
4399 if expected != actual {
4400 t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
4401 }
4402}
4403
4404func TestPrinterPrintStmtUnset(t *testing.T) {
4405 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…