rename meta to freefloating; refactoring
This commit is contained in:
@@ -1,22 +1,23 @@
|
||||
package scalar
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/meta"
|
||||
"github.com/z7zmey/php-parser/freefloating"
|
||||
"github.com/z7zmey/php-parser/position"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// Dnumber node
|
||||
type Dnumber struct {
|
||||
Meta meta.Collection
|
||||
Position *position.Position
|
||||
Value string
|
||||
FreeFloating freefloating.Collection
|
||||
Position *position.Position
|
||||
Value string
|
||||
}
|
||||
|
||||
// NewDnumber node constructor
|
||||
func NewDnumber(Value string) *Dnumber {
|
||||
return &Dnumber{
|
||||
Value: Value,
|
||||
FreeFloating: nil,
|
||||
Value: Value,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,8 +31,8 @@ func (n *Dnumber) GetPosition() *position.Position {
|
||||
return n.Position
|
||||
}
|
||||
|
||||
func (n *Dnumber) GetMeta() *meta.Collection {
|
||||
return &n.Meta
|
||||
func (n *Dnumber) GetFreeFloating() *freefloating.Collection {
|
||||
return &n.FreeFloating
|
||||
}
|
||||
|
||||
// Attributes returns node attributes as map
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package scalar
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/meta"
|
||||
"github.com/z7zmey/php-parser/freefloating"
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/position"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
@@ -9,15 +9,16 @@ import (
|
||||
|
||||
// Encapsed node
|
||||
type Encapsed struct {
|
||||
Meta meta.Collection
|
||||
Position *position.Position
|
||||
Parts []node.Node
|
||||
FreeFloating freefloating.Collection
|
||||
Position *position.Position
|
||||
Parts []node.Node
|
||||
}
|
||||
|
||||
// NewEncapsed node constructor
|
||||
func NewEncapsed(Parts []node.Node) *Encapsed {
|
||||
return &Encapsed{
|
||||
Parts: Parts,
|
||||
FreeFloating: nil,
|
||||
Parts: Parts,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,8 +32,8 @@ func (n *Encapsed) GetPosition() *position.Position {
|
||||
return n.Position
|
||||
}
|
||||
|
||||
func (n *Encapsed) GetMeta() *meta.Collection {
|
||||
return &n.Meta
|
||||
func (n *Encapsed) GetFreeFloating() *freefloating.Collection {
|
||||
return &n.FreeFloating
|
||||
}
|
||||
|
||||
// Attributes returns node attributes as map
|
||||
|
||||
@@ -1,22 +1,23 @@
|
||||
package scalar
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/meta"
|
||||
"github.com/z7zmey/php-parser/freefloating"
|
||||
"github.com/z7zmey/php-parser/position"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// EncapsedStringPart node
|
||||
type EncapsedStringPart struct {
|
||||
Meta meta.Collection
|
||||
Position *position.Position
|
||||
Value string
|
||||
FreeFloating freefloating.Collection
|
||||
Position *position.Position
|
||||
Value string
|
||||
}
|
||||
|
||||
// NewEncapsedStringPart node constructor
|
||||
func NewEncapsedStringPart(Value string) *EncapsedStringPart {
|
||||
return &EncapsedStringPart{
|
||||
Value: Value,
|
||||
FreeFloating: nil,
|
||||
Value: Value,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,8 +31,8 @@ func (n *EncapsedStringPart) GetPosition() *position.Position {
|
||||
return n.Position
|
||||
}
|
||||
|
||||
func (n *EncapsedStringPart) GetMeta() *meta.Collection {
|
||||
return &n.Meta
|
||||
func (n *EncapsedStringPart) GetFreeFloating() *freefloating.Collection {
|
||||
return &n.FreeFloating
|
||||
}
|
||||
|
||||
// Attributes returns node attributes as map
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package scalar
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/meta"
|
||||
"github.com/z7zmey/php-parser/freefloating"
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/position"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
@@ -9,17 +9,18 @@ import (
|
||||
|
||||
// Heredoc node
|
||||
type Heredoc struct {
|
||||
Meta meta.Collection
|
||||
Position *position.Position
|
||||
Label string
|
||||
Parts []node.Node
|
||||
FreeFloating freefloating.Collection
|
||||
Position *position.Position
|
||||
Label string
|
||||
Parts []node.Node
|
||||
}
|
||||
|
||||
// NewHeredoc node constructor
|
||||
func NewHeredoc(Label string, Parts []node.Node) *Heredoc {
|
||||
return &Heredoc{
|
||||
Label: Label,
|
||||
Parts: Parts,
|
||||
FreeFloating: nil,
|
||||
Label: Label,
|
||||
Parts: Parts,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,8 +34,8 @@ func (n *Heredoc) GetPosition() *position.Position {
|
||||
return n.Position
|
||||
}
|
||||
|
||||
func (n *Heredoc) GetMeta() *meta.Collection {
|
||||
return &n.Meta
|
||||
func (n *Heredoc) GetFreeFloating() *freefloating.Collection {
|
||||
return &n.FreeFloating
|
||||
}
|
||||
|
||||
// Attributes returns node attributes as map
|
||||
|
||||
@@ -1,22 +1,23 @@
|
||||
package scalar
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/meta"
|
||||
"github.com/z7zmey/php-parser/freefloating"
|
||||
"github.com/z7zmey/php-parser/position"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// Lnumber node
|
||||
type Lnumber struct {
|
||||
Meta meta.Collection
|
||||
Position *position.Position
|
||||
Value string
|
||||
FreeFloating freefloating.Collection
|
||||
Position *position.Position
|
||||
Value string
|
||||
}
|
||||
|
||||
// NewLnumber node constructor
|
||||
func NewLnumber(Value string) *Lnumber {
|
||||
return &Lnumber{
|
||||
Value: Value,
|
||||
FreeFloating: nil,
|
||||
Value: Value,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,8 +31,8 @@ func (n *Lnumber) GetPosition() *position.Position {
|
||||
return n.Position
|
||||
}
|
||||
|
||||
func (n *Lnumber) GetMeta() *meta.Collection {
|
||||
return &n.Meta
|
||||
func (n *Lnumber) GetFreeFloating() *freefloating.Collection {
|
||||
return &n.FreeFloating
|
||||
}
|
||||
|
||||
// Attributes returns node attributes as map
|
||||
|
||||
@@ -1,22 +1,23 @@
|
||||
package scalar
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/meta"
|
||||
"github.com/z7zmey/php-parser/freefloating"
|
||||
"github.com/z7zmey/php-parser/position"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// MagicConstant node
|
||||
type MagicConstant struct {
|
||||
Meta meta.Collection
|
||||
Position *position.Position
|
||||
Value string
|
||||
FreeFloating freefloating.Collection
|
||||
Position *position.Position
|
||||
Value string
|
||||
}
|
||||
|
||||
// NewMagicConstant node constructor
|
||||
func NewMagicConstant(Value string) *MagicConstant {
|
||||
return &MagicConstant{
|
||||
Value: Value,
|
||||
FreeFloating: nil,
|
||||
Value: Value,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,8 +31,8 @@ func (n *MagicConstant) GetPosition() *position.Position {
|
||||
return n.Position
|
||||
}
|
||||
|
||||
func (n *MagicConstant) GetMeta() *meta.Collection {
|
||||
return &n.Meta
|
||||
func (n *MagicConstant) GetFreeFloating() *freefloating.Collection {
|
||||
return &n.FreeFloating
|
||||
}
|
||||
|
||||
// Attributes returns node attributes as map
|
||||
|
||||
@@ -1,22 +1,23 @@
|
||||
package scalar
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/meta"
|
||||
"github.com/z7zmey/php-parser/freefloating"
|
||||
"github.com/z7zmey/php-parser/position"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// String node
|
||||
type String struct {
|
||||
Meta meta.Collection
|
||||
Position *position.Position
|
||||
Value string
|
||||
FreeFloating freefloating.Collection
|
||||
Position *position.Position
|
||||
Value string
|
||||
}
|
||||
|
||||
// NewString node constructor
|
||||
func NewString(Value string) *String {
|
||||
return &String{
|
||||
Value: Value,
|
||||
FreeFloating: nil,
|
||||
Value: Value,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,8 +31,8 @@ func (n *String) GetPosition() *position.Position {
|
||||
return n.Position
|
||||
}
|
||||
|
||||
func (n *String) GetMeta() *meta.Collection {
|
||||
return &n.Meta
|
||||
func (n *String) GetFreeFloating() *freefloating.Collection {
|
||||
return &n.FreeFloating
|
||||
}
|
||||
|
||||
// Attributes returns node attributes as map
|
||||
|
||||
@@ -4,6 +4,8 @@ import (
|
||||
"bytes"
|
||||
"testing"
|
||||
|
||||
"gotest.tools/assert"
|
||||
|
||||
"github.com/z7zmey/php-parser/node/expr"
|
||||
"github.com/z7zmey/php-parser/position"
|
||||
|
||||
@@ -75,12 +77,12 @@ func TestSimpleVar(t *testing.T) {
|
||||
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
|
||||
php7parser.Parse()
|
||||
actual := php7parser.GetRootNode()
|
||||
assertEqual(t, expected, actual)
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
|
||||
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
|
||||
php5parser.Parse()
|
||||
actual = php5parser.GetRootNode()
|
||||
assertEqual(t, expected, actual)
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
}
|
||||
|
||||
func TestSimpleVarOneChar(t *testing.T) {
|
||||
@@ -144,12 +146,12 @@ func TestSimpleVarOneChar(t *testing.T) {
|
||||
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
|
||||
php7parser.Parse()
|
||||
actual := php7parser.GetRootNode()
|
||||
assertEqual(t, expected, actual)
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
|
||||
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
|
||||
php5parser.Parse()
|
||||
actual = php5parser.GetRootNode()
|
||||
assertEqual(t, expected, actual)
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
}
|
||||
|
||||
func TestSimpleVarEndsEcapsed(t *testing.T) {
|
||||
@@ -222,12 +224,12 @@ func TestSimpleVarEndsEcapsed(t *testing.T) {
|
||||
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
|
||||
php7parser.Parse()
|
||||
actual := php7parser.GetRootNode()
|
||||
assertEqual(t, expected, actual)
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
|
||||
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
|
||||
php5parser.Parse()
|
||||
actual = php5parser.GetRootNode()
|
||||
assertEqual(t, expected, actual)
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
}
|
||||
|
||||
func TestStringVarCurveOpen(t *testing.T) {
|
||||
@@ -308,12 +310,12 @@ func TestStringVarCurveOpen(t *testing.T) {
|
||||
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
|
||||
php7parser.Parse()
|
||||
actual := php7parser.GetRootNode()
|
||||
assertEqual(t, expected, actual)
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
|
||||
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
|
||||
php5parser.Parse()
|
||||
actual = php5parser.GetRootNode()
|
||||
assertEqual(t, expected, actual)
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
}
|
||||
|
||||
func TestSimpleVarPropertyFetch(t *testing.T) {
|
||||
@@ -403,12 +405,12 @@ func TestSimpleVarPropertyFetch(t *testing.T) {
|
||||
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
|
||||
php7parser.Parse()
|
||||
actual := php7parser.GetRootNode()
|
||||
assertEqual(t, expected, actual)
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
|
||||
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
|
||||
php5parser.Parse()
|
||||
actual = php5parser.GetRootNode()
|
||||
assertEqual(t, expected, actual)
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
}
|
||||
|
||||
func TestDollarOpenCurlyBraces(t *testing.T) {
|
||||
@@ -472,12 +474,12 @@ func TestDollarOpenCurlyBraces(t *testing.T) {
|
||||
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
|
||||
php7parser.Parse()
|
||||
actual := php7parser.GetRootNode()
|
||||
assertEqual(t, expected, actual)
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
|
||||
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
|
||||
php5parser.Parse()
|
||||
actual = php5parser.GetRootNode()
|
||||
assertEqual(t, expected, actual)
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
}
|
||||
|
||||
func TestDollarOpenCurlyBracesDimNumber(t *testing.T) {
|
||||
@@ -558,12 +560,12 @@ func TestDollarOpenCurlyBracesDimNumber(t *testing.T) {
|
||||
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
|
||||
php7parser.Parse()
|
||||
actual := php7parser.GetRootNode()
|
||||
assertEqual(t, expected, actual)
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
|
||||
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
|
||||
php5parser.Parse()
|
||||
actual = php5parser.GetRootNode()
|
||||
assertEqual(t, expected, actual)
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
}
|
||||
|
||||
func TestCurlyOpenMethodCall(t *testing.T) {
|
||||
@@ -652,10 +654,10 @@ func TestCurlyOpenMethodCall(t *testing.T) {
|
||||
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
|
||||
php7parser.Parse()
|
||||
actual := php7parser.GetRootNode()
|
||||
assertEqual(t, expected, actual)
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
|
||||
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
|
||||
php5parser.Parse()
|
||||
actual = php5parser.GetRootNode()
|
||||
assertEqual(t, expected, actual)
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
}
|
||||
|
||||
57
node/scalar/t_freefloating_test.go
Normal file
57
node/scalar/t_freefloating_test.go
Normal file
@@ -0,0 +1,57 @@
|
||||
package scalar_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"gotest.tools/assert"
|
||||
|
||||
"github.com/z7zmey/php-parser/freefloating"
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/node/scalar"
|
||||
)
|
||||
|
||||
var expected freefloating.Collection = freefloating.Collection{
|
||||
freefloating.Start: []freefloating.String{
|
||||
{
|
||||
StringType: freefloating.WhiteSpaceType,
|
||||
Value: " ",
|
||||
Position: nil,
|
||||
},
|
||||
{
|
||||
StringType: freefloating.CommentType,
|
||||
Value: "//comment\n",
|
||||
Position: nil,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
var nodes = []node.Node{
|
||||
&scalar.Dnumber{
|
||||
FreeFloating: expected,
|
||||
},
|
||||
&scalar.EncapsedStringPart{
|
||||
FreeFloating: expected,
|
||||
},
|
||||
&scalar.Encapsed{
|
||||
FreeFloating: expected,
|
||||
},
|
||||
&scalar.Heredoc{
|
||||
FreeFloating: expected,
|
||||
},
|
||||
&scalar.Lnumber{
|
||||
FreeFloating: expected,
|
||||
},
|
||||
&scalar.MagicConstant{
|
||||
FreeFloating: expected,
|
||||
},
|
||||
&scalar.String{
|
||||
FreeFloating: expected,
|
||||
},
|
||||
}
|
||||
|
||||
func TestMeta(t *testing.T) {
|
||||
for _, n := range nodes {
|
||||
actual := *n.GetFreeFloating()
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,8 @@ import (
|
||||
"bytes"
|
||||
"testing"
|
||||
|
||||
"gotest.tools/assert"
|
||||
|
||||
"github.com/z7zmey/php-parser/node/expr"
|
||||
"github.com/z7zmey/php-parser/position"
|
||||
|
||||
@@ -79,12 +81,12 @@ LBL;
|
||||
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
|
||||
php7parser.Parse()
|
||||
actual := php7parser.GetRootNode()
|
||||
assertEqual(t, expected, actual)
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
|
||||
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
|
||||
php5parser.Parse()
|
||||
actual = php5parser.GetRootNode()
|
||||
assertEqual(t, expected, actual)
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
}
|
||||
|
||||
func TestSimpleHeredocLabel(t *testing.T) {
|
||||
@@ -152,12 +154,12 @@ LBL;
|
||||
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
|
||||
php7parser.Parse()
|
||||
actual := php7parser.GetRootNode()
|
||||
assertEqual(t, expected, actual)
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
|
||||
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
|
||||
php5parser.Parse()
|
||||
actual = php5parser.GetRootNode()
|
||||
assertEqual(t, expected, actual)
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
}
|
||||
|
||||
func TestSimpleNowdocLabel(t *testing.T) {
|
||||
@@ -208,12 +210,12 @@ LBL;
|
||||
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
|
||||
php7parser.Parse()
|
||||
actual := php7parser.GetRootNode()
|
||||
assertEqual(t, expected, actual)
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
|
||||
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
|
||||
php5parser.Parse()
|
||||
actual = php5parser.GetRootNode()
|
||||
assertEqual(t, expected, actual)
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
}
|
||||
|
||||
func TestEmptyHeredoc(t *testing.T) {
|
||||
@@ -252,12 +254,12 @@ CAD;
|
||||
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
|
||||
php7parser.Parse()
|
||||
actual := php7parser.GetRootNode()
|
||||
assertEqual(t, expected, actual)
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
|
||||
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
|
||||
php5parser.Parse()
|
||||
actual = php5parser.GetRootNode()
|
||||
assertEqual(t, expected, actual)
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
}
|
||||
|
||||
func TestHeredocScalarString(t *testing.T) {
|
||||
@@ -308,10 +310,10 @@ CAD;
|
||||
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
|
||||
php7parser.Parse()
|
||||
actual := php7parser.GetRootNode()
|
||||
assertEqual(t, expected, actual)
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
|
||||
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
|
||||
php5parser.Parse()
|
||||
actual = php5parser.GetRootNode()
|
||||
assertEqual(t, expected, actual)
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@ import (
|
||||
"bytes"
|
||||
"testing"
|
||||
|
||||
"gotest.tools/assert"
|
||||
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/node/scalar"
|
||||
"github.com/z7zmey/php-parser/node/stmt"
|
||||
@@ -47,10 +49,10 @@ func TestMagicConstant(t *testing.T) {
|
||||
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
|
||||
php7parser.Parse()
|
||||
actual := php7parser.GetRootNode()
|
||||
assertEqual(t, expected, actual)
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
|
||||
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
|
||||
php5parser.Parse()
|
||||
actual = php5parser.GetRootNode()
|
||||
assertEqual(t, expected, actual)
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
}
|
||||
|
||||
@@ -1,41 +0,0 @@
|
||||
package scalar_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/z7zmey/php-parser/node/scalar"
|
||||
|
||||
"github.com/z7zmey/php-parser/meta"
|
||||
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
)
|
||||
|
||||
var nodes = []node.Node{
|
||||
&scalar.Dnumber{},
|
||||
&scalar.EncapsedStringPart{},
|
||||
&scalar.Encapsed{},
|
||||
&scalar.Heredoc{},
|
||||
&scalar.Lnumber{},
|
||||
&scalar.MagicConstant{},
|
||||
&scalar.String{},
|
||||
}
|
||||
|
||||
func TestMeta(t *testing.T) {
|
||||
expected := &meta.Collection{
|
||||
&meta.Data{
|
||||
Value: "//comment\n",
|
||||
Type: meta.CommentType,
|
||||
Position: nil,
|
||||
},
|
||||
&meta.Data{
|
||||
Value: " ",
|
||||
Type: meta.WhiteSpaceType,
|
||||
Position: nil,
|
||||
},
|
||||
}
|
||||
for _, n := range nodes {
|
||||
n.GetMeta().Push(*expected...)
|
||||
actual := n.GetMeta()
|
||||
assertEqual(t, expected, actual)
|
||||
}
|
||||
}
|
||||
@@ -2,10 +2,10 @@ package scalar_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/kylelemons/godebug/pretty"
|
||||
"gotest.tools/assert"
|
||||
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/node/scalar"
|
||||
"github.com/z7zmey/php-parser/node/stmt"
|
||||
@@ -14,19 +14,6 @@ import (
|
||||
"github.com/z7zmey/php-parser/position"
|
||||
)
|
||||
|
||||
func assertEqual(t *testing.T, expected interface{}, actual interface{}) {
|
||||
if !reflect.DeepEqual(expected, actual) {
|
||||
diff := pretty.Compare(expected, actual)
|
||||
|
||||
if diff != "" {
|
||||
t.Errorf("diff: (-expected +actual)\n%s", diff)
|
||||
} else {
|
||||
t.Errorf("expected and actual are not equal\n")
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
func TestLNumber(t *testing.T) {
|
||||
src := `<? 1234567890123456789;`
|
||||
|
||||
@@ -61,12 +48,12 @@ func TestLNumber(t *testing.T) {
|
||||
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
|
||||
php7parser.Parse()
|
||||
actual := php7parser.GetRootNode()
|
||||
assertEqual(t, expected, actual)
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
|
||||
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
|
||||
php5parser.Parse()
|
||||
actual = php5parser.GetRootNode()
|
||||
assertEqual(t, expected, actual)
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
}
|
||||
|
||||
func TestDNumber(t *testing.T) {
|
||||
@@ -103,12 +90,12 @@ func TestDNumber(t *testing.T) {
|
||||
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
|
||||
php7parser.Parse()
|
||||
actual := php7parser.GetRootNode()
|
||||
assertEqual(t, expected, actual)
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
|
||||
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
|
||||
php5parser.Parse()
|
||||
actual = php5parser.GetRootNode()
|
||||
assertEqual(t, expected, actual)
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
}
|
||||
|
||||
func TestFloat(t *testing.T) {
|
||||
@@ -145,12 +132,12 @@ func TestFloat(t *testing.T) {
|
||||
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
|
||||
php7parser.Parse()
|
||||
actual := php7parser.GetRootNode()
|
||||
assertEqual(t, expected, actual)
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
|
||||
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
|
||||
php5parser.Parse()
|
||||
actual = php5parser.GetRootNode()
|
||||
assertEqual(t, expected, actual)
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
}
|
||||
|
||||
func TestBinaryLNumber(t *testing.T) {
|
||||
@@ -187,12 +174,12 @@ func TestBinaryLNumber(t *testing.T) {
|
||||
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
|
||||
php7parser.Parse()
|
||||
actual := php7parser.GetRootNode()
|
||||
assertEqual(t, expected, actual)
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
|
||||
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
|
||||
php5parser.Parse()
|
||||
actual = php5parser.GetRootNode()
|
||||
assertEqual(t, expected, actual)
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
}
|
||||
|
||||
func TestBinaryDNumber(t *testing.T) {
|
||||
@@ -229,12 +216,12 @@ func TestBinaryDNumber(t *testing.T) {
|
||||
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
|
||||
php7parser.Parse()
|
||||
actual := php7parser.GetRootNode()
|
||||
assertEqual(t, expected, actual)
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
|
||||
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
|
||||
php5parser.Parse()
|
||||
actual = php5parser.GetRootNode()
|
||||
assertEqual(t, expected, actual)
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
}
|
||||
|
||||
func TestHLNumber(t *testing.T) {
|
||||
@@ -271,12 +258,12 @@ func TestHLNumber(t *testing.T) {
|
||||
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
|
||||
php7parser.Parse()
|
||||
actual := php7parser.GetRootNode()
|
||||
assertEqual(t, expected, actual)
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
|
||||
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
|
||||
php5parser.Parse()
|
||||
actual = php5parser.GetRootNode()
|
||||
assertEqual(t, expected, actual)
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
}
|
||||
|
||||
func TestHDNumber(t *testing.T) {
|
||||
@@ -313,10 +300,10 @@ func TestHDNumber(t *testing.T) {
|
||||
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
|
||||
php7parser.Parse()
|
||||
actual := php7parser.GetRootNode()
|
||||
assertEqual(t, expected, actual)
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
|
||||
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
|
||||
php5parser.Parse()
|
||||
actual = php5parser.GetRootNode()
|
||||
assertEqual(t, expected, actual)
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@ package scalar_test
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"gotest.tools/assert"
|
||||
|
||||
"github.com/z7zmey/php-parser/position"
|
||||
)
|
||||
|
||||
@@ -11,6 +13,6 @@ func TestPosition(t *testing.T) {
|
||||
for _, n := range nodes {
|
||||
n.SetPosition(expected)
|
||||
actual := n.GetPosition()
|
||||
assertEqual(t, expected, actual)
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@ import (
|
||||
"bytes"
|
||||
"testing"
|
||||
|
||||
"gotest.tools/assert"
|
||||
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/node/scalar"
|
||||
"github.com/z7zmey/php-parser/node/stmt"
|
||||
@@ -46,12 +48,12 @@ func TestDoubleQuotedScalarString(t *testing.T) {
|
||||
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
|
||||
php7parser.Parse()
|
||||
actual := php7parser.GetRootNode()
|
||||
assertEqual(t, expected, actual)
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
|
||||
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
|
||||
php5parser.Parse()
|
||||
actual = php5parser.GetRootNode()
|
||||
assertEqual(t, expected, actual)
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
}
|
||||
|
||||
func TestDoubleQuotedScalarStringWithEscapedVar(t *testing.T) {
|
||||
@@ -88,12 +90,12 @@ func TestDoubleQuotedScalarStringWithEscapedVar(t *testing.T) {
|
||||
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
|
||||
php7parser.Parse()
|
||||
actual := php7parser.GetRootNode()
|
||||
assertEqual(t, expected, actual)
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
|
||||
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
|
||||
php5parser.Parse()
|
||||
actual = php5parser.GetRootNode()
|
||||
assertEqual(t, expected, actual)
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
}
|
||||
|
||||
func TestMultilineDoubleQuotedScalarString(t *testing.T) {
|
||||
@@ -132,12 +134,12 @@ func TestMultilineDoubleQuotedScalarString(t *testing.T) {
|
||||
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
|
||||
php7parser.Parse()
|
||||
actual := php7parser.GetRootNode()
|
||||
assertEqual(t, expected, actual)
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
|
||||
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
|
||||
php5parser.Parse()
|
||||
actual = php5parser.GetRootNode()
|
||||
assertEqual(t, expected, actual)
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
}
|
||||
|
||||
func TestSingleQuotedScalarString(t *testing.T) {
|
||||
@@ -174,12 +176,12 @@ func TestSingleQuotedScalarString(t *testing.T) {
|
||||
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
|
||||
php7parser.Parse()
|
||||
actual := php7parser.GetRootNode()
|
||||
assertEqual(t, expected, actual)
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
|
||||
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
|
||||
php5parser.Parse()
|
||||
actual = php5parser.GetRootNode()
|
||||
assertEqual(t, expected, actual)
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
}
|
||||
|
||||
func TestMultilineSingleQuotedScalarString(t *testing.T) {
|
||||
@@ -218,10 +220,10 @@ func TestMultilineSingleQuotedScalarString(t *testing.T) {
|
||||
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
|
||||
php7parser.Parse()
|
||||
actual := php7parser.GetRootNode()
|
||||
assertEqual(t, expected, actual)
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
|
||||
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
|
||||
php5parser.Parse()
|
||||
actual = php5parser.GetRootNode()
|
||||
assertEqual(t, expected, actual)
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user