package printer_test import ( "bytes" "os" "testing" "github.com/z7zmey/php-parser/node" "github.com/z7zmey/php-parser/node/name" "github.com/z7zmey/php-parser/node/stmt" "github.com/z7zmey/php-parser/php7" "github.com/z7zmey/php-parser/printer" ) func ExamplePrinter() { src := `Hello bar ( ' ' ) ; } elseif ( isset ( $b [ 2 ] ) ) list( , $c , ) = $b; else if ( 1 ); else { echo '' ; }` actual := print(parse(src)) if src != actual { t.Errorf("\nexpected: %s\ngot: %s\n", src, actual) } } func TestParseAndPrintNew(t *testing.T) { src := ` b ; print ( $a ) ;` actual := print(parse(src)) if src != actual { t.Errorf("\nexpected: %s\ngot: %s\n", src, actual) } } func TestParseAndPrintForeachReferenceShellExec(t *testing.T) { src := ` & $v ) { ` + "` {$v} cmd `" + ` ; }` actual := print(parse(src)) if src != actual { t.Errorf("\nexpected: %s\ngot: %s\n", src, actual) } } func TestParseAndPrintShortListShortArray(t *testing.T) { src := ` $v ; yield from $a ;` actual := print(parse(src)) if src != actual { t.Errorf("\nexpected: %s\ngot: %s\n", src, actual) } } func TestParseAndPrintAltIf(t *testing.T) { src := ` & $v ) : echo $v ; endforeach ;` actual := print(parse(src)) if src != actual { t.Errorf("\nexpected: %s\ngot: %s\n", src, actual) } } func TestParseAndPrintAltSwitchCaseBreakContinueDefault(t *testing.T) { src := `test>= $b ; ` actual := print(parse(src)) if src != actual { t.Errorf("\nexpected: %s\ngot: %s\n", src, actual) } } func TestParseAndPrintBinary(t *testing.T) { src := `= $b ; $a > $b ; $a === $b ; $a and $b ; $a or $b ; $a xor $b ; $a - $b ; $a % $b ; $a * $b ; $a != $b ; $a !== $b ; $a + $b ; $a ** $b ; $a << $b ; $a >> $b ; $a <= $b ; $a < $b ; $a <=> $b ; ` actual := print(parse(src)) if src != actual { t.Errorf("\nexpected: %s\ngot: %s\n", src, actual) } } func TestParseAndPrintUnary(t *testing.T) { src := ` 2 ] ; $a = array( 0 , 2 => 2 ) ; ` actual := print(parse(src)) if src != actual { t.Errorf("\nexpected: %s\ngot: %s\n", src, actual) } } func TestParseAndPrintClassConstFetch(t *testing.T) { src := `