diff --git a/test/node/scalar/debug.test b/test/node/scalar/debug.test new file mode 100755 index 0000000..e5b2dfa Binary files /dev/null and b/test/node/scalar/debug.test differ diff --git a/test/node/scalar/encapsed_test.go b/test/node/scalar/encapsed_test.go new file mode 100644 index 0000000..c0b291e --- /dev/null +++ b/test/node/scalar/encapsed_test.go @@ -0,0 +1,128 @@ +package test + +import ( + "bytes" + "testing" + + "github.com/z7zmey/php-parser/node/expr" + + "github.com/kylelemons/godebug/pretty" + "github.com/z7zmey/php-parser/node" + "github.com/z7zmey/php-parser/node/scalar" + "github.com/z7zmey/php-parser/node/stmt" + "github.com/z7zmey/php-parser/parser" +) + +func TestSimpleVar(t *testing.T) { + src := `bar()";` + + varName := node.NewIdentifier("$foo").SetPosition(&node.Position{1, 1, 10, 13}) + variable := expr.NewVariable(varName).SetPosition(&node.Position{1, 1, 10, 13}) + + property := node.NewIdentifier("bar").SetPosition(&node.Position{1, 1, 16, 18}) + propertyFetch := expr.NewPropertyFetch(variable, property).SetPosition(&node.Position{1, 1, 10, 18}) + + parts := []node.Node{ + scalar.NewEncapsedStringPart("test ").SetPosition(&node.Position{1, 1, 5, 9}), + propertyFetch, + scalar.NewEncapsedStringPart("()").SetPosition(&node.Position{1, 1, 19, 20}), + } + encapsed := scalar.NewEncapsed(parts).SetPosition(&node.Position{1, 1, 4, 21}) + expr := stmt.NewExpression(encapsed).SetPosition(&node.Position{1, 1, 4, 22}) + expected := stmt.NewStmtList([]node.Node{expr}).SetPosition(&node.Position{1, 1, 4, 22}) + + actual := parser.Parse(bytes.NewBufferString(src), "test.php") + + if diff := pretty.Compare(expected, actual); diff != "" { + t.Errorf("diff: (-expected +actual)\n%s", diff) + } +} + +func TestDollarOpenCurlyBraces(t *testing.T) { + src := `bar()}";` + + varName := node.NewIdentifier("$foo").SetPosition(&node.Position{1, 1, 11, 14}) + variable := expr.NewVariable(varName).SetPosition(&node.Position{1, 1, 11, 14}) + + method := node.NewIdentifier("bar").SetPosition(&node.Position{1, 1, 17, 19}) + + methodCall := expr.NewMethodCall(variable, method, nil).SetPosition(&node.Position{1, 1, 11, 21}) + + parts := []node.Node{ + scalar.NewEncapsedStringPart("test ").SetPosition(&node.Position{1, 1, 5, 9}), + methodCall, + } + encapsed := scalar.NewEncapsed(parts).SetPosition(&node.Position{1, 1, 4, 23}) + expr := stmt.NewExpression(encapsed).SetPosition(&node.Position{1, 1, 4, 24}) + expected := stmt.NewStmtList([]node.Node{expr}).SetPosition(&node.Position{1, 1, 4, 24}) + + actual := parser.Parse(bytes.NewBufferString(src), "test.php") + + if diff := pretty.Compare(expected, actual); diff != "" { + t.Errorf("diff: (-expected +actual)\n%s", diff) + } +} diff --git a/test/node/scalar/node_scalar_string_test.go b/test/node/scalar/node_scalar_string_test.go deleted file mode 100644 index 12963eb..0000000 --- a/test/node/scalar/node_scalar_string_test.go +++ /dev/null @@ -1,123 +0,0 @@ -package test - -import ( - "bytes" - "testing" - - "github.com/kylelemons/godebug/pretty" - "github.com/z7zmey/php-parser/node" - "github.com/z7zmey/php-parser/parser" - "github.com/z7zmey/php-parser/token" - "github.com/z7zmey/php-parser/node/scalar" -) - -func TestDoubleQuotedScalarString(t *testing.T) { - src := `