From 74b094925550f6ff6b5a007e60be545a40ae1c72 Mon Sep 17 00:00:00 2001 From: Vadym Slizov Date: Sun, 20 Dec 2020 22:11:16 +0200 Subject: [PATCH] refactoring: test variable formatter --- pkg/ast/visitor/formatter_test.go | 48 +++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/pkg/ast/visitor/formatter_test.go b/pkg/ast/visitor/formatter_test.go index c6f493f..d4b2c0a 100644 --- a/pkg/ast/visitor/formatter_test.go +++ b/pkg/ast/visitor/formatter_test.go @@ -4855,6 +4855,54 @@ func TestFormatter_ExprUnaryPlus(t *testing.T) { } } +func TestFormatter_ExprVariable(t *testing.T) { + o := bytes.NewBufferString("") + + n := &ast.ExprVariable{ + VarName: &ast.Identifier{ + Value: []byte("$foo"), + }, + } + + f := visitor.NewFormatter().WithState(visitor.FormatterStatePHP).WithIndent(1) + n.Accept(f) + + p := visitor.NewPrinter(o).WithState(visitor.PrinterStatePHP) + n.Accept(p) + + expected := `$foo` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestFormatter_ExprVariable_Variable(t *testing.T) { + o := bytes.NewBufferString("") + + n := &ast.ExprVariable{ + VarName: &ast.ExprVariable{ + VarName: &ast.Identifier{ + Value: []byte("$foo"), + }, + }, + } + + f := visitor.NewFormatter().WithState(visitor.FormatterStatePHP).WithIndent(1) + n.Accept(f) + + p := visitor.NewPrinter(o).WithState(visitor.PrinterStatePHP) + n.Accept(p) + + expected := `$$foo` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + func TestFormatter_ExprYield(t *testing.T) { o := bytes.NewBufferString("")