Merge pull request #103 from z7zmey/dev

merge dev to master
This commit is contained in:
Vadym Slizov 2020-03-09 13:36:33 +02:00 committed by GitHub
commit 5b5e414359
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
126 changed files with 37112 additions and 22025 deletions

1
.gitignore vendored
View File

@ -1,4 +1,5 @@
.vscode
.idea
php-parser
**/*.test

View File

@ -25,10 +25,13 @@ bench:
compile: ./php5/php5.go ./php7/php7.go ./scanner/scanner.go fmt
sed -i '' -e 's/yyErrorVerbose = false/yyErrorVerbose = true/g' ./php7/php7.go
sed -i '' -e 's/yyErrorVerbose = false/yyErrorVerbose = true/g' ./php5/php5.go
sed -i '' -e 's/\/\/line/\/\/ line/g' ./php5/php5.go
sed -i '' -e 's/\/\/line/\/\/ line/g' ./php7/php7.go
sed -i '' -e 's/\/\/line/\/\/ line/g' ./scanner/scanner.go
rm -f y.output
./scanner/scanner.go: ./scanner/scanner.l
golex -o $@ $<
./scanner/scanner.go: ./scanner/scanner.rl
ragel -Z -G2 -o $@ $<
./php5/php5.go: ./php5/php5.y
goyacc -o $@ $<

View File

@ -9,7 +9,7 @@ PHP Parser written in Go
[![Maintainability](https://api.codeclimate.com/v1/badges/950783b2e739db26e0ed/maintainability)](https://codeclimate.com/github/z7zmey/php-parser/maintainability)
[![Test Coverage](https://api.codeclimate.com/v1/badges/950783b2e739db26e0ed/test_coverage)](https://codeclimate.com/github/z7zmey/php-parser/test_coverage)
This project uses [goyacc](https://godoc.org/golang.org/x/tools/cmd/goyacc) and [golex](https://github.com/cznic/golex) libraries to parse PHP sources into [AST](https://en.wikipedia.org/wiki/Abstract_syntax_tree). It can be used to write static analysis, refactoring, metrics, code style formatting tools.
This project uses [goyacc](https://godoc.org/golang.org/x/tools/cmd/goyacc) and [ragel](https://www.colm.net/open-source/ragel/) tools to create PHP parser. It parses source code into [AST](https://en.wikipedia.org/wiki/Abstract_syntax_tree). It can be used to write static analysis, refactoring, metrics, code style formatting tools.
#### Try it online: [demo](https://php-parser.com)
@ -37,7 +37,6 @@ Usage example
package main
import (
"bytes"
"fmt"
"os"
@ -46,9 +45,9 @@ import (
)
func main() {
src := bytes.NewBufferString(`<? echo "Hello world";`)
src := []byte(`<? echo "Hello world";`)
parser := php7.NewParser(src, "example.php")
parser := php7.NewParser(src, "7.4")
parser.Parse()
for _, e := range parser.GetErrors() {
@ -56,8 +55,8 @@ func main() {
}
visitor := visitor.Dumper{
Writer: os.Stdout,
Indent: "",
Writer: os.Stdout,
Indent: "",
}
rootNode := parser.GetRootNode()
@ -88,6 +87,7 @@ php-parser [flags] <path> ...
| flag | type | description |
|-------|------|----------------------------------------------|
| -p | bool | print filepath |
| -d |string| dump format: [custom, go, json, pretty-json] |
| -r | bool | resolve names |
| -ff | bool | parse and show free floating strings |

View File

@ -4,9 +4,91 @@ package freefloating
import "strconv"
const _Position_name = "StartEndSlashColonSemiColonAltEndDollarAmpersandNamePrefixKeyVarUseTypeReturnTypeOptionalTypeCaseSeparatorLexicalVarsParamsRefCastExprInitExprCondExprIncExprTrueCondHaltCompillerNamespaceStaticClassUseWhileForSwitchBreakForeachDeclareLabelFinallyListDefaultIfElseIfElseVariadicFunctionAliasAsEqualExitArrayIssetEmptyEvalEchoTryCatchUnsetStmtsVarListConstListNameListParamListModifierListArrayPairListCaseListStartCaseListEndArgumentListPropertyListParameterListAdaptationListLexicalVarListUseDeclarationListOpenParenthesisTokenCloseParenthesisToken"
func _() {
// An "invalid array index" compiler error signifies that the constant values have changed.
// Re-run the stringer command to generate them again.
var x [1]struct{}
_ = x[Start-0]
_ = x[End-1]
_ = x[Slash-2]
_ = x[Colon-3]
_ = x[SemiColon-4]
_ = x[AltEnd-5]
_ = x[Dollar-6]
_ = x[Ampersand-7]
_ = x[Name-8]
_ = x[Prefix-9]
_ = x[Key-10]
_ = x[Var-11]
_ = x[UseType-12]
_ = x[ReturnType-13]
_ = x[OptionalType-14]
_ = x[CaseSeparator-15]
_ = x[LexicalVars-16]
_ = x[Params-17]
_ = x[Ref-18]
_ = x[Cast-19]
_ = x[Expr-20]
_ = x[InitExpr-21]
_ = x[CondExpr-22]
_ = x[IncExpr-23]
_ = x[True-24]
_ = x[Cond-25]
_ = x[HaltCompiller-26]
_ = x[Namespace-27]
_ = x[Static-28]
_ = x[Class-29]
_ = x[Use-30]
_ = x[While-31]
_ = x[For-32]
_ = x[Switch-33]
_ = x[Break-34]
_ = x[Foreach-35]
_ = x[Declare-36]
_ = x[Label-37]
_ = x[Finally-38]
_ = x[List-39]
_ = x[Default-40]
_ = x[If-41]
_ = x[ElseIf-42]
_ = x[Else-43]
_ = x[Variadic-44]
_ = x[Function-45]
_ = x[DoubleArrow-46]
_ = x[Alias-47]
_ = x[As-48]
_ = x[Equal-49]
_ = x[Exit-50]
_ = x[Array-51]
_ = x[Isset-52]
_ = x[Empty-53]
_ = x[Eval-54]
_ = x[Echo-55]
_ = x[Try-56]
_ = x[Catch-57]
_ = x[Unset-58]
_ = x[Stmts-59]
_ = x[VarList-60]
_ = x[ConstList-61]
_ = x[NameList-62]
_ = x[ParamList-63]
_ = x[ModifierList-64]
_ = x[ArrayPairList-65]
_ = x[CaseListStart-66]
_ = x[CaseListEnd-67]
_ = x[ArgumentList-68]
_ = x[PropertyList-69]
_ = x[ParameterList-70]
_ = x[AdaptationList-71]
_ = x[LexicalVarList-72]
_ = x[UseDeclarationList-73]
_ = x[OpenParenthesisToken-74]
_ = x[CloseParenthesisToken-75]
}
var _Position_index = [...]uint16{0, 5, 8, 13, 18, 27, 33, 39, 48, 52, 58, 61, 64, 71, 81, 93, 106, 117, 123, 126, 130, 134, 142, 150, 157, 161, 165, 178, 187, 193, 198, 201, 206, 209, 215, 220, 227, 234, 239, 246, 250, 257, 259, 265, 269, 277, 285, 290, 292, 297, 301, 306, 311, 316, 320, 324, 327, 332, 337, 342, 349, 358, 366, 375, 387, 400, 413, 424, 436, 448, 461, 475, 489, 507, 527, 548}
const _Position_name = "StartEndSlashColonSemiColonAltEndDollarAmpersandNamePrefixKeyVarUseTypeReturnTypeOptionalTypeCaseSeparatorLexicalVarsParamsRefCastExprInitExprCondExprIncExprTrueCondHaltCompillerNamespaceStaticClassUseWhileForSwitchBreakForeachDeclareLabelFinallyListDefaultIfElseIfElseVariadicFunctionDoubleArrowAliasAsEqualExitArrayIssetEmptyEvalEchoTryCatchUnsetStmtsVarListConstListNameListParamListModifierListArrayPairListCaseListStartCaseListEndArgumentListPropertyListParameterListAdaptationListLexicalVarListUseDeclarationListOpenParenthesisTokenCloseParenthesisToken"
var _Position_index = [...]uint16{0, 5, 8, 13, 18, 27, 33, 39, 48, 52, 58, 61, 64, 71, 81, 93, 106, 117, 123, 126, 130, 134, 142, 150, 157, 161, 165, 178, 187, 193, 198, 201, 206, 209, 215, 220, 227, 234, 239, 246, 250, 257, 259, 265, 269, 277, 285, 296, 301, 303, 308, 312, 317, 322, 327, 331, 335, 338, 343, 348, 353, 360, 369, 377, 386, 398, 411, 424, 435, 447, 459, 472, 486, 500, 518, 538, 559}
func (i Position) String() string {
if i < 0 || i >= Position(len(_Position_index)-1) {

View File

@ -61,6 +61,7 @@ const (
Else
Variadic
Function
DoubleArrow
Alias
As
Equal

12
go.mod Normal file
View File

@ -0,0 +1,12 @@
module github.com/z7zmey/php-parser
go 1.13
require (
github.com/google/go-cmp v0.4.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pkg/profile v1.4.0
github.com/yookoala/realpath v1.0.0
golang.org/x/tools v0.0.0-20200308013534-11ec41452d41 // indirect
gotest.tools v2.2.0+incompatible
)

28
go.sum Normal file
View File

@ -0,0 +1,28 @@
github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4=
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/profile v1.4.0 h1:uCmaf4vVbWAOZz36k1hrQD7ijGRzLwaME8Am/7a4jZI=
github.com/pkg/profile v1.4.0/go.mod h1:NWz/XGvpEW1FyYQ7fCx4dqYBLlfTcE+A9FLAkNKqjFE=
github.com/yookoala/realpath v1.0.0 h1:7OA9pj4FZd+oZDsyvXWQvjn5oBdcHRTV44PpdMSuImQ=
github.com/yookoala/realpath v1.0.0/go.mod h1:gJJMA9wuX7AcqLy1+ffPatSCySA1FQ2S8Ya9AIoYBpE=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20200308013534-11ec41452d41 h1:9Di9iYgOt9ThCipBxChBVhgNipDoE5mxO84rQV7D0FE=
golang.org/x/tools v0.0.0-20200308013534-11ec41452d41/go.mod h1:o4KQGtdN14AW+yjsvvwRTJJuXz8XRtIHtEnmAXLyFUw=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo=
gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw=

67
main.go
View File

@ -1,7 +1,6 @@
package main
import (
"bufio"
"bytes"
"flag"
"fmt"
@ -15,35 +14,45 @@ import (
"github.com/pkg/profile"
"github.com/yookoala/realpath"
"github.com/z7zmey/php-parser/parser"
"github.com/z7zmey/php-parser/php5"
"github.com/z7zmey/php-parser/php7"
"github.com/z7zmey/php-parser/printer"
"github.com/z7zmey/php-parser/visitor"
)
var wg sync.WaitGroup
var usePhp5 *bool
var phpVersion string
var dumpType string
var profiler string
var withFreeFloating *bool
var showResolvedNs *bool
var printBack *bool
var printPath *bool
type file struct {
path string
content []byte
}
type result struct {
path string
parser parser.Parser
}
func main() {
usePhp5 = flag.Bool("php5", false, "parse as PHP5")
withFreeFloating = flag.Bool("ff", false, "parse and show free floating strings")
showResolvedNs = flag.Bool("r", false, "resolve names")
printBack = flag.Bool("pb", false, "print AST back into the parsed file")
printPath = flag.Bool("p", false, "print filepath")
flag.StringVar(&dumpType, "d", "", "dump format: [custom, go, json, pretty_json]")
flag.StringVar(&profiler, "prof", "", "start profiler: [cpu, mem, trace]")
flag.StringVar(&phpVersion, "phpver", "7.4", "php version")
flag.Parse()
if len(flag.Args()) == 0 {
flag.Usage()
return
}
switch profiler {
case "cpu":
defer profile.Start(profile.ProfilePath("."), profile.NoShutdownHook).Stop()
@ -53,10 +62,10 @@ func main() {
defer profile.Start(profile.TraceProfile, profile.ProfilePath("."), profile.NoShutdownHook).Stop()
}
numCpu := runtime.NumCPU()
numCpu := runtime.GOMAXPROCS(0)
fileCh := make(chan *file, numCpu)
resultCh := make(chan parser.Parser, numCpu)
resultCh := make(chan result, numCpu)
// run 4 concurrent parserWorkers
for i := 0; i < numCpu; i++ {
@ -93,21 +102,16 @@ func processPath(pathList []string, fileCh chan<- *file) {
}
}
func parserWorker(fileCh <-chan *file, result chan<- parser.Parser) {
var parserWorker parser.Parser
func parserWorker(fileCh <-chan *file, r chan<- result) {
for {
f, ok := <-fileCh
if !ok {
return
}
src := bytes.NewReader(f.content)
if *usePhp5 {
parserWorker = php5.NewParser(src, f.path)
} else {
parserWorker = php7.NewParser(src, f.path)
parserWorker, err := parser.NewParser(f.content, phpVersion)
if err != nil {
panic(err.Error())
}
if *withFreeFloating {
@ -116,43 +120,42 @@ func parserWorker(fileCh <-chan *file, result chan<- parser.Parser) {
parserWorker.Parse()
result <- parserWorker
r <- result{path: f.path, parser: parserWorker}
}
}
func printerWorker(result <-chan parser.Parser) {
func printerWorker(r <-chan result) {
var counter int
w := bufio.NewWriter(os.Stdout)
for {
parserWorker, ok := <-result
res, ok := <-r
if !ok {
w.Flush()
return
}
counter++
fmt.Fprintf(w, "==> [%d] %s\n", counter, parserWorker.GetPath())
if *printPath {
fmt.Fprintf(os.Stdout, "==> [%d] %s\n", counter, res.path)
}
for _, e := range parserWorker.GetErrors() {
fmt.Fprintln(w, e)
for _, e := range res.parser.GetErrors() {
fmt.Fprintf(os.Stdout, "==> %s\n", e)
}
if *printBack {
o := bytes.NewBuffer([]byte{})
p := printer.NewPrinter(o)
p.Print(parserWorker.GetRootNode())
p.Print(res.parser.GetRootNode())
err := ioutil.WriteFile(parserWorker.GetPath(), o.Bytes(), 0644)
err := ioutil.WriteFile(res.path, o.Bytes(), 0644)
checkErr(err)
}
var nsResolver *visitor.NamespaceResolver
if *showResolvedNs {
nsResolver = visitor.NewNamespaceResolver()
parserWorker.GetRootNode().Walk(nsResolver)
res.parser.GetRootNode().Walk(nsResolver)
}
switch dumpType {
@ -162,22 +165,22 @@ func printerWorker(result <-chan parser.Parser) {
Indent: "| ",
NsResolver: nsResolver,
}
parserWorker.GetRootNode().Walk(dumper)
res.parser.GetRootNode().Walk(dumper)
case "json":
dumper := &visitor.JsonDumper{
Writer: os.Stdout,
NsResolver: nsResolver,
}
parserWorker.GetRootNode().Walk(dumper)
res.parser.GetRootNode().Walk(dumper)
case "pretty_json":
dumper := &visitor.PrettyJsonDumper{
Writer: os.Stdout,
NsResolver: nsResolver,
}
parserWorker.GetRootNode().Walk(dumper)
res.parser.GetRootNode().Walk(dumper)
case "go":
dumper := &visitor.GoDumper{Writer: os.Stdout}
parserWorker.GetRootNode().Walk(dumper)
res.parser.GetRootNode().Walk(dumper)
}
wg.Done()

View File

@ -0,0 +1,66 @@
package assign
import (
"github.com/z7zmey/php-parser/freefloating"
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker"
)
// Coalesce node
type Coalesce struct {
FreeFloating freefloating.Collection
Position *position.Position
Variable node.Node
Expression node.Node
}
// NewCoalesce node constructor
func NewCoalesce(Variable node.Node, Expression node.Node) *Coalesce {
return &Coalesce{
FreeFloating: nil,
Variable: Variable,
Expression: Expression,
}
}
// SetPosition sets node position
func (n *Coalesce) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *Coalesce) GetPosition() *position.Position {
return n.Position
}
func (n *Coalesce) GetFreeFloating() *freefloating.Collection {
return &n.FreeFloating
}
// Attributes returns node attributes as map
func (n *Coalesce) Attributes() map[string]interface{} {
return nil
}
// Walk traverses nodes
// Walk is invoked recursively until v.EnterNode returns true
func (n *Coalesce) Walk(v walker.Visitor) {
if v.EnterNode(n) == false {
return
}
if n.Variable != nil {
v.EnterChildNode("Variable", n)
n.Variable.Walk(v)
v.LeaveChildNode("Variable", n)
}
if n.Expression != nil {
v.EnterChildNode("Expression", n)
n.Expression.Walk(v)
v.LeaveChildNode("Expression", n)
}
v.LeaveNode(n)
}

File diff suppressed because it is too large Load Diff

View File

@ -41,6 +41,9 @@ var nodes = []node.Node{
&assign.BitwiseXor{
FreeFloating: expected,
},
&assign.Coalesce{
FreeFloating: expected,
},
&assign.Concat{
FreeFloating: expected,
},

View File

@ -56,6 +56,14 @@ var nodesToTest = []struct {
[]string{"Variable", "Expression"},
nil,
},
{
&assign.Coalesce{
Variable: &expr.Variable{},
Expression: &expr.Variable{},
},
[]string{"Variable", "Expression"},
nil,
},
{
&assign.Concat{
Variable: &expr.Variable{},

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +1,6 @@
package cast_test
import (
"bytes"
"testing"
"gotest.tools/assert"
@ -22,7 +21,7 @@ func TestArray(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 13,
},
Stmts: []node.Node{
@ -30,28 +29,28 @@ func TestArray(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 13,
},
Expr: &cast.Array{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 12,
},
Expr: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 11,
StartPos: 10,
EndPos: 12,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 11,
StartPos: 10,
EndPos: 12,
},
Value: "a",
@ -62,12 +61,12 @@ func TestArray(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -80,7 +79,7 @@ func TestBool(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 15,
},
Stmts: []node.Node{
@ -88,28 +87,28 @@ func TestBool(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 15,
},
Expr: &cast.Bool{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 14,
},
Expr: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 13,
StartPos: 12,
EndPos: 14,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 13,
StartPos: 12,
EndPos: 14,
},
Value: "a",
@ -120,12 +119,12 @@ func TestBool(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -138,7 +137,7 @@ func TestBoolShort(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 12,
},
Stmts: []node.Node{
@ -146,28 +145,28 @@ func TestBoolShort(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 12,
},
Expr: &cast.Bool{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 11,
},
Expr: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
StartPos: 9,
EndPos: 11,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
StartPos: 9,
EndPos: 11,
},
Value: "a",
@ -178,12 +177,12 @@ func TestBoolShort(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -196,7 +195,7 @@ func TestDouble(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 14,
},
Stmts: []node.Node{
@ -204,28 +203,28 @@ func TestDouble(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 14,
},
Expr: &cast.Double{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 13,
},
Expr: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 12,
StartPos: 11,
EndPos: 13,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 12,
StartPos: 11,
EndPos: 13,
},
Value: "a",
@ -236,12 +235,12 @@ func TestDouble(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -254,7 +253,7 @@ func TestCastFloat(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 13,
},
Stmts: []node.Node{
@ -262,28 +261,28 @@ func TestCastFloat(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 13,
},
Expr: &cast.Double{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 12,
},
Expr: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 11,
StartPos: 10,
EndPos: 12,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 11,
StartPos: 10,
EndPos: 12,
},
Value: "a",
@ -294,12 +293,12 @@ func TestCastFloat(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -312,7 +311,7 @@ func TestInt(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 15,
},
Stmts: []node.Node{
@ -320,28 +319,28 @@ func TestInt(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 15,
},
Expr: &cast.Int{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 14,
},
Expr: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 13,
StartPos: 12,
EndPos: 14,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 13,
StartPos: 12,
EndPos: 14,
},
Value: "a",
@ -352,12 +351,12 @@ func TestInt(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -370,7 +369,7 @@ func TestIntShort(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 11,
},
Stmts: []node.Node{
@ -378,28 +377,28 @@ func TestIntShort(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 11,
},
Expr: &cast.Int{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 10,
},
Expr: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 9,
StartPos: 8,
EndPos: 10,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 9,
StartPos: 8,
EndPos: 10,
},
Value: "a",
@ -410,12 +409,12 @@ func TestIntShort(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -428,7 +427,7 @@ func TestObject(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 14,
},
Stmts: []node.Node{
@ -436,28 +435,28 @@ func TestObject(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 14,
},
Expr: &cast.Object{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 13,
},
Expr: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 12,
StartPos: 11,
EndPos: 13,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 12,
StartPos: 11,
EndPos: 13,
},
Value: "a",
@ -468,12 +467,12 @@ func TestObject(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -486,7 +485,7 @@ func TestString(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 14,
},
Stmts: []node.Node{
@ -494,28 +493,28 @@ func TestString(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 14,
},
Expr: &cast.String{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 13,
},
Expr: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 12,
StartPos: 11,
EndPos: 13,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 12,
StartPos: 11,
EndPos: 13,
},
Value: "a",
@ -526,12 +525,12 @@ func TestString(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -544,7 +543,7 @@ func TestBinaryString(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 14,
},
Stmts: []node.Node{
@ -552,28 +551,28 @@ func TestBinaryString(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 14,
},
Expr: &cast.String{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 13,
},
Expr: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 12,
StartPos: 11,
EndPos: 13,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 12,
StartPos: 11,
EndPos: 13,
},
Value: "a",
@ -584,12 +583,12 @@ func TestBinaryString(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -602,7 +601,7 @@ func TestUnset(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 13,
},
Stmts: []node.Node{
@ -610,28 +609,28 @@ func TestUnset(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 13,
},
Expr: &cast.Unset{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 12,
},
Expr: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 11,
StartPos: 10,
EndPos: 12,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 11,
StartPos: 10,
EndPos: 12,
},
Value: "a",
@ -642,12 +641,12 @@ func TestUnset(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@ -13,14 +13,16 @@ type ArrayItem struct {
Position *position.Position
Key node.Node
Val node.Node
Unpack bool
}
// NewArrayItem node constructor
func NewArrayItem(Key node.Node, Val node.Node) *ArrayItem {
func NewArrayItem(Key node.Node, Val node.Node, Unpack bool) *ArrayItem {
return &ArrayItem{
FreeFloating: nil,
Key: Key,
Val: Val,
Unpack: Unpack,
}
}
@ -40,7 +42,9 @@ func (n *ArrayItem) GetFreeFloating() *freefloating.Collection {
// Attributes returns node attributes as map
func (n *ArrayItem) Attributes() map[string]interface{} {
return nil
return map[string]interface{}{
"Unpack": n.Unpack,
}
}
// Walk traverses nodes

View File

@ -0,0 +1,88 @@
package expr
import (
"github.com/z7zmey/php-parser/freefloating"
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker"
)
// ArrowFunction node
type ArrowFunction struct {
FreeFloating freefloating.Collection
Position *position.Position
ReturnsRef bool
Static bool
PhpDocComment string
Params []node.Node
ReturnType node.Node
Expr node.Node
}
// NewArrowFunction node constructor
func NewArrowFunction(Params []node.Node, ReturnType node.Node, Stmt node.Node, Static bool, ReturnsRef bool, PhpDocComment string) *ArrowFunction {
return &ArrowFunction{
FreeFloating: nil,
ReturnsRef: ReturnsRef,
Static: Static,
PhpDocComment: PhpDocComment,
Params: Params,
ReturnType: ReturnType,
Expr: Stmt,
}
}
// SetPosition sets node position
func (n *ArrowFunction) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *ArrowFunction) GetPosition() *position.Position {
return n.Position
}
func (n *ArrowFunction) GetFreeFloating() *freefloating.Collection {
return &n.FreeFloating
}
// Attributes returns node attributes as map
func (n *ArrowFunction) Attributes() map[string]interface{} {
return map[string]interface{}{
"ReturnsRef": n.ReturnsRef,
"Static": n.Static,
"PhpDocComment": n.PhpDocComment,
}
}
// Walk traverses nodes
// Walk is invoked recursively until v.EnterNode returns true
func (n *ArrowFunction) Walk(v walker.Visitor) {
if v.EnterNode(n) == false {
return
}
if n.Params != nil {
v.EnterChildList("Params", n)
for _, nn := range n.Params {
if nn != nil {
nn.Walk(v)
}
}
v.LeaveChildList("Params", n)
}
if n.ReturnType != nil {
v.EnterChildNode("ReturnType", n)
n.ReturnType.Walk(v)
v.LeaveChildNode("ReturnType", n)
}
if n.Expr != nil {
v.EnterChildNode("Expr", n)
n.Expr.Walk(v)
v.LeaveChildNode("Expr", n)
}
v.LeaveNode(n)
}

View File

@ -1,7 +1,6 @@
package expr_test
import (
"bytes"
"testing"
"gotest.tools/assert"
@ -22,7 +21,7 @@ func TestArrayDimFetch(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 9,
},
Stmts: []node.Node{
@ -30,28 +29,28 @@ func TestArrayDimFetch(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 9,
},
Expr: &expr.ArrayDimFetch{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 8,
},
Variable: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 5,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 5,
},
Value: "a",
@ -61,7 +60,7 @@ func TestArrayDimFetch(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 7,
StartPos: 6,
EndPos: 7,
},
Value: "1",
@ -71,12 +70,12 @@ func TestArrayDimFetch(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -89,7 +88,7 @@ func TestArrayDimFetchNested(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 12,
},
Stmts: []node.Node{
@ -97,35 +96,35 @@ func TestArrayDimFetchNested(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 12,
},
Expr: &expr.ArrayDimFetch{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 11,
},
Variable: &expr.ArrayDimFetch{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 8,
},
Variable: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 5,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 5,
},
Value: "a",
@ -135,7 +134,7 @@ func TestArrayDimFetchNested(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 7,
StartPos: 6,
EndPos: 7,
},
Value: "1",
@ -145,7 +144,7 @@ func TestArrayDimFetchNested(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
StartPos: 9,
EndPos: 10,
},
Value: "2",
@ -155,12 +154,12 @@ func TestArrayDimFetchNested(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@ -1,7 +1,6 @@
package expr_test
import (
"bytes"
"testing"
"gotest.tools/assert"
@ -22,7 +21,7 @@ func TestArray(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 11,
},
Stmts: []node.Node{
@ -30,14 +29,14 @@ func TestArray(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 11,
},
Expr: &expr.Array{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 10,
},
Items: []node.Node{},
@ -46,12 +45,12 @@ func TestArray(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -64,7 +63,7 @@ func TestArrayItem(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 12,
},
Stmts: []node.Node{
@ -72,14 +71,14 @@ func TestArrayItem(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 12,
},
Expr: &expr.Array{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 11,
},
Items: []node.Node{
@ -87,14 +86,14 @@ func TestArrayItem(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
StartPos: 9,
EndPos: 10,
},
Val: &scalar.Lnumber{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
StartPos: 9,
EndPos: 10,
},
Value: "1",
@ -106,12 +105,12 @@ func TestArrayItem(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -124,7 +123,7 @@ func TestArrayItems(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 21,
},
Stmts: []node.Node{
@ -132,14 +131,14 @@ func TestArrayItems(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 21,
},
Expr: &expr.Array{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 20,
},
Items: []node.Node{
@ -147,14 +146,14 @@ func TestArrayItems(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
StartPos: 9,
EndPos: 13,
},
Key: &scalar.Lnumber{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
StartPos: 9,
EndPos: 10,
},
Value: "1",
@ -163,7 +162,7 @@ func TestArrayItems(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 13,
StartPos: 12,
EndPos: 13,
},
Value: "1",
@ -173,28 +172,28 @@ func TestArrayItems(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 16,
StartPos: 15,
EndPos: 18,
},
Val: &expr.Reference{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 16,
StartPos: 15,
EndPos: 18,
},
Variable: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 17,
StartPos: 16,
EndPos: 18,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 17,
StartPos: 16,
EndPos: 18,
},
Value: "b",
@ -209,13 +208,77 @@ func TestArrayItems(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
}
func TestArrayItemUnpack(t *testing.T) {
src := `<? array(...$b);`
expected := &node.Root{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 3,
EndPos: 16,
},
Stmts: []node.Node{
&stmt.Expression{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 3,
EndPos: 16,
},
Expr: &expr.Array{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 3,
EndPos: 15,
},
Items: []node.Node{
&expr.ArrayItem{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 9,
EndPos: 14,
},
Unpack: true,
Val: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 12,
EndPos: 14,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 12,
EndPos: 14,
},
Value: "b",
},
},
},
},
},
},
},
}
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
}

View File

@ -0,0 +1,144 @@
package expr_test
import (
"testing"
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/node/expr"
"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/position"
"gotest.tools/assert"
)
func TestArrowFunction(t *testing.T) {
src := `<? fn() => $a;`
expected := &node.Root{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 3,
EndPos: 14,
},
Stmts: []node.Node{
&stmt.Expression{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 3,
EndPos: 14,
},
Expr: &expr.ArrowFunction{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 3,
EndPos: 13,
},
ReturnsRef: false,
Static: false,
PhpDocComment: "",
Expr: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 11,
EndPos: 13,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 11,
EndPos: 13,
},
Value: "a",
},
},
},
},
},
}
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
}
func TestArrowFunctionReturnType(t *testing.T) {
src := `<? fn & () : foo => $a;`
expected := &node.Root{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 3,
EndPos: 23,
},
Stmts: []node.Node{
&stmt.Expression{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 3,
EndPos: 23,
},
Expr: &expr.ArrowFunction{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 3,
EndPos: 22,
},
Static: false,
PhpDocComment: "",
ReturnsRef: true,
ReturnType: &name.Name{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 13,
EndPos: 16,
},
Parts: []node.Node{
&name.NamePart{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 13,
EndPos: 16,
},
Value: "foo",
},
},
},
Expr: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 20,
EndPos: 22,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 20,
EndPos: 22,
},
Value: "a",
},
},
},
},
},
}
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
}

View File

@ -1,7 +1,6 @@
package expr_test
import (
"bytes"
"testing"
"gotest.tools/assert"
@ -22,7 +21,7 @@ func TestBitwiseNot(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 7,
},
Stmts: []node.Node{
@ -30,28 +29,28 @@ func TestBitwiseNot(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 7,
},
Expr: &expr.BitwiseNot{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 6,
},
Expr: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 5,
StartPos: 4,
EndPos: 6,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 5,
StartPos: 4,
EndPos: 6,
},
Value: "a",
@ -62,12 +61,12 @@ func TestBitwiseNot(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@ -1,7 +1,6 @@
package expr_test
import (
"bytes"
"testing"
"gotest.tools/assert"
@ -22,7 +21,7 @@ func TestBooleanNot(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 7,
},
Stmts: []node.Node{
@ -30,28 +29,28 @@ func TestBooleanNot(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 7,
},
Expr: &expr.BooleanNot{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 6,
},
Expr: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 5,
StartPos: 4,
EndPos: 6,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 5,
StartPos: 4,
EndPos: 6,
},
Value: "a",
@ -62,12 +61,12 @@ func TestBooleanNot(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@ -1,7 +1,6 @@
package expr_test
import (
"bytes"
"testing"
"gotest.tools/assert"
@ -24,7 +23,7 @@ func TestClassConstFetch(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 12,
},
Stmts: []node.Node{
@ -32,21 +31,21 @@ func TestClassConstFetch(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 12,
},
Expr: &expr.ClassConstFetch{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 11,
},
Class: &name.Name{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 6,
},
Parts: []node.Node{
@ -54,7 +53,7 @@ func TestClassConstFetch(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 6,
},
Value: "Foo",
@ -65,7 +64,7 @@ func TestClassConstFetch(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 9,
StartPos: 8,
EndPos: 11,
},
Value: "Bar",
@ -75,12 +74,12 @@ func TestClassConstFetch(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -93,7 +92,7 @@ func TestStaticClassConstFetch(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 15,
},
Stmts: []node.Node{
@ -101,21 +100,21 @@ func TestStaticClassConstFetch(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 15,
},
Expr: &expr.ClassConstFetch{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 14,
},
Class: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 9,
},
Value: "static",
@ -124,7 +123,7 @@ func TestStaticClassConstFetch(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 12,
StartPos: 11,
EndPos: 14,
},
Value: "bar",
@ -134,12 +133,12 @@ func TestStaticClassConstFetch(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@ -1,7 +1,6 @@
package expr_test
import (
"bytes"
"testing"
"gotest.tools/assert"
@ -22,7 +21,7 @@ func TestCloneBrackets(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 13,
},
Stmts: []node.Node{
@ -30,28 +29,28 @@ func TestCloneBrackets(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 13,
},
Expr: &expr.Clone{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 11,
},
Expr: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
StartPos: 9,
EndPos: 11,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
StartPos: 9,
EndPos: 11,
},
Value: "a",
@ -62,12 +61,12 @@ func TestCloneBrackets(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -80,7 +79,7 @@ func TestClone(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 12,
},
Stmts: []node.Node{
@ -88,28 +87,28 @@ func TestClone(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 12,
},
Expr: &expr.Clone{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 11,
},
Expr: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
StartPos: 9,
EndPos: 11,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
StartPos: 9,
EndPos: 11,
},
Value: "a",
@ -120,12 +119,12 @@ func TestClone(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@ -1,7 +1,6 @@
package expr_test
import (
"bytes"
"testing"
"gotest.tools/assert"
@ -24,7 +23,7 @@ func TestClosure(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 16,
},
Stmts: []node.Node{
@ -32,14 +31,14 @@ func TestClosure(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 16,
},
Expr: &expr.Closure{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 15,
},
ReturnsRef: false,
@ -51,12 +50,12 @@ func TestClosure(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -69,7 +68,7 @@ func TestClosureUse(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 37,
},
Stmts: []node.Node{
@ -77,14 +76,14 @@ func TestClosureUse(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 37,
},
Expr: &expr.Closure{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 36,
},
ReturnsRef: false,
@ -95,7 +94,7 @@ func TestClosureUse(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 13,
StartPos: 12,
EndPos: 14,
},
Variadic: false,
@ -104,14 +103,14 @@ func TestClosureUse(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 13,
StartPos: 12,
EndPos: 14,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 13,
StartPos: 12,
EndPos: 14,
},
Value: "a",
@ -122,7 +121,7 @@ func TestClosureUse(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 17,
StartPos: 16,
EndPos: 18,
},
ByRef: false,
@ -131,14 +130,14 @@ func TestClosureUse(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 17,
StartPos: 16,
EndPos: 18,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 17,
StartPos: 16,
EndPos: 18,
},
Value: "b",
@ -150,7 +149,7 @@ func TestClosureUse(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 21,
StartPos: 20,
EndPos: 33,
},
Uses: []node.Node{
@ -158,14 +157,14 @@ func TestClosureUse(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 26,
StartPos: 25,
EndPos: 27,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 26,
StartPos: 25,
EndPos: 27,
},
Value: "c",
@ -175,21 +174,21 @@ func TestClosureUse(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 30,
StartPos: 29,
EndPos: 32,
},
Variable: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 31,
StartPos: 30,
EndPos: 32,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 31,
StartPos: 30,
EndPos: 32,
},
Value: "d",
@ -204,12 +203,12 @@ func TestClosureUse(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -222,7 +221,7 @@ func TestClosureUse2(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 37,
},
Stmts: []node.Node{
@ -230,14 +229,14 @@ func TestClosureUse2(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 37,
},
Expr: &expr.Closure{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 36,
},
ReturnsRef: false,
@ -248,7 +247,7 @@ func TestClosureUse2(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 13,
StartPos: 12,
EndPos: 14,
},
ByRef: false,
@ -257,14 +256,14 @@ func TestClosureUse2(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 13,
StartPos: 12,
EndPos: 14,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 13,
StartPos: 12,
EndPos: 14,
},
Value: "a",
@ -275,7 +274,7 @@ func TestClosureUse2(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 17,
StartPos: 16,
EndPos: 18,
},
ByRef: false,
@ -284,14 +283,14 @@ func TestClosureUse2(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 17,
StartPos: 16,
EndPos: 18,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 17,
StartPos: 16,
EndPos: 18,
},
Value: "b",
@ -303,7 +302,7 @@ func TestClosureUse2(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 21,
StartPos: 20,
EndPos: 33,
},
Uses: []node.Node{
@ -311,21 +310,21 @@ func TestClosureUse2(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 26,
StartPos: 25,
EndPos: 28,
},
Variable: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 27,
StartPos: 26,
EndPos: 28,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 27,
StartPos: 26,
EndPos: 28,
},
Value: "c",
@ -336,14 +335,14 @@ func TestClosureUse2(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 31,
StartPos: 30,
EndPos: 32,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 31,
StartPos: 30,
EndPos: 32,
},
Value: "d",
@ -357,12 +356,12 @@ func TestClosureUse2(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -375,7 +374,7 @@ func TestClosureReturnType(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 23,
},
Stmts: []node.Node{
@ -383,14 +382,14 @@ func TestClosureReturnType(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 23,
},
Expr: &expr.Closure{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 22,
},
PhpDocComment: "",
@ -400,7 +399,7 @@ func TestClosureReturnType(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 16,
StartPos: 15,
EndPos: 19,
},
Parts: []node.Node{
@ -408,7 +407,7 @@ func TestClosureReturnType(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 16,
StartPos: 15,
EndPos: 19,
},
Value: "void",
@ -421,7 +420,7 @@ func TestClosureReturnType(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@ -1,7 +1,6 @@
package expr_test
import (
"bytes"
"testing"
"gotest.tools/assert"
@ -24,7 +23,7 @@ func TestConstFetch(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 7,
},
Stmts: []node.Node{
@ -32,21 +31,21 @@ func TestConstFetch(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 7,
},
Expr: &expr.ConstFetch{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 6,
},
Constant: &name.Name{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 6,
},
Parts: []node.Node{
@ -54,7 +53,7 @@ func TestConstFetch(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 6,
},
Value: "foo",
@ -66,12 +65,12 @@ func TestConstFetch(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -84,7 +83,7 @@ func TestConstFetchRelative(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 17,
},
Stmts: []node.Node{
@ -92,21 +91,21 @@ func TestConstFetchRelative(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 17,
},
Expr: &expr.ConstFetch{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 16,
},
Constant: &name.Relative{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 16,
},
Parts: []node.Node{
@ -114,7 +113,7 @@ func TestConstFetchRelative(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 14,
StartPos: 13,
EndPos: 16,
},
Value: "foo",
@ -126,12 +125,12 @@ func TestConstFetchRelative(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -144,7 +143,7 @@ func TestConstFetchFullyQualified(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 8,
},
Stmts: []node.Node{
@ -152,21 +151,21 @@ func TestConstFetchFullyQualified(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 8,
},
Expr: &expr.ConstFetch{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 7,
},
Constant: &name.FullyQualified{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 7,
},
Parts: []node.Node{
@ -174,7 +173,7 @@ func TestConstFetchFullyQualified(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 5,
StartPos: 4,
EndPos: 7,
},
Value: "foo",
@ -186,12 +185,12 @@ func TestConstFetchFullyQualified(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@ -1,7 +1,6 @@
package expr_test
import (
"bytes"
"testing"
"gotest.tools/assert"
@ -22,7 +21,7 @@ func TestEmpty(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 13,
},
Stmts: []node.Node{
@ -30,28 +29,28 @@ func TestEmpty(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 13,
},
Expr: &expr.Empty{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 12,
},
Expr: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
StartPos: 9,
EndPos: 11,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
StartPos: 9,
EndPos: 11,
},
Value: "a",
@ -62,12 +61,12 @@ func TestEmpty(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@ -1,7 +1,6 @@
package expr_test
import (
"bytes"
"testing"
"gotest.tools/assert"
@ -22,7 +21,7 @@ func TestErrorSuppress(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 7,
},
Stmts: []node.Node{
@ -30,28 +29,28 @@ func TestErrorSuppress(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 7,
},
Expr: &expr.ErrorSuppress{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 6,
},
Expr: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 5,
StartPos: 4,
EndPos: 6,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 5,
StartPos: 4,
EndPos: 6,
},
Value: "a",
@ -62,12 +61,12 @@ func TestErrorSuppress(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@ -1,7 +1,6 @@
package expr_test
import (
"bytes"
"testing"
"gotest.tools/assert"
@ -22,7 +21,7 @@ func TestEval(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 12,
},
Stmts: []node.Node{
@ -30,28 +29,28 @@ func TestEval(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 12,
},
Expr: &expr.Eval{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 11,
},
Expr: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 9,
StartPos: 8,
EndPos: 10,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 9,
StartPos: 8,
EndPos: 10,
},
Value: "a",
@ -62,12 +61,12 @@ func TestEval(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@ -1,7 +1,6 @@
package expr_test
import (
"bytes"
"testing"
"gotest.tools/assert"
@ -22,7 +21,7 @@ func TestExit(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 8,
},
Stmts: []node.Node{
@ -30,7 +29,7 @@ func TestExit(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 8,
},
Expr: &expr.Exit{
@ -38,7 +37,7 @@ func TestExit(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 7,
},
},
@ -46,12 +45,12 @@ func TestExit(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -64,7 +63,7 @@ func TestExitEmpty(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 10,
},
Stmts: []node.Node{
@ -72,7 +71,7 @@ func TestExitEmpty(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 10,
},
Expr: &expr.Exit{
@ -80,7 +79,7 @@ func TestExitEmpty(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 9,
},
},
@ -88,12 +87,12 @@ func TestExitEmpty(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -106,7 +105,7 @@ func TestExitExpr(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 12,
},
Stmts: []node.Node{
@ -114,7 +113,7 @@ func TestExitExpr(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 12,
},
Expr: &expr.Exit{
@ -122,21 +121,21 @@ func TestExitExpr(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 11,
},
Expr: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 9,
StartPos: 8,
EndPos: 10,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 9,
StartPos: 8,
EndPos: 10,
},
Value: "a",
@ -147,12 +146,12 @@ func TestExitExpr(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -165,7 +164,7 @@ func TestDie(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 7,
},
Stmts: []node.Node{
@ -173,7 +172,7 @@ func TestDie(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 7,
},
Expr: &expr.Exit{
@ -181,7 +180,7 @@ func TestDie(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 6,
},
},
@ -189,12 +188,12 @@ func TestDie(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -207,7 +206,7 @@ func TestDieEmpty(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 9,
},
Stmts: []node.Node{
@ -215,7 +214,7 @@ func TestDieEmpty(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 9,
},
Expr: &expr.Exit{
@ -223,7 +222,7 @@ func TestDieEmpty(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 8,
},
},
@ -231,12 +230,12 @@ func TestDieEmpty(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -249,7 +248,7 @@ func TestDieExpr(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 11,
},
Stmts: []node.Node{
@ -257,7 +256,7 @@ func TestDieExpr(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 11,
},
Expr: &expr.Exit{
@ -265,21 +264,21 @@ func TestDieExpr(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 10,
},
Expr: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 8,
StartPos: 7,
EndPos: 9,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 8,
StartPos: 7,
EndPos: 9,
},
Value: "a",
@ -290,12 +289,12 @@ func TestDieExpr(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@ -35,6 +35,9 @@ var nodes = []node.Node{
&expr.Array{
FreeFloating: expected,
},
&expr.ArrowFunction{
FreeFloating: expected,
},
&expr.BitwiseNot{
FreeFloating: expected,
},

View File

@ -1,7 +1,6 @@
package expr_test
import (
"bytes"
"testing"
"gotest.tools/assert"
@ -27,7 +26,7 @@ func TestFunctionCall(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 9,
},
Stmts: []node.Node{
@ -35,21 +34,21 @@ func TestFunctionCall(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 9,
},
Expr: &expr.FunctionCall{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 8,
},
Function: &name.Name{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 6,
},
Parts: []node.Node{
@ -57,7 +56,7 @@ func TestFunctionCall(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 6,
},
Value: "foo",
@ -68,7 +67,7 @@ func TestFunctionCall(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 7,
StartPos: 6,
EndPos: 8,
},
},
@ -77,12 +76,12 @@ func TestFunctionCall(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -95,7 +94,7 @@ func TestFunctionCallRelative(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 19,
},
Stmts: []node.Node{
@ -103,21 +102,21 @@ func TestFunctionCallRelative(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 19,
},
Expr: &expr.FunctionCall{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 18,
},
Function: &name.Relative{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 16,
},
Parts: []node.Node{
@ -125,7 +124,7 @@ func TestFunctionCallRelative(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 14,
StartPos: 13,
EndPos: 16,
},
Value: "foo",
@ -136,7 +135,7 @@ func TestFunctionCallRelative(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 17,
StartPos: 16,
EndPos: 18,
},
},
@ -145,12 +144,12 @@ func TestFunctionCallRelative(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -163,7 +162,7 @@ func TestFunctionFullyQualified(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 12,
},
Stmts: []node.Node{
@ -171,21 +170,21 @@ func TestFunctionFullyQualified(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 12,
},
Expr: &expr.FunctionCall{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 11,
},
Function: &name.FullyQualified{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 7,
},
Parts: []node.Node{
@ -193,7 +192,7 @@ func TestFunctionFullyQualified(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 5,
StartPos: 4,
EndPos: 7,
},
Value: "foo",
@ -204,7 +203,7 @@ func TestFunctionFullyQualified(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 8,
StartPos: 7,
EndPos: 11,
},
Arguments: []node.Node{
@ -212,7 +211,7 @@ func TestFunctionFullyQualified(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 9,
StartPos: 8,
EndPos: 10,
},
Variadic: false,
@ -221,7 +220,7 @@ func TestFunctionFullyQualified(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 9,
StartPos: 8,
EndPos: 10,
},
Items: []node.Node{},
@ -234,12 +233,12 @@ func TestFunctionFullyQualified(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -252,7 +251,7 @@ func TestFunctionCallVar(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 18,
},
Stmts: []node.Node{
@ -260,28 +259,28 @@ func TestFunctionCallVar(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 18,
},
Expr: &expr.FunctionCall{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 17,
},
Function: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 7,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 7,
},
Value: "foo",
@ -291,7 +290,7 @@ func TestFunctionCallVar(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 8,
StartPos: 7,
EndPos: 17,
},
Arguments: []node.Node{
@ -299,7 +298,7 @@ func TestFunctionCallVar(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 9,
StartPos: 8,
EndPos: 16,
},
Variadic: false,
@ -308,21 +307,21 @@ func TestFunctionCallVar(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 9,
StartPos: 8,
EndPos: 16,
},
Value: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 15,
StartPos: 14,
EndPos: 16,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 15,
StartPos: 14,
EndPos: 16,
},
Value: "a",
@ -337,12 +336,12 @@ func TestFunctionCallVar(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -355,7 +354,7 @@ func TestFunctionCallExprArg(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 16,
},
Stmts: []node.Node{
@ -363,21 +362,21 @@ func TestFunctionCallExprArg(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 16,
},
Expr: &expr.FunctionCall{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 15,
},
Function: &name.Name{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 7,
},
Parts: []node.Node{
@ -385,7 +384,7 @@ func TestFunctionCallExprArg(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 7,
},
Value: "ceil",
@ -396,7 +395,7 @@ func TestFunctionCallExprArg(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 8,
StartPos: 7,
EndPos: 15,
},
Arguments: []node.Node{
@ -404,7 +403,7 @@ func TestFunctionCallExprArg(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 9,
StartPos: 8,
EndPos: 14,
},
Variadic: false,
@ -413,21 +412,21 @@ func TestFunctionCallExprArg(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 9,
StartPos: 8,
EndPos: 14,
},
Left: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 9,
StartPos: 8,
EndPos: 12,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 9,
StartPos: 8,
EndPos: 12,
},
Value: "foo",
@ -437,7 +436,7 @@ func TestFunctionCallExprArg(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 14,
StartPos: 13,
EndPos: 14,
},
Value: "3",
@ -451,12 +450,12 @@ func TestFunctionCallExprArg(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@ -1,7 +1,6 @@
package expr_test
import (
"bytes"
"testing"
"gotest.tools/assert"
@ -22,7 +21,7 @@ func TestPostDec(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 8,
},
Stmts: []node.Node{
@ -30,28 +29,28 @@ func TestPostDec(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 8,
},
Expr: &expr.PostDec{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 7,
},
Variable: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 5,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 5,
},
Value: "a",
@ -62,12 +61,12 @@ func TestPostDec(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -80,7 +79,7 @@ func TestPostInc(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 8,
},
Stmts: []node.Node{
@ -88,28 +87,28 @@ func TestPostInc(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 8,
},
Expr: &expr.PostInc{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 7,
},
Variable: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 5,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 5,
},
Value: "a",
@ -120,12 +119,12 @@ func TestPostInc(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -138,7 +137,7 @@ func TestPreDec(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 8,
},
Stmts: []node.Node{
@ -146,28 +145,28 @@ func TestPreDec(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 8,
},
Expr: &expr.PreDec{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 7,
},
Variable: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 6,
StartPos: 5,
EndPos: 7,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 6,
StartPos: 5,
EndPos: 7,
},
Value: "a",
@ -178,12 +177,12 @@ func TestPreDec(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -196,7 +195,7 @@ func TestPreInc(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 8,
},
Stmts: []node.Node{
@ -204,28 +203,28 @@ func TestPreInc(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 8,
},
Expr: &expr.PreInc{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 7,
},
Variable: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 6,
StartPos: 5,
EndPos: 7,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 6,
StartPos: 5,
EndPos: 7,
},
Value: "a",
@ -236,12 +235,12 @@ func TestPreInc(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@ -1,7 +1,6 @@
package expr_test
import (
"bytes"
"testing"
"gotest.tools/assert"
@ -22,7 +21,7 @@ func TestInclude(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 14,
},
Stmts: []node.Node{
@ -30,28 +29,28 @@ func TestInclude(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 14,
},
Expr: &expr.Include{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 13,
},
Expr: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 12,
StartPos: 11,
EndPos: 13,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 12,
StartPos: 11,
EndPos: 13,
},
Value: "a",
@ -62,12 +61,12 @@ func TestInclude(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -80,7 +79,7 @@ func TestIncludeOnce(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 19,
},
Stmts: []node.Node{
@ -88,28 +87,28 @@ func TestIncludeOnce(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 19,
},
Expr: &expr.IncludeOnce{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 18,
},
Expr: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 17,
StartPos: 16,
EndPos: 18,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 17,
StartPos: 16,
EndPos: 18,
},
Value: "a",
@ -120,12 +119,12 @@ func TestIncludeOnce(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -138,7 +137,7 @@ func TestRequire(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 14,
},
Stmts: []node.Node{
@ -146,28 +145,28 @@ func TestRequire(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 14,
},
Expr: &expr.Require{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 13,
},
Expr: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 12,
StartPos: 11,
EndPos: 13,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 12,
StartPos: 11,
EndPos: 13,
},
Value: "a",
@ -178,12 +177,12 @@ func TestRequire(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -196,7 +195,7 @@ func TestRequireOnce(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 19,
},
Stmts: []node.Node{
@ -204,28 +203,28 @@ func TestRequireOnce(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 19,
},
Expr: &expr.RequireOnce{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 18,
},
Expr: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 17,
StartPos: 16,
EndPos: 18,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 17,
StartPos: 16,
EndPos: 18,
},
Value: "a",
@ -236,12 +235,12 @@ func TestRequireOnce(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@ -1,7 +1,6 @@
package expr_test
import (
"bytes"
"testing"
"gotest.tools/assert"
@ -24,7 +23,7 @@ func TestInstanceOf(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 21,
},
Stmts: []node.Node{
@ -32,28 +31,28 @@ func TestInstanceOf(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 21,
},
Expr: &expr.InstanceOf{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 20,
},
Expr: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 5,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 5,
},
Value: "a",
@ -63,7 +62,7 @@ func TestInstanceOf(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 18,
StartPos: 17,
EndPos: 20,
},
Parts: []node.Node{
@ -71,7 +70,7 @@ func TestInstanceOf(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 18,
StartPos: 17,
EndPos: 20,
},
Value: "Foo",
@ -83,12 +82,12 @@ func TestInstanceOf(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -101,7 +100,7 @@ func TestInstanceOfRelative(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 31,
},
Stmts: []node.Node{
@ -109,28 +108,28 @@ func TestInstanceOfRelative(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 31,
},
Expr: &expr.InstanceOf{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 30,
},
Expr: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 5,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 5,
},
Value: "a",
@ -140,7 +139,7 @@ func TestInstanceOfRelative(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 18,
StartPos: 17,
EndPos: 30,
},
Parts: []node.Node{
@ -148,7 +147,7 @@ func TestInstanceOfRelative(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 28,
StartPos: 27,
EndPos: 30,
},
Value: "Foo",
@ -160,12 +159,12 @@ func TestInstanceOfRelative(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -178,7 +177,7 @@ func TestInstanceOfFullyQualified(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 22,
},
Stmts: []node.Node{
@ -186,28 +185,28 @@ func TestInstanceOfFullyQualified(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 22,
},
Expr: &expr.InstanceOf{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 21,
},
Expr: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 5,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 5,
},
Value: "a",
@ -217,7 +216,7 @@ func TestInstanceOfFullyQualified(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 18,
StartPos: 17,
EndPos: 21,
},
Parts: []node.Node{
@ -225,7 +224,7 @@ func TestInstanceOfFullyQualified(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 19,
StartPos: 18,
EndPos: 21,
},
Value: "Foo",
@ -237,12 +236,12 @@ func TestInstanceOfFullyQualified(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@ -1,7 +1,6 @@
package expr_test
import (
"bytes"
"testing"
"gotest.tools/assert"
@ -22,7 +21,7 @@ func TestIsset(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 13,
},
Stmts: []node.Node{
@ -30,14 +29,14 @@ func TestIsset(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 13,
},
Expr: &expr.Isset{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 12,
},
Variables: []node.Node{
@ -45,14 +44,14 @@ func TestIsset(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
StartPos: 9,
EndPos: 11,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
StartPos: 9,
EndPos: 11,
},
Value: "a",
@ -64,12 +63,12 @@ func TestIsset(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -82,7 +81,7 @@ func TestIssetVariables(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 17,
},
Stmts: []node.Node{
@ -90,14 +89,14 @@ func TestIssetVariables(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 17,
},
Expr: &expr.Isset{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 16,
},
Variables: []node.Node{
@ -105,14 +104,14 @@ func TestIssetVariables(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
StartPos: 9,
EndPos: 11,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
StartPos: 9,
EndPos: 11,
},
Value: "a",
@ -122,14 +121,14 @@ func TestIssetVariables(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 14,
StartPos: 13,
EndPos: 15,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 14,
StartPos: 13,
EndPos: 15,
},
Value: "b",
@ -141,12 +140,12 @@ func TestIssetVariables(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@ -1,7 +1,6 @@
package expr_test
import (
"bytes"
"testing"
"gotest.tools/assert"
@ -22,7 +21,7 @@ func TestEmptyList(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 15,
},
Stmts: []node.Node{
@ -30,21 +29,21 @@ func TestEmptyList(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 15,
},
Expr: &assign.Assign{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 14,
},
Variable: &expr.List{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 9,
},
Items: []node.Node{},
@ -53,14 +52,14 @@ func TestEmptyList(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 13,
StartPos: 12,
EndPos: 14,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 13,
StartPos: 12,
EndPos: 14,
},
Value: "b",
@ -71,12 +70,12 @@ func TestEmptyList(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -89,7 +88,7 @@ func TestList(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 17,
},
Stmts: []node.Node{
@ -97,21 +96,21 @@ func TestList(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 17,
},
Expr: &assign.Assign{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 16,
},
Variable: &expr.List{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 11,
},
Items: []node.Node{
@ -119,21 +118,21 @@ func TestList(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 9,
StartPos: 8,
EndPos: 10,
},
Val: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 9,
StartPos: 8,
EndPos: 10,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 9,
StartPos: 8,
EndPos: 10,
},
Value: "a",
@ -146,14 +145,14 @@ func TestList(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 15,
StartPos: 14,
EndPos: 16,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 15,
StartPos: 14,
EndPos: 16,
},
Value: "b",
@ -164,12 +163,12 @@ func TestList(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -182,7 +181,7 @@ func TestListArrayIndex(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 19,
},
Stmts: []node.Node{
@ -190,21 +189,21 @@ func TestListArrayIndex(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 19,
},
Expr: &assign.Assign{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 18,
},
Variable: &expr.List{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 13,
},
Items: []node.Node{
@ -212,28 +211,28 @@ func TestListArrayIndex(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 9,
StartPos: 8,
EndPos: 12,
},
Val: &expr.ArrayDimFetch{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 9,
StartPos: 8,
EndPos: 12,
},
Variable: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 9,
StartPos: 8,
EndPos: 10,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 9,
StartPos: 8,
EndPos: 10,
},
Value: "a",
@ -247,14 +246,14 @@ func TestListArrayIndex(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 17,
StartPos: 16,
EndPos: 18,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 17,
StartPos: 16,
EndPos: 18,
},
Value: "b",
@ -265,12 +264,12 @@ func TestListArrayIndex(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -283,7 +282,7 @@ func TestListList(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 23,
},
Stmts: []node.Node{
@ -291,21 +290,21 @@ func TestListList(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 23,
},
Expr: &assign.Assign{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 22,
},
Variable: &expr.List{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 17,
},
Items: []node.Node{
@ -313,14 +312,14 @@ func TestListList(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 9,
StartPos: 8,
EndPos: 16,
},
Val: &expr.List{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 9,
StartPos: 8,
EndPos: 16,
},
Items: []node.Node{
@ -328,21 +327,21 @@ func TestListList(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 14,
StartPos: 13,
EndPos: 15,
},
Val: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 14,
StartPos: 13,
EndPos: 15,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 14,
StartPos: 13,
EndPos: 15,
},
Value: "a",
@ -358,14 +357,14 @@ func TestListList(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 21,
StartPos: 20,
EndPos: 22,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 21,
StartPos: 20,
EndPos: 22,
},
Value: "b",
@ -376,12 +375,12 @@ func TestListList(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -394,7 +393,7 @@ func TestListEmptyItem(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 19,
},
Stmts: []node.Node{
@ -402,21 +401,21 @@ func TestListEmptyItem(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 19,
},
Expr: &assign.Assign{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 18,
},
Variable: &expr.List{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 13,
},
Items: []node.Node{
@ -425,21 +424,21 @@ func TestListEmptyItem(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 11,
StartPos: 10,
EndPos: 12,
},
Val: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 11,
StartPos: 10,
EndPos: 12,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 11,
StartPos: 10,
EndPos: 12,
},
Value: "a",
@ -452,14 +451,14 @@ func TestListEmptyItem(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 17,
StartPos: 16,
EndPos: 18,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 17,
StartPos: 16,
EndPos: 18,
},
Value: "b",
@ -470,12 +469,12 @@ func TestListEmptyItem(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -488,7 +487,7 @@ func TestListEmptyItems(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 23,
},
Stmts: []node.Node{
@ -496,21 +495,21 @@ func TestListEmptyItems(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 23,
},
Expr: &assign.Assign{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 22,
},
Variable: &expr.List{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 17,
},
Items: []node.Node{
@ -520,21 +519,21 @@ func TestListEmptyItems(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 13,
StartPos: 12,
EndPos: 14,
},
Val: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 13,
StartPos: 12,
EndPos: 14,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 13,
StartPos: 12,
EndPos: 14,
},
Value: "a",
@ -548,14 +547,14 @@ func TestListEmptyItems(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 21,
StartPos: 20,
EndPos: 22,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 21,
StartPos: 20,
EndPos: 22,
},
Value: "b",
@ -566,12 +565,12 @@ func TestListEmptyItems(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@ -1,7 +1,6 @@
package expr_test
import (
"bytes"
"testing"
"gotest.tools/assert"
@ -22,7 +21,7 @@ func TestMethodCall(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 13,
},
Stmts: []node.Node{
@ -30,28 +29,28 @@ func TestMethodCall(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 13,
},
Expr: &expr.MethodCall{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 12,
},
Variable: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 5,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 5,
},
Value: "a",
@ -61,7 +60,7 @@ func TestMethodCall(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 8,
StartPos: 7,
EndPos: 10,
},
Value: "foo",
@ -70,7 +69,7 @@ func TestMethodCall(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 11,
StartPos: 10,
EndPos: 12,
},
},
@ -79,12 +78,12 @@ func TestMethodCall(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@ -1,7 +1,6 @@
package expr_test
import (
"bytes"
"testing"
"gotest.tools/assert"
@ -24,7 +23,7 @@ func TestNew(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 11,
},
Stmts: []node.Node{
@ -32,21 +31,21 @@ func TestNew(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 11,
},
Expr: &expr.New{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 10,
},
Class: &name.Name{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 8,
StartPos: 7,
EndPos: 10,
},
Parts: []node.Node{
@ -54,7 +53,7 @@ func TestNew(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 8,
StartPos: 7,
EndPos: 10,
},
Value: "Foo",
@ -66,12 +65,12 @@ func TestNew(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -84,7 +83,7 @@ func TestNewRelative(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 23,
},
Stmts: []node.Node{
@ -92,21 +91,21 @@ func TestNewRelative(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 23,
},
Expr: &expr.New{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 22,
},
Class: &name.Relative{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 8,
StartPos: 7,
EndPos: 20,
},
Parts: []node.Node{
@ -114,7 +113,7 @@ func TestNewRelative(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 18,
StartPos: 17,
EndPos: 20,
},
Value: "Foo",
@ -125,7 +124,7 @@ func TestNewRelative(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 21,
StartPos: 20,
EndPos: 22,
},
},
@ -134,12 +133,12 @@ func TestNewRelative(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -152,7 +151,7 @@ func TestNewFullyQualified(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 14,
},
Stmts: []node.Node{
@ -160,21 +159,21 @@ func TestNewFullyQualified(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 14,
},
Expr: &expr.New{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 13,
},
Class: &name.FullyQualified{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 8,
StartPos: 7,
EndPos: 11,
},
Parts: []node.Node{
@ -182,7 +181,7 @@ func TestNewFullyQualified(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 9,
StartPos: 8,
EndPos: 11,
},
Value: "Foo",
@ -193,7 +192,7 @@ func TestNewFullyQualified(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 12,
StartPos: 11,
EndPos: 13,
},
},
@ -202,12 +201,12 @@ func TestNewFullyQualified(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -220,7 +219,7 @@ func TestNewAnonymous(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 28,
},
Stmts: []node.Node{
@ -228,21 +227,21 @@ func TestNewAnonymous(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 28,
},
Expr: &expr.New{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 27,
},
Class: &stmt.Class{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 8,
StartPos: 7,
EndPos: 27,
},
PhpDocComment: "",
@ -250,7 +249,7 @@ func TestNewAnonymous(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 14,
StartPos: 13,
EndPos: 24,
},
Arguments: []node.Node{
@ -258,7 +257,7 @@ func TestNewAnonymous(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 15,
StartPos: 14,
EndPos: 16,
},
Variadic: false,
@ -267,14 +266,14 @@ func TestNewAnonymous(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 15,
StartPos: 14,
EndPos: 16,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 15,
StartPos: 14,
EndPos: 16,
},
Value: "a",
@ -285,7 +284,7 @@ func TestNewAnonymous(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 19,
StartPos: 18,
EndPos: 23,
},
IsReference: false,
@ -294,14 +293,14 @@ func TestNewAnonymous(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 22,
StartPos: 21,
EndPos: 23,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 22,
StartPos: 21,
EndPos: 23,
},
Value: "b",
@ -317,7 +316,7 @@ func TestNewAnonymous(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@ -1,7 +1,6 @@
package expr_test
import (
"bytes"
"testing"
"gotest.tools/assert"
@ -22,7 +21,7 @@ func TestPrint(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 13,
},
Stmts: []node.Node{
@ -30,28 +29,28 @@ func TestPrint(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 13,
},
Expr: &expr.Print{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 11,
},
Expr: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
StartPos: 9,
EndPos: 11,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
StartPos: 9,
EndPos: 11,
},
Value: "a",
@ -62,12 +61,12 @@ func TestPrint(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@ -1,7 +1,6 @@
package expr_test
import (
"bytes"
"testing"
"gotest.tools/assert"
@ -22,7 +21,7 @@ func TestPropertyFetch(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 11,
},
Stmts: []node.Node{
@ -30,28 +29,28 @@ func TestPropertyFetch(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 11,
},
Expr: &expr.PropertyFetch{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 10,
},
Variable: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 5,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 5,
},
Value: "a",
@ -61,7 +60,7 @@ func TestPropertyFetch(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 8,
StartPos: 7,
EndPos: 10,
},
Value: "foo",
@ -71,12 +70,12 @@ func TestPropertyFetch(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@ -1,7 +1,6 @@
package expr_test
import (
"bytes"
"testing"
"gotest.tools/assert"
@ -23,7 +22,7 @@ func TestForeachWithRef(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 31,
},
Stmts: []node.Node{
@ -31,21 +30,21 @@ func TestForeachWithRef(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 31,
},
Expr: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 13,
StartPos: 12,
EndPos: 14,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 13,
StartPos: 12,
EndPos: 14,
},
Value: "a",
@ -55,14 +54,14 @@ func TestForeachWithRef(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 19,
StartPos: 18,
EndPos: 20,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 19,
StartPos: 18,
EndPos: 20,
},
Value: "k",
@ -72,21 +71,21 @@ func TestForeachWithRef(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 25,
StartPos: 24,
EndPos: 27,
},
Variable: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 26,
StartPos: 25,
EndPos: 27,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 26,
StartPos: 25,
EndPos: 27,
},
Value: "v",
@ -97,7 +96,7 @@ func TestForeachWithRef(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 30,
StartPos: 29,
EndPos: 31,
},
Stmts: []node.Node{},
@ -106,12 +105,12 @@ func TestForeachWithRef(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@ -1,7 +1,6 @@
package expr_test
import (
"bytes"
"testing"
"gotest.tools/assert"
@ -24,7 +23,7 @@ func TestShellExec(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 12,
},
Stmts: []node.Node{
@ -32,14 +31,14 @@ func TestShellExec(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 12,
},
Expr: &expr.ShellExec{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 11,
},
Parts: []node.Node{
@ -47,7 +46,7 @@ func TestShellExec(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 5,
StartPos: 4,
EndPos: 8,
},
Value: "cmd ",
@ -56,14 +55,14 @@ func TestShellExec(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 9,
StartPos: 8,
EndPos: 10,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 9,
StartPos: 8,
EndPos: 10,
},
Value: "a",
@ -75,12 +74,12 @@ func TestShellExec(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@ -1,7 +1,6 @@
package expr_test
import (
"bytes"
"testing"
"gotest.tools/assert"
@ -22,7 +21,7 @@ func TestShortArray(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 6,
},
Stmts: []node.Node{
@ -30,14 +29,14 @@ func TestShortArray(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 6,
},
Expr: &expr.ShortArray{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 5,
},
Items: []node.Node{},
@ -46,12 +45,12 @@ func TestShortArray(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -64,7 +63,7 @@ func TestShortArrayItem(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 7,
},
Stmts: []node.Node{
@ -72,14 +71,14 @@ func TestShortArrayItem(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 7,
},
Expr: &expr.ShortArray{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 6,
},
Items: []node.Node{
@ -87,14 +86,14 @@ func TestShortArrayItem(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 5,
StartPos: 4,
EndPos: 5,
},
Val: &scalar.Lnumber{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 5,
StartPos: 4,
EndPos: 5,
},
Value: "1",
@ -106,12 +105,12 @@ func TestShortArrayItem(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -124,7 +123,7 @@ func TestShortArrayItems(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 16,
},
Stmts: []node.Node{
@ -132,14 +131,14 @@ func TestShortArrayItems(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 16,
},
Expr: &expr.ShortArray{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 15,
},
Items: []node.Node{
@ -147,14 +146,14 @@ func TestShortArrayItems(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 5,
StartPos: 4,
EndPos: 8,
},
Key: &scalar.Lnumber{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 5,
StartPos: 4,
EndPos: 5,
},
Value: "1",
@ -163,7 +162,7 @@ func TestShortArrayItems(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 8,
StartPos: 7,
EndPos: 8,
},
Value: "1",
@ -173,28 +172,28 @@ func TestShortArrayItems(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 11,
StartPos: 10,
EndPos: 13,
},
Val: &expr.Reference{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 11,
StartPos: 10,
EndPos: 13,
},
Variable: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 12,
StartPos: 11,
EndPos: 13,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 12,
StartPos: 11,
EndPos: 13,
},
Value: "b",
@ -209,12 +208,12 @@ func TestShortArrayItems(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@ -1,7 +1,6 @@
package expr_test
import (
"bytes"
"testing"
"gotest.tools/assert"
@ -21,7 +20,7 @@ func TestShortList(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 13,
},
Stmts: []node.Node{
@ -29,21 +28,21 @@ func TestShortList(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 13,
},
Expr: &assign.Assign{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 12,
},
Variable: &expr.ShortList{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 7,
},
Items: []node.Node{
@ -51,21 +50,21 @@ func TestShortList(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 5,
StartPos: 4,
EndPos: 6,
},
Val: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 5,
StartPos: 4,
EndPos: 6,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 5,
StartPos: 4,
EndPos: 6,
},
Value: "a",
@ -78,14 +77,14 @@ func TestShortList(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 11,
StartPos: 10,
EndPos: 12,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 11,
StartPos: 10,
EndPos: 12,
},
Value: "b",
@ -96,7 +95,7 @@ func TestShortList(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -109,7 +108,7 @@ func TestShortListArrayIndex(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 15,
},
Stmts: []node.Node{
@ -117,21 +116,21 @@ func TestShortListArrayIndex(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 15,
},
Expr: &assign.Assign{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 14,
},
Variable: &expr.ShortList{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 9,
},
Items: []node.Node{
@ -139,28 +138,28 @@ func TestShortListArrayIndex(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 5,
StartPos: 4,
EndPos: 8,
},
Val: &expr.ArrayDimFetch{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 5,
StartPos: 4,
EndPos: 8,
},
Variable: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 5,
StartPos: 4,
EndPos: 6,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 5,
StartPos: 4,
EndPos: 6,
},
Value: "a",
@ -174,14 +173,14 @@ func TestShortListArrayIndex(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 13,
StartPos: 12,
EndPos: 14,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 13,
StartPos: 12,
EndPos: 14,
},
Value: "b",
@ -192,7 +191,7 @@ func TestShortListArrayIndex(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -205,7 +204,7 @@ func TestShortListList(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 19,
},
Stmts: []node.Node{
@ -213,21 +212,21 @@ func TestShortListList(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 19,
},
Expr: &assign.Assign{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 18,
},
Variable: &expr.ShortList{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 13,
},
Items: []node.Node{
@ -235,14 +234,14 @@ func TestShortListList(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 5,
StartPos: 4,
EndPos: 12,
},
Val: &expr.List{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 5,
StartPos: 4,
EndPos: 12,
},
Items: []node.Node{
@ -250,21 +249,21 @@ func TestShortListList(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
StartPos: 9,
EndPos: 11,
},
Val: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
StartPos: 9,
EndPos: 11,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
StartPos: 9,
EndPos: 11,
},
Value: "a",
@ -280,14 +279,14 @@ func TestShortListList(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 17,
StartPos: 16,
EndPos: 18,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 17,
StartPos: 16,
EndPos: 18,
},
Value: "b",
@ -298,7 +297,7 @@ func TestShortListList(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@ -1,7 +1,6 @@
package expr_test
import (
"bytes"
"testing"
"gotest.tools/assert"
@ -24,7 +23,7 @@ func TestStaticCall(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 14,
},
Stmts: []node.Node{
@ -32,21 +31,21 @@ func TestStaticCall(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 14,
},
Expr: &expr.StaticCall{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 13,
},
Class: &name.Name{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 6,
},
Parts: []node.Node{
@ -54,7 +53,7 @@ func TestStaticCall(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 6,
},
Value: "Foo",
@ -65,7 +64,7 @@ func TestStaticCall(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 9,
StartPos: 8,
EndPos: 11,
},
Value: "bar",
@ -74,7 +73,7 @@ func TestStaticCall(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 12,
StartPos: 11,
EndPos: 13,
},
},
@ -83,12 +82,12 @@ func TestStaticCall(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -101,7 +100,7 @@ func TestStaticCallRelative(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 24,
},
Stmts: []node.Node{
@ -109,21 +108,21 @@ func TestStaticCallRelative(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 24,
},
Expr: &expr.StaticCall{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 23,
},
Class: &name.Relative{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 16,
},
Parts: []node.Node{
@ -131,7 +130,7 @@ func TestStaticCallRelative(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 14,
StartPos: 13,
EndPos: 16,
},
Value: "Foo",
@ -142,7 +141,7 @@ func TestStaticCallRelative(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 19,
StartPos: 18,
EndPos: 21,
},
Value: "bar",
@ -151,7 +150,7 @@ func TestStaticCallRelative(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 22,
StartPos: 21,
EndPos: 23,
},
},
@ -160,12 +159,12 @@ func TestStaticCallRelative(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -178,7 +177,7 @@ func TestStaticCallFullyQualified(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 15,
},
Stmts: []node.Node{
@ -186,21 +185,21 @@ func TestStaticCallFullyQualified(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 15,
},
Expr: &expr.StaticCall{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 14,
},
Class: &name.FullyQualified{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 7,
},
Parts: []node.Node{
@ -208,7 +207,7 @@ func TestStaticCallFullyQualified(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 5,
StartPos: 4,
EndPos: 7,
},
Value: "Foo",
@ -219,7 +218,7 @@ func TestStaticCallFullyQualified(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
StartPos: 9,
EndPos: 12,
},
Value: "bar",
@ -228,7 +227,7 @@ func TestStaticCallFullyQualified(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 13,
StartPos: 12,
EndPos: 14,
},
},
@ -237,12 +236,12 @@ func TestStaticCallFullyQualified(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -255,7 +254,7 @@ func TestStaticCallVar(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 15,
},
Stmts: []node.Node{
@ -263,21 +262,21 @@ func TestStaticCallVar(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 15,
},
Expr: &expr.StaticCall{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 14,
},
Class: &name.Name{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 6,
},
Parts: []node.Node{
@ -285,7 +284,7 @@ func TestStaticCallVar(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 6,
},
Value: "Foo",
@ -296,14 +295,14 @@ func TestStaticCallVar(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 9,
StartPos: 8,
EndPos: 12,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 9,
StartPos: 8,
EndPos: 12,
},
Value: "bar",
@ -313,7 +312,7 @@ func TestStaticCallVar(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 13,
StartPos: 12,
EndPos: 14,
},
},
@ -322,12 +321,12 @@ func TestStaticCallVar(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -340,7 +339,7 @@ func TestStaticCallVarVar(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 16,
},
Stmts: []node.Node{
@ -348,28 +347,28 @@ func TestStaticCallVarVar(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 16,
},
Expr: &expr.StaticCall{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 15,
},
Class: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 7,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 7,
},
Value: "foo",
@ -379,14 +378,14 @@ func TestStaticCallVarVar(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
StartPos: 9,
EndPos: 13,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
StartPos: 9,
EndPos: 13,
},
Value: "bar",
@ -396,7 +395,7 @@ func TestStaticCallVarVar(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 14,
StartPos: 13,
EndPos: 15,
},
},
@ -405,12 +404,12 @@ func TestStaticCallVarVar(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@ -1,7 +1,6 @@
package expr_test
import (
"bytes"
"testing"
"gotest.tools/assert"
@ -23,7 +22,7 @@ func TestStaticPropertyFetch(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 13,
},
Stmts: []node.Node{
@ -31,21 +30,21 @@ func TestStaticPropertyFetch(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 13,
},
Expr: &expr.StaticPropertyFetch{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 12,
},
Class: &name.Name{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 6,
},
Parts: []node.Node{
@ -53,7 +52,7 @@ func TestStaticPropertyFetch(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 6,
},
Value: "Foo",
@ -64,14 +63,14 @@ func TestStaticPropertyFetch(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 9,
StartPos: 8,
EndPos: 12,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 9,
StartPos: 8,
EndPos: 12,
},
Value: "bar",
@ -82,12 +81,12 @@ func TestStaticPropertyFetch(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -100,7 +99,7 @@ func TestStaticPropertyFetchRelative(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 23,
},
Stmts: []node.Node{
@ -108,21 +107,21 @@ func TestStaticPropertyFetchRelative(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 23,
},
Expr: &expr.StaticPropertyFetch{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 22,
},
Class: &name.Relative{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 16,
},
Parts: []node.Node{
@ -130,7 +129,7 @@ func TestStaticPropertyFetchRelative(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 14,
StartPos: 13,
EndPos: 16,
},
Value: "Foo",
@ -141,14 +140,14 @@ func TestStaticPropertyFetchRelative(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 19,
StartPos: 18,
EndPos: 22,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 19,
StartPos: 18,
EndPos: 22,
},
Value: "bar",
@ -159,12 +158,12 @@ func TestStaticPropertyFetchRelative(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -177,7 +176,7 @@ func TestStaticPropertyFetchFullyQualified(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 14,
},
Stmts: []node.Node{
@ -185,21 +184,21 @@ func TestStaticPropertyFetchFullyQualified(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 14,
},
Expr: &expr.StaticPropertyFetch{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 13,
},
Class: &name.FullyQualified{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 7,
},
Parts: []node.Node{
@ -207,7 +206,7 @@ func TestStaticPropertyFetchFullyQualified(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 5,
StartPos: 4,
EndPos: 7,
},
Value: "Foo",
@ -218,14 +217,14 @@ func TestStaticPropertyFetchFullyQualified(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
StartPos: 9,
EndPos: 13,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
StartPos: 9,
EndPos: 13,
},
Value: "bar",
@ -236,12 +235,12 @@ func TestStaticPropertyFetchFullyQualified(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@ -1,7 +1,6 @@
package expr_test
import (
"bytes"
"testing"
"gotest.tools/assert"
@ -22,7 +21,7 @@ func TestTernary(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 16,
},
Stmts: []node.Node{
@ -30,28 +29,28 @@ func TestTernary(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 16,
},
Expr: &expr.Ternary{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 15,
},
Condition: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 5,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 5,
},
Value: "a",
@ -61,14 +60,14 @@ func TestTernary(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 9,
StartPos: 8,
EndPos: 10,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 9,
StartPos: 8,
EndPos: 10,
},
Value: "b",
@ -78,14 +77,14 @@ func TestTernary(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 14,
StartPos: 13,
EndPos: 15,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 14,
StartPos: 13,
EndPos: 15,
},
Value: "c",
@ -96,12 +95,12 @@ func TestTernary(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -114,7 +113,7 @@ func TestTernarySimple(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 13,
},
Stmts: []node.Node{
@ -122,28 +121,28 @@ func TestTernarySimple(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 13,
},
Expr: &expr.Ternary{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 12,
},
Condition: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 5,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 5,
},
Value: "a",
@ -153,14 +152,14 @@ func TestTernarySimple(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 11,
StartPos: 10,
EndPos: 12,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 11,
StartPos: 10,
EndPos: 12,
},
Value: "c",
@ -171,12 +170,12 @@ func TestTernarySimple(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -189,7 +188,7 @@ func TestTernaryNestedTrue(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 26,
},
Stmts: []node.Node{
@ -197,28 +196,28 @@ func TestTernaryNestedTrue(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 26,
},
Expr: &expr.Ternary{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 25,
},
Condition: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 5,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 5,
},
Value: "a",
@ -228,21 +227,21 @@ func TestTernaryNestedTrue(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 9,
StartPos: 8,
EndPos: 20,
},
Condition: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 9,
StartPos: 8,
EndPos: 10,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 9,
StartPos: 8,
EndPos: 10,
},
Value: "b",
@ -252,14 +251,14 @@ func TestTernaryNestedTrue(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 14,
StartPos: 13,
EndPos: 15,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 14,
StartPos: 13,
EndPos: 15,
},
Value: "c",
@ -269,14 +268,14 @@ func TestTernaryNestedTrue(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 19,
StartPos: 18,
EndPos: 20,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 19,
StartPos: 18,
EndPos: 20,
},
Value: "d",
@ -287,14 +286,14 @@ func TestTernaryNestedTrue(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 24,
StartPos: 23,
EndPos: 25,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 24,
StartPos: 23,
EndPos: 25,
},
Value: "e",
@ -305,12 +304,12 @@ func TestTernaryNestedTrue(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -323,7 +322,7 @@ func TestTernaryNestedCond(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 26,
},
Stmts: []node.Node{
@ -331,35 +330,35 @@ func TestTernaryNestedCond(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 26,
},
Expr: &expr.Ternary{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 25,
},
Condition: &expr.Ternary{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 15,
},
Condition: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 5,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 5,
},
Value: "a",
@ -369,14 +368,14 @@ func TestTernaryNestedCond(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 9,
StartPos: 8,
EndPos: 10,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 9,
StartPos: 8,
EndPos: 10,
},
Value: "b",
@ -386,14 +385,14 @@ func TestTernaryNestedCond(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 14,
StartPos: 13,
EndPos: 15,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 14,
StartPos: 13,
EndPos: 15,
},
Value: "c",
@ -404,14 +403,14 @@ func TestTernaryNestedCond(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 19,
StartPos: 18,
EndPos: 20,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 19,
StartPos: 18,
EndPos: 20,
},
Value: "d",
@ -421,14 +420,14 @@ func TestTernaryNestedCond(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 24,
StartPos: 23,
EndPos: 25,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 24,
StartPos: 23,
EndPos: 25,
},
Value: "e",
@ -439,12 +438,12 @@ func TestTernaryNestedCond(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@ -1,7 +1,6 @@
package expr_test
import (
"bytes"
"testing"
"gotest.tools/assert"
@ -22,7 +21,7 @@ func TestUnaryMinus(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 7,
},
Stmts: []node.Node{
@ -30,28 +29,28 @@ func TestUnaryMinus(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 7,
},
Expr: &expr.UnaryMinus{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 6,
},
Expr: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 5,
StartPos: 4,
EndPos: 6,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 5,
StartPos: 4,
EndPos: 6,
},
Value: "a",
@ -62,12 +61,12 @@ func TestUnaryMinus(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -80,7 +79,7 @@ func TestUnaryPlus(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 7,
},
Stmts: []node.Node{
@ -88,28 +87,28 @@ func TestUnaryPlus(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 7,
},
Expr: &expr.UnaryPlus{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 6,
},
Expr: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 5,
StartPos: 4,
EndPos: 6,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 5,
StartPos: 4,
EndPos: 6,
},
Value: "a",
@ -120,12 +119,12 @@ func TestUnaryPlus(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@ -1,7 +1,6 @@
package expr_test
import (
"bytes"
"testing"
"gotest.tools/assert"
@ -22,7 +21,7 @@ func TestVariable(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 6,
},
Stmts: []node.Node{
@ -30,21 +29,21 @@ func TestVariable(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 6,
},
Expr: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 5,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 5,
},
Value: "a",
@ -54,12 +53,12 @@ func TestVariable(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -72,7 +71,7 @@ func TestVariableVariable(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 7,
},
Stmts: []node.Node{
@ -80,28 +79,28 @@ func TestVariableVariable(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 7,
},
Expr: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 6,
},
VarName: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 5,
StartPos: 4,
EndPos: 6,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 5,
StartPos: 4,
EndPos: 6,
},
Value: "a",
@ -112,12 +111,12 @@ func TestVariableVariable(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@ -31,11 +31,12 @@ var nodesToTest = []struct {
},
{
&expr.ArrayItem{
Key: &scalar.String{Value: "key"},
Val: &scalar.Lnumber{Value: "1"},
Key: &scalar.String{Value: "key"},
Val: &scalar.Lnumber{Value: "1"},
Unpack: true,
},
[]string{"Key", "Val"},
nil,
map[string]interface{}{"Unpack": true},
},
{
&expr.Array{
@ -97,6 +98,18 @@ var nodesToTest = []struct {
[]string{"Params", "ClosureUse", "ReturnType", "Stmts"},
map[string]interface{}{"ReturnsRef": true, "Static": false, "PhpDocComment": ""},
},
{
&expr.ArrowFunction{
ReturnsRef: true,
Static: false,
PhpDocComment: "",
Params: []node.Node{&node.Parameter{}},
ReturnType: &name.Name{},
Expr: &expr.Variable{},
},
[]string{"Params", "ReturnType", "Expr"},
map[string]interface{}{"ReturnsRef": true, "Static": false, "PhpDocComment": ""},
},
{
&expr.ConstFetch{
Constant: &node.Identifier{Value: "foo"},

View File

@ -1,7 +1,6 @@
package expr_test
import (
"bytes"
"testing"
"gotest.tools/assert"
@ -23,7 +22,7 @@ func TestYield(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 9,
},
Stmts: []node.Node{
@ -31,14 +30,14 @@ func TestYield(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 9,
},
Expr: &expr.Yield{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 8,
},
},
@ -46,12 +45,12 @@ func TestYield(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -64,7 +63,7 @@ func TestYieldVal(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 12,
},
Stmts: []node.Node{
@ -72,28 +71,28 @@ func TestYieldVal(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 12,
},
Expr: &expr.Yield{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 11,
},
Value: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
StartPos: 9,
EndPos: 11,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
StartPos: 9,
EndPos: 11,
},
Value: "a",
@ -104,12 +103,12 @@ func TestYieldVal(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -122,7 +121,7 @@ func TestYieldKeyVal(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 18,
},
Stmts: []node.Node{
@ -130,28 +129,28 @@ func TestYieldKeyVal(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 18,
},
Expr: &expr.Yield{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 17,
},
Key: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
StartPos: 9,
EndPos: 11,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
StartPos: 9,
EndPos: 11,
},
Value: "a",
@ -161,14 +160,14 @@ func TestYieldKeyVal(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 16,
StartPos: 15,
EndPos: 17,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 16,
StartPos: 15,
EndPos: 17,
},
Value: "b",
@ -179,12 +178,12 @@ func TestYieldKeyVal(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -197,7 +196,7 @@ func TestYieldExpr(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 11,
},
Stmts: []node.Node{
@ -205,21 +204,21 @@ func TestYieldExpr(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 11,
},
Expr: &expr.Yield{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 10,
},
Value: &scalar.Lnumber{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
StartPos: 9,
EndPos: 10,
},
Value: "1",
@ -229,12 +228,12 @@ func TestYieldExpr(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -247,7 +246,7 @@ func TestYieldKeyExpr(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 17,
},
Stmts: []node.Node{
@ -255,28 +254,28 @@ func TestYieldKeyExpr(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 17,
},
Expr: &expr.Yield{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 16,
},
Key: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
StartPos: 9,
EndPos: 11,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
StartPos: 9,
EndPos: 11,
},
Value: "a",
@ -286,7 +285,7 @@ func TestYieldKeyExpr(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 16,
StartPos: 15,
EndPos: 16,
},
Value: "1",
@ -296,12 +295,12 @@ func TestYieldKeyExpr(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -314,7 +313,7 @@ func TestYieldFrom(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 17,
},
Stmts: []node.Node{
@ -322,28 +321,28 @@ func TestYieldFrom(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 17,
},
Expr: &expr.YieldFrom{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 16,
},
Expr: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 15,
StartPos: 14,
EndPos: 16,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 15,
StartPos: 14,
EndPos: 16,
},
Value: "a",
@ -354,7 +353,7 @@ func TestYieldFrom(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@ -1,7 +1,6 @@
package name_test
import (
"bytes"
"testing"
"gotest.tools/assert"
@ -23,7 +22,7 @@ func TestName(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 9,
},
Stmts: []node.Node{
@ -31,21 +30,21 @@ func TestName(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 9,
},
Expr: &expr.FunctionCall{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 8,
},
Function: &name.Name{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 6,
},
Parts: []node.Node{
@ -53,7 +52,7 @@ func TestName(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 6,
},
Value: "foo",
@ -64,7 +63,7 @@ func TestName(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 7,
StartPos: 6,
EndPos: 8,
},
},
@ -73,12 +72,12 @@ func TestName(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -91,7 +90,7 @@ func TestFullyQualified(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 10,
},
Stmts: []node.Node{
@ -99,21 +98,21 @@ func TestFullyQualified(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 10,
},
Expr: &expr.FunctionCall{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 9,
},
Function: &name.FullyQualified{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 7,
},
Parts: []node.Node{
@ -121,7 +120,7 @@ func TestFullyQualified(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 5,
StartPos: 4,
EndPos: 7,
},
Value: "foo",
@ -132,7 +131,7 @@ func TestFullyQualified(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 8,
StartPos: 7,
EndPos: 9,
},
},
@ -141,12 +140,12 @@ func TestFullyQualified(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -159,7 +158,7 @@ func TestRelative(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 19,
},
Stmts: []node.Node{
@ -167,21 +166,21 @@ func TestRelative(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 19,
},
Expr: &expr.FunctionCall{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 18,
},
Function: &name.Relative{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 16,
},
Parts: []node.Node{
@ -189,7 +188,7 @@ func TestRelative(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 14,
StartPos: 13,
EndPos: 16,
},
Value: "foo",
@ -200,7 +199,7 @@ func TestRelative(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 17,
StartPos: 16,
EndPos: 18,
},
},
@ -209,12 +208,12 @@ func TestRelative(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@ -1,7 +1,6 @@
package scalar_test
import (
"bytes"
"testing"
"gotest.tools/assert"
@ -23,7 +22,7 @@ func TestSimpleVar(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 15,
},
Stmts: []node.Node{
@ -31,14 +30,14 @@ func TestSimpleVar(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 15,
},
Expr: &scalar.Encapsed{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 14,
},
Parts: []node.Node{
@ -46,7 +45,7 @@ func TestSimpleVar(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 5,
StartPos: 4,
EndPos: 9,
},
Value: "test ",
@ -55,14 +54,14 @@ func TestSimpleVar(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
StartPos: 9,
EndPos: 13,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
StartPos: 9,
EndPos: 13,
},
Value: "var",
@ -74,12 +73,12 @@ func TestSimpleVar(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -92,7 +91,7 @@ func TestSimpleVarOneChar(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 13,
},
Stmts: []node.Node{
@ -100,14 +99,14 @@ func TestSimpleVarOneChar(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 13,
},
Expr: &scalar.Encapsed{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 12,
},
Parts: []node.Node{
@ -115,7 +114,7 @@ func TestSimpleVarOneChar(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 5,
StartPos: 4,
EndPos: 9,
},
Value: "test ",
@ -124,14 +123,14 @@ func TestSimpleVarOneChar(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
StartPos: 9,
EndPos: 11,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
StartPos: 9,
EndPos: 11,
},
Value: "a",
@ -143,12 +142,12 @@ func TestSimpleVarOneChar(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -161,7 +160,7 @@ func TestSimpleVarEndsEcapsed(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 17,
},
Stmts: []node.Node{
@ -169,14 +168,14 @@ func TestSimpleVarEndsEcapsed(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 17,
},
Expr: &scalar.Encapsed{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 16,
},
Parts: []node.Node{
@ -184,7 +183,7 @@ func TestSimpleVarEndsEcapsed(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 5,
StartPos: 4,
EndPos: 9,
},
Value: "test ",
@ -193,14 +192,14 @@ func TestSimpleVarEndsEcapsed(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
StartPos: 9,
EndPos: 13,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
StartPos: 9,
EndPos: 13,
},
Value: "var",
@ -210,7 +209,7 @@ func TestSimpleVarEndsEcapsed(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 14,
StartPos: 13,
EndPos: 15,
},
Value: "\\\"",
@ -221,12 +220,12 @@ func TestSimpleVarEndsEcapsed(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -239,7 +238,7 @@ func TestStringVarCurveOpen(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 13,
},
Stmts: []node.Node{
@ -247,14 +246,14 @@ func TestStringVarCurveOpen(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 13,
},
Expr: &scalar.Encapsed{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 12,
},
Parts: []node.Node{
@ -262,7 +261,7 @@ func TestStringVarCurveOpen(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 5,
StartPos: 4,
EndPos: 5,
},
Value: "=",
@ -271,14 +270,14 @@ func TestStringVarCurveOpen(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 6,
StartPos: 5,
EndPos: 7,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 6,
StartPos: 5,
EndPos: 7,
},
Value: "a",
@ -288,14 +287,14 @@ func TestStringVarCurveOpen(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 9,
StartPos: 8,
EndPos: 10,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 9,
StartPos: 8,
EndPos: 10,
},
Value: "b",
@ -307,12 +306,12 @@ func TestStringVarCurveOpen(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -325,7 +324,7 @@ func TestSimpleVarPropertyFetch(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 22,
},
Stmts: []node.Node{
@ -333,14 +332,14 @@ func TestSimpleVarPropertyFetch(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 22,
},
Expr: &scalar.Encapsed{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 21,
},
Parts: []node.Node{
@ -348,7 +347,7 @@ func TestSimpleVarPropertyFetch(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 5,
StartPos: 4,
EndPos: 9,
},
Value: "test ",
@ -357,21 +356,21 @@ func TestSimpleVarPropertyFetch(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
StartPos: 9,
EndPos: 18,
},
Variable: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
StartPos: 9,
EndPos: 13,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
StartPos: 9,
EndPos: 13,
},
Value: "foo",
@ -381,7 +380,7 @@ func TestSimpleVarPropertyFetch(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 16,
StartPos: 15,
EndPos: 18,
},
Value: "bar",
@ -391,7 +390,7 @@ func TestSimpleVarPropertyFetch(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 19,
StartPos: 18,
EndPos: 20,
},
Value: "()",
@ -402,12 +401,12 @@ func TestSimpleVarPropertyFetch(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -420,7 +419,7 @@ func TestDollarOpenCurlyBraces(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 17,
},
Stmts: []node.Node{
@ -428,14 +427,14 @@ func TestDollarOpenCurlyBraces(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 17,
},
Expr: &scalar.Encapsed{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 16,
},
Parts: []node.Node{
@ -443,7 +442,7 @@ func TestDollarOpenCurlyBraces(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 5,
StartPos: 4,
EndPos: 9,
},
Value: "test ",
@ -452,14 +451,14 @@ func TestDollarOpenCurlyBraces(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
StartPos: 9,
EndPos: 15,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 12,
StartPos: 11,
EndPos: 14,
},
Value: "foo",
@ -471,12 +470,12 @@ func TestDollarOpenCurlyBraces(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -489,7 +488,7 @@ func TestDollarOpenCurlyBracesDimNumber(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 20,
},
Stmts: []node.Node{
@ -497,14 +496,14 @@ func TestDollarOpenCurlyBracesDimNumber(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 20,
},
Expr: &scalar.Encapsed{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 19,
},
Parts: []node.Node{
@ -512,7 +511,7 @@ func TestDollarOpenCurlyBracesDimNumber(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 5,
StartPos: 4,
EndPos: 9,
},
Value: "test ",
@ -521,95 +520,9 @@ func TestDollarOpenCurlyBracesDimNumber(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
StartPos: 9,
EndPos: 18,
},
Variable: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 12,
EndPos: 14,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 12,
EndPos: 14,
},
Value: "foo",
},
},
Dim: &scalar.Lnumber{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 16,
EndPos: 16,
},
Value: "0",
},
},
},
},
},
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
}
func TestCurlyOpenMethodCall(t *testing.T) {
src := `<? "test {$foo->bar()}";`
expected := &node.Root{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 24,
},
Stmts: []node.Node{
&stmt.Expression{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 24,
},
Expr: &scalar.Encapsed{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 23,
},
Parts: []node.Node{
&scalar.EncapsedStringPart{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 5,
EndPos: 9,
},
Value: "test ",
},
&expr.MethodCall{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 11,
EndPos: 21,
},
Variable: &expr.Variable{
Position: &position.Position{
StartLine: 1,
@ -627,11 +540,97 @@ func TestCurlyOpenMethodCall(t *testing.T) {
Value: "foo",
},
},
Dim: &scalar.Lnumber{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 15,
EndPos: 16,
},
Value: "0",
},
},
},
},
},
},
}
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
}
func TestCurlyOpenMethodCall(t *testing.T) {
src := `<? "test {$foo->bar()}";`
expected := &node.Root{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 3,
EndPos: 24,
},
Stmts: []node.Node{
&stmt.Expression{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 3,
EndPos: 24,
},
Expr: &scalar.Encapsed{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 3,
EndPos: 23,
},
Parts: []node.Node{
&scalar.EncapsedStringPart{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 9,
},
Value: "test ",
},
&expr.MethodCall{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
EndPos: 21,
},
Variable: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
EndPos: 14,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
EndPos: 14,
},
Value: "foo",
},
},
Method: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 17,
StartPos: 16,
EndPos: 19,
},
Value: "bar",
@ -640,7 +639,7 @@ func TestCurlyOpenMethodCall(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 20,
StartPos: 19,
EndPos: 21,
},
},
@ -651,12 +650,12 @@ func TestCurlyOpenMethodCall(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@ -1,7 +1,6 @@
package scalar_test
import (
"bytes"
"testing"
"gotest.tools/assert"
@ -26,7 +25,7 @@ LBL;
Position: &position.Position{
StartLine: 1,
EndLine: 3,
StartPos: 7,
StartPos: 3,
EndPos: 24,
},
Stmts: []node.Node{
@ -34,23 +33,23 @@ LBL;
Position: &position.Position{
StartLine: 1,
EndLine: 3,
StartPos: 7,
StartPos: 3,
EndPos: 24,
},
Expr: &scalar.Heredoc{
Position: &position.Position{
StartLine: 1,
EndLine: 3,
StartPos: 7,
StartPos: 3,
EndPos: 23,
},
Label: "LBL",
Label: "<<<LBL\n",
Parts: []node.Node{
&scalar.EncapsedStringPart{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 11,
StartPos: 10,
EndPos: 15,
},
Value: "test ",
@ -59,31 +58,40 @@ LBL;
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 16,
StartPos: 15,
EndPos: 19,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 16,
StartPos: 15,
EndPos: 19,
},
Value: "var",
},
},
&scalar.EncapsedStringPart{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 19,
EndPos: 20,
},
Value: "\n",
},
},
},
},
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -99,7 +107,7 @@ LBL;
Position: &position.Position{
StartLine: 1,
EndLine: 3,
StartPos: 7,
StartPos: 3,
EndPos: 26,
},
Stmts: []node.Node{
@ -107,23 +115,23 @@ LBL;
Position: &position.Position{
StartLine: 1,
EndLine: 3,
StartPos: 7,
StartPos: 3,
EndPos: 26,
},
Expr: &scalar.Heredoc{
Position: &position.Position{
StartLine: 1,
EndLine: 3,
StartPos: 7,
StartPos: 3,
EndPos: 25,
},
Label: "\"LBL\"",
Label: "<<<\"LBL\"\n",
Parts: []node.Node{
&scalar.EncapsedStringPart{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 13,
StartPos: 12,
EndPos: 17,
},
Value: "test ",
@ -132,31 +140,40 @@ LBL;
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 18,
StartPos: 17,
EndPos: 21,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 18,
StartPos: 17,
EndPos: 21,
},
Value: "var",
},
},
&scalar.EncapsedStringPart{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 21,
EndPos: 22,
},
Value: "\n",
},
},
},
},
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -172,7 +189,7 @@ LBL;
Position: &position.Position{
StartLine: 1,
EndLine: 3,
StartPos: 7,
StartPos: 3,
EndPos: 26,
},
Stmts: []node.Node{
@ -180,26 +197,26 @@ LBL;
Position: &position.Position{
StartLine: 1,
EndLine: 3,
StartPos: 7,
StartPos: 3,
EndPos: 26,
},
Expr: &scalar.Heredoc{
Position: &position.Position{
StartLine: 1,
EndLine: 3,
StartPos: 7,
StartPos: 3,
EndPos: 25,
},
Label: "'LBL'",
Label: "<<<'LBL'\n",
Parts: []node.Node{
&scalar.EncapsedStringPart{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 13,
EndPos: 21,
StartPos: 12,
EndPos: 22,
},
Value: "test $var",
Value: "test $var\n",
},
},
},
@ -207,12 +224,12 @@ LBL;
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -227,7 +244,7 @@ CAD;
Position: &position.Position{
StartLine: 1,
EndLine: 2,
StartPos: 7,
StartPos: 3,
EndPos: 14,
},
Stmts: []node.Node{
@ -235,28 +252,28 @@ CAD;
Position: &position.Position{
StartLine: 1,
EndLine: 2,
StartPos: 7,
StartPos: 3,
EndPos: 14,
},
Expr: &scalar.Heredoc{
Position: &position.Position{
StartLine: 1,
EndLine: 2,
StartPos: 7,
StartPos: 3,
EndPos: 13,
},
Label: "CAD",
Label: "<<<CAD\n",
},
},
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -272,7 +289,7 @@ CAD;
Position: &position.Position{
StartLine: 1,
EndLine: 3,
StartPos: 7,
StartPos: 3,
EndPos: 21,
},
Stmts: []node.Node{
@ -280,26 +297,26 @@ CAD;
Position: &position.Position{
StartLine: 1,
EndLine: 3,
StartPos: 7,
StartPos: 3,
EndPos: 21,
},
Expr: &scalar.Heredoc{
Position: &position.Position{
StartLine: 1,
EndLine: 3,
StartPos: 7,
StartPos: 3,
EndPos: 20,
},
Label: "CAD",
Label: "<<<CAD\n",
Parts: []node.Node{
&scalar.EncapsedStringPart{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 11,
EndPos: 16,
StartPos: 10,
EndPos: 17,
},
Value: "\thello",
Value: "\thello\n",
},
},
},
@ -307,12 +324,12 @@ CAD;
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@ -1,7 +1,6 @@
package scalar_test
import (
"bytes"
"testing"
"gotest.tools/assert"
@ -22,7 +21,7 @@ func TestMagicConstant(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 11,
},
Stmts: []node.Node{
@ -30,14 +29,14 @@ func TestMagicConstant(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 11,
},
Expr: &scalar.MagicConstant{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 10,
},
Value: "__DIR__",
@ -46,12 +45,12 @@ func TestMagicConstant(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@ -1,7 +1,6 @@
package scalar_test
import (
"bytes"
"testing"
"gotest.tools/assert"
@ -21,7 +20,7 @@ func TestLNumber(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 23,
},
Stmts: []node.Node{
@ -29,14 +28,14 @@ func TestLNumber(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 23,
},
Expr: &scalar.Lnumber{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 22,
},
Value: "1234567890123456789",
@ -45,12 +44,12 @@ func TestLNumber(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -63,7 +62,7 @@ func TestDNumber(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 24,
},
Stmts: []node.Node{
@ -71,14 +70,14 @@ func TestDNumber(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 24,
},
Expr: &scalar.Dnumber{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 23,
},
Value: "12345678901234567890",
@ -87,12 +86,12 @@ func TestDNumber(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -105,7 +104,7 @@ func TestFloat(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 6,
},
Stmts: []node.Node{
@ -113,14 +112,14 @@ func TestFloat(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 6,
},
Expr: &scalar.Dnumber{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 5,
},
Value: "0.",
@ -129,12 +128,12 @@ func TestFloat(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -147,7 +146,7 @@ func TestBinaryLNumber(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 70,
},
Stmts: []node.Node{
@ -155,14 +154,14 @@ func TestBinaryLNumber(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 70,
},
Expr: &scalar.Lnumber{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 69,
},
Value: "0b0111111111111111111111111111111111111111111111111111111111111111",
@ -171,12 +170,12 @@ func TestBinaryLNumber(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -189,7 +188,7 @@ func TestBinaryDNumber(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 70,
},
Stmts: []node.Node{
@ -197,14 +196,14 @@ func TestBinaryDNumber(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 70,
},
Expr: &scalar.Dnumber{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 69,
},
Value: "0b1111111111111111111111111111111111111111111111111111111111111111",
@ -213,12 +212,12 @@ func TestBinaryDNumber(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -231,7 +230,7 @@ func TestHLNumber(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 24,
},
Stmts: []node.Node{
@ -239,14 +238,14 @@ func TestHLNumber(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 24,
},
Expr: &scalar.Lnumber{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 23,
},
Value: "0x007111111111111111",
@ -255,12 +254,12 @@ func TestHLNumber(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -273,7 +272,7 @@ func TestHDNumber(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 22,
},
Stmts: []node.Node{
@ -281,14 +280,14 @@ func TestHDNumber(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 22,
},
Expr: &scalar.Dnumber{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 21,
},
Value: "0x8111111111111111",
@ -297,12 +296,12 @@ func TestHDNumber(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@ -1,7 +1,6 @@
package scalar_test
import (
"bytes"
"testing"
"gotest.tools/assert"
@ -21,7 +20,7 @@ func TestDoubleQuotedScalarString(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 10,
},
Stmts: []node.Node{
@ -29,14 +28,14 @@ func TestDoubleQuotedScalarString(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 10,
},
Expr: &scalar.String{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 9,
},
Value: "\"test\"",
@ -45,12 +44,12 @@ func TestDoubleQuotedScalarString(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -63,7 +62,7 @@ func TestDoubleQuotedScalarStringWithEscapedVar(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 12,
},
Stmts: []node.Node{
@ -71,14 +70,14 @@ func TestDoubleQuotedScalarStringWithEscapedVar(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 12,
},
Expr: &scalar.String{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 11,
},
Value: "\"\\$test\"",
@ -87,12 +86,12 @@ func TestDoubleQuotedScalarStringWithEscapedVar(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -107,7 +106,7 @@ func TestMultilineDoubleQuotedScalarString(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 3,
StartPos: 4,
StartPos: 3,
EndPos: 14,
},
Stmts: []node.Node{
@ -115,14 +114,14 @@ func TestMultilineDoubleQuotedScalarString(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 3,
StartPos: 4,
StartPos: 3,
EndPos: 14,
},
Expr: &scalar.String{
Position: &position.Position{
StartLine: 1,
EndLine: 3,
StartPos: 4,
StartPos: 3,
EndPos: 13,
},
Value: "\"\n\ttest\n\t\"",
@ -131,12 +130,12 @@ func TestMultilineDoubleQuotedScalarString(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -149,7 +148,7 @@ func TestSingleQuotedScalarString(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 11,
},
Stmts: []node.Node{
@ -157,14 +156,14 @@ func TestSingleQuotedScalarString(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 11,
},
Expr: &scalar.String{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 10,
},
Value: "'$test'",
@ -173,12 +172,12 @@ func TestSingleQuotedScalarString(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -193,7 +192,7 @@ func TestMultilineSingleQuotedScalarString(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 3,
StartPos: 4,
StartPos: 3,
EndPos: 15,
},
Stmts: []node.Node{
@ -201,14 +200,14 @@ func TestMultilineSingleQuotedScalarString(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 3,
StartPos: 4,
StartPos: 3,
EndPos: 15,
},
Expr: &scalar.String{
Position: &position.Position{
StartLine: 1,
EndLine: 3,
StartPos: 4,
StartPos: 3,
EndPos: 14,
},
Value: "'\n\t$test\n\t'",
@ -217,12 +216,12 @@ func TestMultilineSingleQuotedScalarString(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@ -42,7 +42,9 @@ func (n *Declare) GetFreeFloating() *freefloating.Collection {
// Attributes returns node attributes as map
func (n *Declare) Attributes() map[string]interface{} {
return nil
return map[string]interface{}{
"Alt": n.Alt,
}
}
// Walk traverses nodes

View File

@ -12,14 +12,16 @@ type PropertyList struct {
FreeFloating freefloating.Collection
Position *position.Position
Modifiers []node.Node
Type node.Node
Properties []node.Node
}
// NewPropertyList node constructor
func NewPropertyList(Modifiers []node.Node, Properties []node.Node) *PropertyList {
func NewPropertyList(Modifiers []node.Node, Type node.Node, Properties []node.Node) *PropertyList {
return &PropertyList{
FreeFloating: nil,
Modifiers: Modifiers,
Type: Type,
Properties: Properties,
}
}
@ -60,6 +62,12 @@ func (n *PropertyList) Walk(v walker.Visitor) {
v.LeaveChildList("Modifiers", n)
}
if n.Type != nil {
v.EnterChildNode("Type", n)
n.Type.Walk(v)
v.LeaveChildNode("Type", n)
}
if n.Properties != nil {
v.EnterChildList("Properties", n)
for _, nn := range n.Properties {

View File

@ -1,7 +1,6 @@
package stmt_test
import (
"bytes"
"testing"
"gotest.tools/assert"
@ -24,7 +23,7 @@ func TestAltIf(t *testing.T) {
Position: &position.Position{
StartLine: 2,
EndLine: 3,
StartPos: 6,
StartPos: 5,
EndPos: 23,
},
Stmts: []node.Node{
@ -32,21 +31,21 @@ func TestAltIf(t *testing.T) {
Position: &position.Position{
StartLine: 2,
EndLine: 3,
StartPos: 6,
StartPos: 5,
EndPos: 23,
},
Cond: &expr.Variable{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 10,
StartPos: 9,
EndPos: 11,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 10,
StartPos: 9,
EndPos: 11,
},
Value: "a",
@ -65,12 +64,12 @@ func TestAltIf(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -87,7 +86,7 @@ func TestAltElseIf(t *testing.T) {
Position: &position.Position{
StartLine: 2,
EndLine: 4,
StartPos: 6,
StartPos: 5,
EndPos: 38,
},
Stmts: []node.Node{
@ -95,21 +94,21 @@ func TestAltElseIf(t *testing.T) {
Position: &position.Position{
StartLine: 2,
EndLine: 4,
StartPos: 6,
StartPos: 5,
EndPos: 38,
},
Cond: &expr.Variable{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 10,
StartPos: 9,
EndPos: 11,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 10,
StartPos: 9,
EndPos: 11,
},
Value: "a",
@ -129,21 +128,21 @@ func TestAltElseIf(t *testing.T) {
Position: &position.Position{
StartLine: 3,
EndLine: -1,
StartPos: 18,
StartPos: 17,
EndPos: -1,
},
Cond: &expr.Variable{
Position: &position.Position{
StartLine: 3,
EndLine: 3,
StartPos: 26,
StartPos: 25,
EndPos: 27,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 3,
EndLine: 3,
StartPos: 26,
StartPos: 25,
EndPos: 27,
},
Value: "b",
@ -164,12 +163,12 @@ func TestAltElseIf(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -186,7 +185,7 @@ func TestAltElse(t *testing.T) {
Position: &position.Position{
StartLine: 2,
EndLine: 4,
StartPos: 6,
StartPos: 5,
EndPos: 31,
},
Stmts: []node.Node{
@ -194,21 +193,21 @@ func TestAltElse(t *testing.T) {
Position: &position.Position{
StartLine: 2,
EndLine: 4,
StartPos: 6,
StartPos: 5,
EndPos: 31,
},
Cond: &expr.Variable{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 10,
StartPos: 9,
EndPos: 11,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 10,
StartPos: 9,
EndPos: 11,
},
Value: "a",
@ -227,7 +226,7 @@ func TestAltElse(t *testing.T) {
Position: &position.Position{
StartLine: 3,
EndLine: -1,
StartPos: 18,
StartPos: 17,
EndPos: -1,
},
Stmt: &stmt.StmtList{
@ -244,12 +243,12 @@ func TestAltElse(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -268,7 +267,7 @@ func TestAltElseElseIf(t *testing.T) {
Position: &position.Position{
StartLine: 2,
EndLine: 6,
StartPos: 6,
StartPos: 5,
EndPos: 61,
},
Stmts: []node.Node{
@ -276,21 +275,21 @@ func TestAltElseElseIf(t *testing.T) {
Position: &position.Position{
StartLine: 2,
EndLine: 6,
StartPos: 6,
StartPos: 5,
EndPos: 61,
},
Cond: &expr.Variable{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 10,
StartPos: 9,
EndPos: 11,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 10,
StartPos: 9,
EndPos: 11,
},
Value: "a",
@ -310,21 +309,21 @@ func TestAltElseElseIf(t *testing.T) {
Position: &position.Position{
StartLine: 3,
EndLine: -1,
StartPos: 18,
StartPos: 17,
EndPos: -1,
},
Cond: &expr.Variable{
Position: &position.Position{
StartLine: 3,
EndLine: 3,
StartPos: 26,
StartPos: 25,
EndPos: 27,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 3,
EndLine: 3,
StartPos: 26,
StartPos: 25,
EndPos: 27,
},
Value: "b",
@ -344,21 +343,21 @@ func TestAltElseElseIf(t *testing.T) {
Position: &position.Position{
StartLine: 4,
EndLine: -1,
StartPos: 33,
StartPos: 32,
EndPos: -1,
},
Cond: &expr.Variable{
Position: &position.Position{
StartLine: 4,
EndLine: 4,
StartPos: 41,
StartPos: 40,
EndPos: 42,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 4,
EndLine: 4,
StartPos: 41,
StartPos: 40,
EndPos: 42,
},
Value: "c",
@ -379,7 +378,7 @@ func TestAltElseElseIf(t *testing.T) {
Position: &position.Position{
StartLine: 5,
EndLine: -1,
StartPos: 48,
StartPos: 47,
EndPos: -1,
},
Stmt: &stmt.StmtList{
@ -396,12 +395,12 @@ func TestAltElseElseIf(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@ -1,7 +1,6 @@
package stmt_test
import (
"bytes"
"testing"
"gotest.tools/assert"
@ -22,7 +21,7 @@ func TestClassConstList(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 46,
},
Stmts: []node.Node{
@ -30,7 +29,7 @@ func TestClassConstList(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 46,
},
PhpDocComment: "",
@ -38,7 +37,7 @@ func TestClassConstList(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
StartPos: 9,
EndPos: 12,
},
Value: "foo",
@ -48,7 +47,7 @@ func TestClassConstList(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 15,
StartPos: 14,
EndPos: 44,
},
Modifiers: []node.Node{
@ -56,7 +55,7 @@ func TestClassConstList(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 15,
StartPos: 14,
EndPos: 20,
},
Value: "public",
@ -67,7 +66,7 @@ func TestClassConstList(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 28,
StartPos: 27,
EndPos: 34,
},
PhpDocComment: "",
@ -75,7 +74,7 @@ func TestClassConstList(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 28,
StartPos: 27,
EndPos: 30,
},
Value: "FOO",
@ -84,7 +83,7 @@ func TestClassConstList(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 34,
StartPos: 33,
EndPos: 34,
},
Value: "1",
@ -94,7 +93,7 @@ func TestClassConstList(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 37,
StartPos: 36,
EndPos: 43,
},
PhpDocComment: "",
@ -102,7 +101,7 @@ func TestClassConstList(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 37,
StartPos: 36,
EndPos: 39,
},
Value: "BAR",
@ -111,7 +110,7 @@ func TestClassConstList(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 43,
StartPos: 42,
EndPos: 43,
},
Value: "2",
@ -124,7 +123,7 @@ func TestClassConstList(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -137,7 +136,7 @@ func TestClassConstListWithoutModifiers(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 39,
},
Stmts: []node.Node{
@ -145,7 +144,7 @@ func TestClassConstListWithoutModifiers(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 39,
},
PhpDocComment: "",
@ -153,7 +152,7 @@ func TestClassConstListWithoutModifiers(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
StartPos: 9,
EndPos: 12,
},
Value: "foo",
@ -163,7 +162,7 @@ func TestClassConstListWithoutModifiers(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 15,
StartPos: 14,
EndPos: 37,
},
Consts: []node.Node{
@ -171,7 +170,7 @@ func TestClassConstListWithoutModifiers(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 21,
StartPos: 20,
EndPos: 27,
},
PhpDocComment: "",
@ -179,7 +178,7 @@ func TestClassConstListWithoutModifiers(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 21,
StartPos: 20,
EndPos: 23,
},
Value: "FOO",
@ -188,7 +187,7 @@ func TestClassConstListWithoutModifiers(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 27,
StartPos: 26,
EndPos: 27,
},
Value: "1",
@ -198,7 +197,7 @@ func TestClassConstListWithoutModifiers(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 30,
StartPos: 29,
EndPos: 36,
},
PhpDocComment: "",
@ -206,7 +205,7 @@ func TestClassConstListWithoutModifiers(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 30,
StartPos: 29,
EndPos: 32,
},
Value: "BAR",
@ -215,7 +214,7 @@ func TestClassConstListWithoutModifiers(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 36,
StartPos: 35,
EndPos: 36,
},
Value: "2",
@ -228,12 +227,12 @@ func TestClassConstListWithoutModifiers(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@ -1,7 +1,6 @@
package stmt_test
import (
"bytes"
"testing"
"gotest.tools/assert"
@ -22,7 +21,7 @@ func TestSimpleClassMethod(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 33,
},
Stmts: []node.Node{
@ -30,7 +29,7 @@ func TestSimpleClassMethod(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 33,
},
PhpDocComment: "",
@ -38,7 +37,7 @@ func TestSimpleClassMethod(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
StartPos: 9,
EndPos: 12,
},
Value: "foo",
@ -48,7 +47,7 @@ func TestSimpleClassMethod(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 15,
StartPos: 14,
EndPos: 31,
},
ReturnsRef: false,
@ -57,7 +56,7 @@ func TestSimpleClassMethod(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 24,
StartPos: 23,
EndPos: 26,
},
Value: "bar",
@ -66,7 +65,7 @@ func TestSimpleClassMethod(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 30,
StartPos: 29,
EndPos: 31,
},
Stmts: []node.Node{},
@ -77,12 +76,12 @@ func TestSimpleClassMethod(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -95,7 +94,7 @@ func TestPrivateProtectedClassMethod(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 75,
},
Stmts: []node.Node{
@ -103,7 +102,7 @@ func TestPrivateProtectedClassMethod(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 75,
},
PhpDocComment: "",
@ -111,7 +110,7 @@ func TestPrivateProtectedClassMethod(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
StartPos: 9,
EndPos: 12,
},
Value: "foo",
@ -121,7 +120,7 @@ func TestPrivateProtectedClassMethod(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 15,
StartPos: 14,
EndPos: 45,
},
ReturnsRef: false,
@ -130,7 +129,7 @@ func TestPrivateProtectedClassMethod(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 38,
StartPos: 37,
EndPos: 40,
},
Value: "bar",
@ -140,7 +139,7 @@ func TestPrivateProtectedClassMethod(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 15,
StartPos: 14,
EndPos: 19,
},
Value: "final",
@ -149,7 +148,7 @@ func TestPrivateProtectedClassMethod(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 21,
StartPos: 20,
EndPos: 27,
},
Value: "private",
@ -159,7 +158,7 @@ func TestPrivateProtectedClassMethod(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 44,
StartPos: 43,
EndPos: 45,
},
Stmts: []node.Node{},
@ -169,7 +168,7 @@ func TestPrivateProtectedClassMethod(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 47,
StartPos: 46,
EndPos: 73,
},
ReturnsRef: false,
@ -178,7 +177,7 @@ func TestPrivateProtectedClassMethod(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 66,
StartPos: 65,
EndPos: 68,
},
Value: "baz",
@ -188,7 +187,7 @@ func TestPrivateProtectedClassMethod(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 47,
StartPos: 46,
EndPos: 55,
},
Value: "protected",
@ -198,7 +197,7 @@ func TestPrivateProtectedClassMethod(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 72,
StartPos: 71,
EndPos: 73,
},
Stmts: []node.Node{},
@ -209,12 +208,12 @@ func TestPrivateProtectedClassMethod(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -227,7 +226,7 @@ func TestPhp5ClassMethod(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 48,
},
Stmts: []node.Node{
@ -235,7 +234,7 @@ func TestPhp5ClassMethod(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 48,
},
PhpDocComment: "",
@ -243,7 +242,7 @@ func TestPhp5ClassMethod(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
StartPos: 9,
EndPos: 12,
},
Value: "foo",
@ -253,7 +252,7 @@ func TestPhp5ClassMethod(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 15,
StartPos: 14,
EndPos: 46,
},
ReturnsRef: true,
@ -262,7 +261,7 @@ func TestPhp5ClassMethod(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 39,
StartPos: 38,
EndPos: 41,
},
Value: "bar",
@ -272,7 +271,7 @@ func TestPhp5ClassMethod(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 15,
StartPos: 14,
EndPos: 20,
},
Value: "public",
@ -281,7 +280,7 @@ func TestPhp5ClassMethod(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 22,
StartPos: 21,
EndPos: 27,
},
Value: "static",
@ -291,7 +290,7 @@ func TestPhp5ClassMethod(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 45,
StartPos: 44,
EndPos: 46,
},
Stmts: []node.Node{},
@ -302,7 +301,7 @@ func TestPhp5ClassMethod(t *testing.T) {
},
}
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual := php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -315,7 +314,7 @@ func TestPhp7ClassMethod(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 54,
},
Stmts: []node.Node{
@ -323,7 +322,7 @@ func TestPhp7ClassMethod(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 54,
},
PhpDocComment: "",
@ -331,7 +330,7 @@ func TestPhp7ClassMethod(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
StartPos: 9,
EndPos: 12,
},
Value: "foo",
@ -341,7 +340,7 @@ func TestPhp7ClassMethod(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 15,
StartPos: 14,
EndPos: 52,
},
ReturnsRef: true,
@ -350,7 +349,7 @@ func TestPhp7ClassMethod(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 39,
StartPos: 38,
EndPos: 41,
},
Value: "bar",
@ -360,7 +359,7 @@ func TestPhp7ClassMethod(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 15,
StartPos: 14,
EndPos: 20,
},
Value: "public",
@ -369,7 +368,7 @@ func TestPhp7ClassMethod(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 22,
StartPos: 21,
EndPos: 27,
},
Value: "static",
@ -379,7 +378,7 @@ func TestPhp7ClassMethod(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 46,
StartPos: 45,
EndPos: 49,
},
Parts: []node.Node{
@ -387,7 +386,7 @@ func TestPhp7ClassMethod(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 46,
StartPos: 45,
EndPos: 49,
},
Value: "void",
@ -398,7 +397,7 @@ func TestPhp7ClassMethod(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 51,
StartPos: 50,
EndPos: 52,
},
Stmts: []node.Node{},
@ -409,7 +408,7 @@ func TestPhp7ClassMethod(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -422,7 +421,7 @@ func TestAbstractClassMethod(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 56,
},
Stmts: []node.Node{
@ -430,7 +429,7 @@ func TestAbstractClassMethod(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 56,
},
PhpDocComment: "",
@ -438,7 +437,7 @@ func TestAbstractClassMethod(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 19,
StartPos: 18,
EndPos: 21,
},
Value: "Foo",
@ -448,7 +447,7 @@ func TestAbstractClassMethod(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 11,
},
Value: "abstract",
@ -459,7 +458,7 @@ func TestAbstractClassMethod(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 24,
StartPos: 23,
EndPos: 54,
},
ReturnsRef: false,
@ -468,7 +467,7 @@ func TestAbstractClassMethod(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 49,
StartPos: 48,
EndPos: 51,
},
Value: "bar",
@ -478,7 +477,7 @@ func TestAbstractClassMethod(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 24,
StartPos: 23,
EndPos: 31,
},
Value: "abstract",
@ -487,7 +486,7 @@ func TestAbstractClassMethod(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 33,
StartPos: 32,
EndPos: 38,
},
Value: "public",
@ -497,7 +496,7 @@ func TestAbstractClassMethod(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 54,
StartPos: 53,
EndPos: 54,
},
},
@ -507,12 +506,12 @@ func TestAbstractClassMethod(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -525,7 +524,7 @@ func TestPhp7AbstractClassMethod(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 53,
},
Stmts: []node.Node{
@ -533,7 +532,7 @@ func TestPhp7AbstractClassMethod(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 53,
},
PhpDocComment: "",
@ -541,7 +540,7 @@ func TestPhp7AbstractClassMethod(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 19,
StartPos: 18,
EndPos: 21,
},
Value: "Foo",
@ -551,7 +550,7 @@ func TestPhp7AbstractClassMethod(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 11,
},
Value: "abstract",
@ -562,7 +561,7 @@ func TestPhp7AbstractClassMethod(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 24,
StartPos: 23,
EndPos: 51,
},
ReturnsRef: false,
@ -571,7 +570,7 @@ func TestPhp7AbstractClassMethod(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 40,
StartPos: 39,
EndPos: 42,
},
Value: "bar",
@ -581,7 +580,7 @@ func TestPhp7AbstractClassMethod(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 24,
StartPos: 23,
EndPos: 29,
},
Value: "public",
@ -591,7 +590,7 @@ func TestPhp7AbstractClassMethod(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 47,
StartPos: 46,
EndPos: 50,
},
Parts: []node.Node{
@ -599,7 +598,7 @@ func TestPhp7AbstractClassMethod(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 47,
StartPos: 46,
EndPos: 50,
},
Value: "void",
@ -610,7 +609,7 @@ func TestPhp7AbstractClassMethod(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 51,
StartPos: 50,
EndPos: 51,
},
},
@ -620,7 +619,7 @@ func TestPhp7AbstractClassMethod(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@ -1,7 +1,6 @@
package stmt_test
import (
"bytes"
"testing"
"gotest.tools/assert"
@ -23,7 +22,7 @@ func TestSimpleClass(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 15,
},
Stmts: []node.Node{
@ -31,7 +30,7 @@ func TestSimpleClass(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 15,
},
PhpDocComment: "",
@ -39,7 +38,7 @@ func TestSimpleClass(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
StartPos: 9,
EndPos: 12,
},
Value: "foo",
@ -49,12 +48,12 @@ func TestSimpleClass(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -67,7 +66,7 @@ func TestAbstractClass(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 24,
},
Stmts: []node.Node{
@ -75,7 +74,7 @@ func TestAbstractClass(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 24,
},
PhpDocComment: "",
@ -83,7 +82,7 @@ func TestAbstractClass(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 19,
StartPos: 18,
EndPos: 21,
},
Value: "foo",
@ -93,7 +92,7 @@ func TestAbstractClass(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 11,
},
Value: "abstract",
@ -104,12 +103,12 @@ func TestAbstractClass(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -122,7 +121,7 @@ func TestClassExtends(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 34,
},
Stmts: []node.Node{
@ -130,7 +129,7 @@ func TestClassExtends(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 34,
},
PhpDocComment: "",
@ -138,7 +137,7 @@ func TestClassExtends(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 16,
StartPos: 15,
EndPos: 18,
},
Value: "foo",
@ -148,7 +147,7 @@ func TestClassExtends(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 8,
},
Value: "final",
@ -158,14 +157,14 @@ func TestClassExtends(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 20,
StartPos: 19,
EndPos: 30,
},
ClassName: &name.Name{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 28,
StartPos: 27,
EndPos: 30,
},
Parts: []node.Node{
@ -173,7 +172,7 @@ func TestClassExtends(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 28,
StartPos: 27,
EndPos: 30,
},
Value: "bar",
@ -186,12 +185,12 @@ func TestClassExtends(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -204,7 +203,7 @@ func TestClassImplement(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 37,
},
Stmts: []node.Node{
@ -212,7 +211,7 @@ func TestClassImplement(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 37,
},
PhpDocComment: "",
@ -220,7 +219,7 @@ func TestClassImplement(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 16,
StartPos: 15,
EndPos: 18,
},
Value: "foo",
@ -230,7 +229,7 @@ func TestClassImplement(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 8,
},
Value: "final",
@ -240,7 +239,7 @@ func TestClassImplement(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 20,
StartPos: 19,
EndPos: 33,
},
InterfaceNames: []node.Node{
@ -248,7 +247,7 @@ func TestClassImplement(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 31,
StartPos: 30,
EndPos: 33,
},
Parts: []node.Node{
@ -256,7 +255,7 @@ func TestClassImplement(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 31,
StartPos: 30,
EndPos: 33,
},
Value: "bar",
@ -270,12 +269,12 @@ func TestClassImplement(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -288,7 +287,7 @@ func TestClassImplements(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 42,
},
Stmts: []node.Node{
@ -296,7 +295,7 @@ func TestClassImplements(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 42,
},
PhpDocComment: "",
@ -304,7 +303,7 @@ func TestClassImplements(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 16,
StartPos: 15,
EndPos: 18,
},
Value: "foo",
@ -314,7 +313,7 @@ func TestClassImplements(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 8,
},
Value: "final",
@ -324,7 +323,7 @@ func TestClassImplements(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 20,
StartPos: 19,
EndPos: 38,
},
InterfaceNames: []node.Node{
@ -332,7 +331,7 @@ func TestClassImplements(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 31,
StartPos: 30,
EndPos: 33,
},
Parts: []node.Node{
@ -340,7 +339,7 @@ func TestClassImplements(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 31,
StartPos: 30,
EndPos: 33,
},
Value: "bar",
@ -351,7 +350,7 @@ func TestClassImplements(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 36,
StartPos: 35,
EndPos: 38,
},
Parts: []node.Node{
@ -359,7 +358,7 @@ func TestClassImplements(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 36,
StartPos: 35,
EndPos: 38,
},
Value: "baz",
@ -373,12 +372,12 @@ func TestClassImplements(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -391,7 +390,7 @@ func TestAnonimousClass(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 51,
},
Stmts: []node.Node{
@ -399,21 +398,21 @@ func TestAnonimousClass(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 51,
},
Expr: &expr.New{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 50,
},
Class: &stmt.Class{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 8,
StartPos: 7,
EndPos: 50,
},
PhpDocComment: "",
@ -421,7 +420,7 @@ func TestAnonimousClass(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 13,
StartPos: 12,
EndPos: 14,
},
},
@ -429,14 +428,14 @@ func TestAnonimousClass(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 16,
StartPos: 15,
EndPos: 26,
},
ClassName: &name.Name{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 24,
StartPos: 23,
EndPos: 26,
},
Parts: []node.Node{
@ -444,7 +443,7 @@ func TestAnonimousClass(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 24,
StartPos: 23,
EndPos: 26,
},
Value: "foo",
@ -456,7 +455,7 @@ func TestAnonimousClass(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 28,
StartPos: 27,
EndPos: 46,
},
InterfaceNames: []node.Node{
@ -464,7 +463,7 @@ func TestAnonimousClass(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 39,
StartPos: 38,
EndPos: 41,
},
Parts: []node.Node{
@ -472,7 +471,7 @@ func TestAnonimousClass(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 39,
StartPos: 38,
EndPos: 41,
},
Value: "bar",
@ -483,7 +482,7 @@ func TestAnonimousClass(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 44,
StartPos: 43,
EndPos: 46,
},
Parts: []node.Node{
@ -491,7 +490,7 @@ func TestAnonimousClass(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 44,
StartPos: 43,
EndPos: 46,
},
Value: "baz",
@ -507,7 +506,7 @@ func TestAnonimousClass(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@ -1,7 +1,6 @@
package stmt_test
import (
"bytes"
"testing"
"gotest.tools/assert"
@ -22,7 +21,7 @@ func TestConstList(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 26,
},
Stmts: []node.Node{
@ -30,7 +29,7 @@ func TestConstList(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 26,
},
Consts: []node.Node{
@ -38,7 +37,7 @@ func TestConstList(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
StartPos: 9,
EndPos: 16,
},
PhpDocComment: "",
@ -46,7 +45,7 @@ func TestConstList(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
StartPos: 9,
EndPos: 12,
},
Value: "FOO",
@ -55,7 +54,7 @@ func TestConstList(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 16,
StartPos: 15,
EndPos: 16,
},
Value: "1",
@ -65,7 +64,7 @@ func TestConstList(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 19,
StartPos: 18,
EndPos: 25,
},
PhpDocComment: "",
@ -73,7 +72,7 @@ func TestConstList(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 19,
StartPos: 18,
EndPos: 21,
},
Value: "BAR",
@ -82,7 +81,7 @@ func TestConstList(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 25,
StartPos: 24,
EndPos: 25,
},
Value: "2",
@ -93,12 +92,12 @@ func TestConstList(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@ -1,7 +1,6 @@
package stmt_test
import (
"bytes"
"testing"
"gotest.tools/assert"
@ -22,7 +21,7 @@ func TestContinueEmpty(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 26,
},
Stmts: []node.Node{
@ -30,14 +29,14 @@ func TestContinueEmpty(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 26,
},
Cond: &scalar.Lnumber{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 11,
StartPos: 10,
EndPos: 11,
},
Value: "1",
@ -46,7 +45,7 @@ func TestContinueEmpty(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 14,
StartPos: 13,
EndPos: 26,
},
Stmts: []node.Node{
@ -54,7 +53,7 @@ func TestContinueEmpty(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 16,
StartPos: 15,
EndPos: 24,
},
},
@ -64,12 +63,12 @@ func TestContinueEmpty(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -82,7 +81,7 @@ func TestContinueLight(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 28,
},
Stmts: []node.Node{
@ -90,14 +89,14 @@ func TestContinueLight(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 28,
},
Cond: &scalar.Lnumber{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 11,
StartPos: 10,
EndPos: 11,
},
Value: "1",
@ -106,7 +105,7 @@ func TestContinueLight(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 14,
StartPos: 13,
EndPos: 28,
},
Stmts: []node.Node{
@ -114,14 +113,14 @@ func TestContinueLight(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 16,
StartPos: 15,
EndPos: 26,
},
Expr: &scalar.Lnumber{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 25,
StartPos: 24,
EndPos: 25,
},
Value: "2",
@ -133,12 +132,12 @@ func TestContinueLight(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -151,7 +150,7 @@ func TestContinue(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 29,
},
Stmts: []node.Node{
@ -159,14 +158,14 @@ func TestContinue(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 29,
},
Cond: &scalar.Lnumber{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 11,
StartPos: 10,
EndPos: 11,
},
Value: "1",
@ -175,7 +174,7 @@ func TestContinue(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 14,
StartPos: 13,
EndPos: 29,
},
Stmts: []node.Node{
@ -183,14 +182,14 @@ func TestContinue(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 16,
StartPos: 15,
EndPos: 27,
},
Expr: &scalar.Lnumber{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 25,
StartPos: 24,
EndPos: 25,
},
Value: "3",
@ -202,12 +201,12 @@ func TestContinue(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@ -1,7 +1,6 @@
package stmt_test
import (
"bytes"
"testing"
"gotest.tools/assert"
@ -22,7 +21,7 @@ func TestDeclare(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 20,
},
Stmts: []node.Node{
@ -30,7 +29,7 @@ func TestDeclare(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 20,
},
Consts: []node.Node{
@ -38,7 +37,7 @@ func TestDeclare(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 12,
StartPos: 11,
EndPos: 18,
},
PhpDocComment: "",
@ -46,7 +45,7 @@ func TestDeclare(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 12,
StartPos: 11,
EndPos: 16,
},
Value: "ticks",
@ -55,7 +54,7 @@ func TestDeclare(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 18,
StartPos: 17,
EndPos: 18,
},
Value: "1",
@ -66,7 +65,7 @@ func TestDeclare(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 20,
StartPos: 19,
EndPos: 20,
},
},
@ -74,12 +73,12 @@ func TestDeclare(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -92,7 +91,7 @@ func TestDeclareStmts(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 38,
},
Stmts: []node.Node{
@ -100,7 +99,7 @@ func TestDeclareStmts(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 38,
},
Consts: []node.Node{
@ -108,7 +107,7 @@ func TestDeclareStmts(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 12,
StartPos: 11,
EndPos: 18,
},
PhpDocComment: "",
@ -116,7 +115,7 @@ func TestDeclareStmts(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 12,
StartPos: 11,
EndPos: 16,
},
Value: "ticks",
@ -125,7 +124,7 @@ func TestDeclareStmts(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 18,
StartPos: 17,
EndPos: 18,
},
Value: "1",
@ -135,7 +134,7 @@ func TestDeclareStmts(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 21,
StartPos: 20,
EndPos: 34,
},
PhpDocComment: "",
@ -143,7 +142,7 @@ func TestDeclareStmts(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 21,
StartPos: 20,
EndPos: 32,
},
Value: "strict_types",
@ -152,7 +151,7 @@ func TestDeclareStmts(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 34,
StartPos: 33,
EndPos: 34,
},
Value: "1",
@ -163,7 +162,7 @@ func TestDeclareStmts(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 37,
StartPos: 36,
EndPos: 38,
},
Stmts: []node.Node{},
@ -172,12 +171,12 @@ func TestDeclareStmts(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -190,7 +189,7 @@ func TestAltDeclare(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 32,
},
Stmts: []node.Node{
@ -198,7 +197,7 @@ func TestAltDeclare(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 32,
},
Consts: []node.Node{
@ -206,7 +205,7 @@ func TestAltDeclare(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 12,
StartPos: 11,
EndPos: 18,
},
PhpDocComment: "",
@ -214,7 +213,7 @@ func TestAltDeclare(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 12,
StartPos: 11,
EndPos: 16,
},
Value: "ticks",
@ -223,7 +222,7 @@ func TestAltDeclare(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 18,
StartPos: 17,
EndPos: 18,
},
Value: "1",
@ -244,12 +243,12 @@ func TestAltDeclare(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@ -1,7 +1,6 @@
package stmt_test
import (
"bytes"
"testing"
"gotest.tools/assert"
@ -22,7 +21,7 @@ func TestDo(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 18,
},
Stmts: []node.Node{
@ -30,14 +29,14 @@ func TestDo(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 18,
},
Stmt: &stmt.StmtList{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 7,
StartPos: 6,
EndPos: 8,
},
Stmts: []node.Node{},
@ -46,7 +45,7 @@ func TestDo(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 16,
StartPos: 15,
EndPos: 16,
},
Value: "1",
@ -55,12 +54,12 @@ func TestDo(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@ -1,7 +1,6 @@
package stmt_test
import (
"bytes"
"testing"
"gotest.tools/assert"
@ -24,7 +23,7 @@ func TestSimpleEcho(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 14,
},
Stmts: []node.Node{
@ -32,7 +31,7 @@ func TestSimpleEcho(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 14,
},
Exprs: []node.Node{
@ -40,14 +39,14 @@ func TestSimpleEcho(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 9,
StartPos: 8,
EndPos: 10,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 9,
StartPos: 8,
EndPos: 10,
},
Value: "a",
@ -57,7 +56,7 @@ func TestSimpleEcho(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 13,
StartPos: 12,
EndPos: 13,
},
Value: "1",
@ -67,12 +66,12 @@ func TestSimpleEcho(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -85,7 +84,7 @@ func TestEcho(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 12,
},
Stmts: []node.Node{
@ -93,7 +92,7 @@ func TestEcho(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 12,
},
Exprs: []node.Node{
@ -101,14 +100,14 @@ func TestEcho(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 9,
StartPos: 8,
EndPos: 10,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 9,
StartPos: 8,
EndPos: 10,
},
Value: "a",
@ -119,12 +118,12 @@ func TestEcho(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@ -1,7 +1,6 @@
package stmt_test
import (
"bytes"
"testing"
"gotest.tools/assert"
@ -22,7 +21,7 @@ func TestExpression(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 5,
},
Stmts: []node.Node{
@ -30,14 +29,14 @@ func TestExpression(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 5,
},
Expr: &scalar.Lnumber{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 4,
},
Value: "1",
@ -46,12 +45,12 @@ func TestExpression(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@ -1,7 +1,6 @@
package stmt_test
import (
"bytes"
"testing"
"gotest.tools/assert"
@ -27,7 +26,7 @@ func TestFor(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 38,
},
Stmts: []node.Node{
@ -35,7 +34,7 @@ func TestFor(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 38,
},
Init: []node.Node{
@ -43,21 +42,21 @@ func TestFor(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 8,
StartPos: 7,
EndPos: 13,
},
Variable: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 8,
StartPos: 7,
EndPos: 9,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 8,
StartPos: 7,
EndPos: 9,
},
Value: "i",
@ -67,7 +66,7 @@ func TestFor(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 13,
StartPos: 12,
EndPos: 13,
},
Value: "0",
@ -79,21 +78,21 @@ func TestFor(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 16,
StartPos: 15,
EndPos: 22,
},
Left: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 16,
StartPos: 15,
EndPos: 17,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 16,
StartPos: 15,
EndPos: 17,
},
Value: "i",
@ -103,7 +102,7 @@ func TestFor(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 21,
StartPos: 20,
EndPos: 22,
},
Value: "10",
@ -115,21 +114,21 @@ func TestFor(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 25,
StartPos: 24,
EndPos: 28,
},
Variable: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 25,
StartPos: 24,
EndPos: 26,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 25,
StartPos: 24,
EndPos: 26,
},
Value: "i",
@ -140,21 +139,21 @@ func TestFor(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 31,
StartPos: 30,
EndPos: 34,
},
Variable: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 31,
StartPos: 30,
EndPos: 32,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 31,
StartPos: 30,
EndPos: 32,
},
Value: "i",
@ -166,7 +165,7 @@ func TestFor(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 37,
StartPos: 36,
EndPos: 38,
},
Stmts: []node.Node{},
@ -175,12 +174,12 @@ func TestFor(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -193,7 +192,7 @@ func TestAltFor(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 33,
},
Stmts: []node.Node{
@ -201,7 +200,7 @@ func TestAltFor(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 33,
},
Cond: []node.Node{
@ -209,21 +208,21 @@ func TestAltFor(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
StartPos: 9,
EndPos: 16,
},
Left: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
StartPos: 9,
EndPos: 11,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
StartPos: 9,
EndPos: 11,
},
Value: "i",
@ -233,7 +232,7 @@ func TestAltFor(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 15,
StartPos: 14,
EndPos: 16,
},
Value: "10",
@ -245,21 +244,21 @@ func TestAltFor(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 19,
StartPos: 18,
EndPos: 22,
},
Variable: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 19,
StartPos: 18,
EndPos: 20,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 19,
StartPos: 18,
EndPos: 20,
},
Value: "i",
@ -280,12 +279,12 @@ func TestAltFor(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@ -1,7 +1,6 @@
package stmt_test
import (
"bytes"
"testing"
"gotest.tools/assert"
@ -22,7 +21,7 @@ func TestForeach(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 24,
},
Stmts: []node.Node{
@ -30,21 +29,21 @@ func TestForeach(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 24,
},
Expr: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 13,
StartPos: 12,
EndPos: 14,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 13,
StartPos: 12,
EndPos: 14,
},
Value: "a",
@ -54,14 +53,14 @@ func TestForeach(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 19,
StartPos: 18,
EndPos: 20,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 19,
StartPos: 18,
EndPos: 20,
},
Value: "v",
@ -71,7 +70,7 @@ func TestForeach(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 23,
StartPos: 22,
EndPos: 24,
},
Stmts: []node.Node{},
@ -80,12 +79,12 @@ func TestForeach(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -98,7 +97,7 @@ func TestForeachExpr(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 24,
},
Stmts: []node.Node{
@ -106,14 +105,14 @@ func TestForeachExpr(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 24,
},
Expr: &expr.ShortArray{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 13,
StartPos: 12,
EndPos: 14,
},
Items: []node.Node{},
@ -122,14 +121,14 @@ func TestForeachExpr(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 19,
StartPos: 18,
EndPos: 20,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 19,
StartPos: 18,
EndPos: 20,
},
Value: "v",
@ -139,7 +138,7 @@ func TestForeachExpr(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 23,
StartPos: 22,
EndPos: 24,
},
Stmts: []node.Node{},
@ -148,12 +147,12 @@ func TestForeachExpr(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -166,7 +165,7 @@ func TestAltForeach(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 35,
},
Stmts: []node.Node{
@ -174,21 +173,21 @@ func TestAltForeach(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 35,
},
Expr: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 13,
StartPos: 12,
EndPos: 14,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 13,
StartPos: 12,
EndPos: 14,
},
Value: "a",
@ -198,14 +197,14 @@ func TestAltForeach(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 19,
StartPos: 18,
EndPos: 20,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 19,
StartPos: 18,
EndPos: 20,
},
Value: "v",
@ -224,12 +223,12 @@ func TestAltForeach(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -242,7 +241,7 @@ func TestForeachWithKey(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 30,
},
Stmts: []node.Node{
@ -250,21 +249,21 @@ func TestForeachWithKey(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 30,
},
Expr: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 13,
StartPos: 12,
EndPos: 14,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 13,
StartPos: 12,
EndPos: 14,
},
Value: "a",
@ -274,14 +273,14 @@ func TestForeachWithKey(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 19,
StartPos: 18,
EndPos: 20,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 19,
StartPos: 18,
EndPos: 20,
},
Value: "k",
@ -291,14 +290,14 @@ func TestForeachWithKey(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 25,
StartPos: 24,
EndPos: 26,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 25,
StartPos: 24,
EndPos: 26,
},
Value: "v",
@ -308,7 +307,7 @@ func TestForeachWithKey(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 29,
StartPos: 28,
EndPos: 30,
},
Stmts: []node.Node{},
@ -317,12 +316,12 @@ func TestForeachWithKey(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -335,7 +334,7 @@ func TestForeachExprWithKey(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 30,
},
Stmts: []node.Node{
@ -343,14 +342,14 @@ func TestForeachExprWithKey(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 30,
},
Expr: &expr.ShortArray{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 13,
StartPos: 12,
EndPos: 14,
},
Items: []node.Node{},
@ -359,14 +358,14 @@ func TestForeachExprWithKey(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 19,
StartPos: 18,
EndPos: 20,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 19,
StartPos: 18,
EndPos: 20,
},
Value: "k",
@ -376,14 +375,14 @@ func TestForeachExprWithKey(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 25,
StartPos: 24,
EndPos: 26,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 25,
StartPos: 24,
EndPos: 26,
},
Value: "v",
@ -393,7 +392,7 @@ func TestForeachExprWithKey(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 29,
StartPos: 28,
EndPos: 30,
},
Stmts: []node.Node{},
@ -402,12 +401,12 @@ func TestForeachExprWithKey(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -420,7 +419,7 @@ func TestForeachWithRef(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 31,
},
Stmts: []node.Node{
@ -428,21 +427,21 @@ func TestForeachWithRef(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 31,
},
Expr: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 13,
StartPos: 12,
EndPos: 14,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 13,
StartPos: 12,
EndPos: 14,
},
Value: "a",
@ -452,14 +451,14 @@ func TestForeachWithRef(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 19,
StartPos: 18,
EndPos: 20,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 19,
StartPos: 18,
EndPos: 20,
},
Value: "k",
@ -469,21 +468,21 @@ func TestForeachWithRef(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 25,
StartPos: 24,
EndPos: 27,
},
Variable: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 26,
StartPos: 25,
EndPos: 27,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 26,
StartPos: 25,
EndPos: 27,
},
Value: "v",
@ -494,7 +493,7 @@ func TestForeachWithRef(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 30,
StartPos: 29,
EndPos: 31,
},
Stmts: []node.Node{},
@ -503,12 +502,12 @@ func TestForeachWithRef(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -521,7 +520,7 @@ func TestForeachWithList(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 36,
},
Stmts: []node.Node{
@ -529,21 +528,21 @@ func TestForeachWithList(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 36,
},
Expr: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 13,
StartPos: 12,
EndPos: 14,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 13,
StartPos: 12,
EndPos: 14,
},
Value: "a",
@ -553,14 +552,14 @@ func TestForeachWithList(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 19,
StartPos: 18,
EndPos: 20,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 19,
StartPos: 18,
EndPos: 20,
},
Value: "k",
@ -570,7 +569,7 @@ func TestForeachWithList(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 25,
StartPos: 24,
EndPos: 32,
},
Items: []node.Node{
@ -578,21 +577,21 @@ func TestForeachWithList(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 30,
StartPos: 29,
EndPos: 31,
},
Val: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 30,
StartPos: 29,
EndPos: 31,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 30,
StartPos: 29,
EndPos: 31,
},
Value: "v",
@ -605,7 +604,7 @@ func TestForeachWithList(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 35,
StartPos: 34,
EndPos: 36,
},
Stmts: []node.Node{},
@ -614,12 +613,12 @@ func TestForeachWithList(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@ -1,7 +1,6 @@
package stmt_test
import (
"bytes"
"testing"
"gotest.tools/assert"
@ -24,7 +23,7 @@ func TestSimpleFunction(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 20,
},
Stmts: []node.Node{
@ -32,7 +31,7 @@ func TestSimpleFunction(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 20,
},
ReturnsRef: false,
@ -41,7 +40,7 @@ func TestSimpleFunction(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 13,
StartPos: 12,
EndPos: 15,
},
Value: "foo",
@ -51,12 +50,12 @@ func TestSimpleFunction(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -69,7 +68,7 @@ func TestFunctionReturn(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 27,
},
Stmts: []node.Node{
@ -77,7 +76,7 @@ func TestFunctionReturn(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 27,
},
ReturnsRef: false,
@ -86,7 +85,7 @@ func TestFunctionReturn(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 13,
StartPos: 12,
EndPos: 15,
},
Value: "foo",
@ -96,7 +95,7 @@ func TestFunctionReturn(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 20,
StartPos: 19,
EndPos: 26,
},
},
@ -105,12 +104,12 @@ func TestFunctionReturn(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -123,7 +122,7 @@ func TestFunctionReturnVar(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 51,
},
Stmts: []node.Node{
@ -131,7 +130,7 @@ func TestFunctionReturnVar(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 51,
},
ReturnsRef: false,
@ -140,7 +139,7 @@ func TestFunctionReturnVar(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 13,
StartPos: 12,
EndPos: 15,
},
Value: "foo",
@ -150,7 +149,7 @@ func TestFunctionReturnVar(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 17,
StartPos: 16,
EndPos: 24,
},
ByRef: false,
@ -159,7 +158,7 @@ func TestFunctionReturnVar(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 17,
StartPos: 16,
EndPos: 21,
},
Value: "array",
@ -168,14 +167,14 @@ func TestFunctionReturnVar(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 23,
StartPos: 22,
EndPos: 24,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 23,
StartPos: 22,
EndPos: 24,
},
Value: "a",
@ -186,7 +185,7 @@ func TestFunctionReturnVar(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 27,
StartPos: 26,
EndPos: 37,
},
ByRef: false,
@ -195,7 +194,7 @@ func TestFunctionReturnVar(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 27,
StartPos: 26,
EndPos: 34,
},
Value: "callable",
@ -204,14 +203,14 @@ func TestFunctionReturnVar(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 36,
StartPos: 35,
EndPos: 37,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 36,
StartPos: 35,
EndPos: 37,
},
Value: "b",
@ -224,21 +223,21 @@ func TestFunctionReturnVar(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 41,
StartPos: 40,
EndPos: 50,
},
Expr: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 48,
StartPos: 47,
EndPos: 49,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 48,
StartPos: 47,
EndPos: 49,
},
Value: "a",
@ -250,12 +249,12 @@ func TestFunctionReturnVar(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -268,7 +267,7 @@ func TestRefFunction(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 30,
},
Stmts: []node.Node{
@ -276,7 +275,7 @@ func TestRefFunction(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 30,
},
ReturnsRef: true,
@ -285,7 +284,7 @@ func TestRefFunction(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 14,
StartPos: 13,
EndPos: 16,
},
Value: "foo",
@ -295,14 +294,14 @@ func TestRefFunction(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 21,
StartPos: 20,
EndPos: 29,
},
Expr: &scalar.Lnumber{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 28,
StartPos: 27,
EndPos: 28,
},
Value: "1",
@ -313,12 +312,12 @@ func TestRefFunction(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -331,7 +330,7 @@ func TestReturnTypeFunction(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 27,
},
Stmts: []node.Node{
@ -339,7 +338,7 @@ func TestReturnTypeFunction(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 27,
},
PhpDocComment: "",
@ -348,7 +347,7 @@ func TestReturnTypeFunction(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 14,
StartPos: 13,
EndPos: 16,
},
Value: "foo",
@ -357,7 +356,7 @@ func TestReturnTypeFunction(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 21,
StartPos: 20,
EndPos: 24,
},
Parts: []node.Node{
@ -365,7 +364,7 @@ func TestReturnTypeFunction(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 21,
StartPos: 20,
EndPos: 24,
},
Value: "void",
@ -377,7 +376,7 @@ func TestReturnTypeFunction(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@ -1,7 +1,6 @@
package stmt_test
import (
"bytes"
"testing"
"gotest.tools/assert"
@ -22,7 +21,7 @@ func TestGlobal(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 13,
},
Stmts: []node.Node{
@ -30,7 +29,7 @@ func TestGlobal(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 13,
},
Vars: []node.Node{
@ -38,14 +37,14 @@ func TestGlobal(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 11,
StartPos: 10,
EndPos: 12,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 11,
StartPos: 10,
EndPos: 12,
},
Value: "a",
@ -56,12 +55,12 @@ func TestGlobal(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -74,7 +73,7 @@ func TestGlobalVars(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 32,
},
Stmts: []node.Node{
@ -82,7 +81,7 @@ func TestGlobalVars(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 32,
},
Vars: []node.Node{
@ -90,14 +89,14 @@ func TestGlobalVars(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 11,
StartPos: 10,
EndPos: 12,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 11,
StartPos: 10,
EndPos: 12,
},
Value: "a",
@ -107,14 +106,14 @@ func TestGlobalVars(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 15,
StartPos: 14,
EndPos: 16,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 15,
StartPos: 14,
EndPos: 16,
},
Value: "b",
@ -124,21 +123,21 @@ func TestGlobalVars(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 19,
StartPos: 18,
EndPos: 21,
},
VarName: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 20,
StartPos: 19,
EndPos: 21,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 20,
StartPos: 19,
EndPos: 21,
},
Value: "c",
@ -149,21 +148,21 @@ func TestGlobalVars(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 24,
StartPos: 23,
EndPos: 31,
},
VarName: &expr.FunctionCall{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 26,
StartPos: 25,
EndPos: 30,
},
Function: &name.Name{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 26,
StartPos: 25,
EndPos: 28,
},
Parts: []node.Node{
@ -171,7 +170,7 @@ func TestGlobalVars(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 26,
StartPos: 25,
EndPos: 28,
},
Value: "foo",
@ -182,7 +181,7 @@ func TestGlobalVars(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 29,
StartPos: 28,
EndPos: 30,
},
},
@ -193,12 +192,12 @@ func TestGlobalVars(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@ -1,7 +1,6 @@
package stmt_test
import (
"bytes"
"testing"
"gotest.tools/assert"
@ -20,7 +19,7 @@ func TestGotoLabel(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 13,
},
Stmts: []node.Node{
@ -28,14 +27,14 @@ func TestGotoLabel(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 5,
},
LabelName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 4,
},
Value: "a",
@ -45,14 +44,14 @@ func TestGotoLabel(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 7,
StartPos: 6,
EndPos: 13,
},
Label: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 12,
StartPos: 11,
EndPos: 12,
},
Value: "a",
@ -61,12 +60,12 @@ func TestGotoLabel(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@ -1,7 +1,6 @@
package stmt_test
import (
"bytes"
"testing"
"gotest.tools/assert"
@ -20,7 +19,7 @@ func TestHaltCompiler(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 21,
},
Stmts: []node.Node{
@ -28,19 +27,19 @@ func TestHaltCompiler(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 21,
},
},
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@ -1,7 +1,6 @@
package stmt_test
import (
"bytes"
"testing"
"gotest.tools/assert"
@ -22,7 +21,7 @@ func TestIf(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 13,
},
Stmts: []node.Node{
@ -30,21 +29,21 @@ func TestIf(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 13,
},
Cond: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 8,
StartPos: 7,
EndPos: 9,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 8,
StartPos: 7,
EndPos: 9,
},
Value: "a",
@ -54,7 +53,7 @@ func TestIf(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 12,
StartPos: 11,
EndPos: 13,
},
Stmts: []node.Node{},
@ -63,12 +62,12 @@ func TestIf(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -81,7 +80,7 @@ func TestElseIf(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 28,
},
Stmts: []node.Node{
@ -89,21 +88,21 @@ func TestElseIf(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 28,
},
Cond: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 8,
StartPos: 7,
EndPos: 9,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 8,
StartPos: 7,
EndPos: 9,
},
Value: "a",
@ -113,7 +112,7 @@ func TestElseIf(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 12,
StartPos: 11,
EndPos: 13,
},
Stmts: []node.Node{},
@ -123,21 +122,21 @@ func TestElseIf(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 15,
StartPos: 14,
EndPos: 28,
},
Cond: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 23,
StartPos: 22,
EndPos: 24,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 23,
StartPos: 22,
EndPos: 24,
},
Value: "b",
@ -147,7 +146,7 @@ func TestElseIf(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 27,
StartPos: 26,
EndPos: 28,
},
Stmts: []node.Node{},
@ -158,12 +157,12 @@ func TestElseIf(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -176,7 +175,7 @@ func TestElse(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 21,
},
Stmts: []node.Node{
@ -184,21 +183,21 @@ func TestElse(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 21,
},
Cond: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 8,
StartPos: 7,
EndPos: 9,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 8,
StartPos: 7,
EndPos: 9,
},
Value: "a",
@ -208,7 +207,7 @@ func TestElse(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 12,
StartPos: 11,
EndPos: 13,
},
Stmts: []node.Node{},
@ -217,14 +216,14 @@ func TestElse(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 15,
StartPos: 14,
EndPos: 21,
},
Stmt: &stmt.StmtList{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 20,
StartPos: 19,
EndPos: 21,
},
Stmts: []node.Node{},
@ -234,12 +233,12 @@ func TestElse(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -252,7 +251,7 @@ func TestElseElseIf(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 51,
},
Stmts: []node.Node{
@ -260,21 +259,21 @@ func TestElseElseIf(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 51,
},
Cond: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 8,
StartPos: 7,
EndPos: 9,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 8,
StartPos: 7,
EndPos: 9,
},
Value: "a",
@ -284,7 +283,7 @@ func TestElseElseIf(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 12,
StartPos: 11,
EndPos: 13,
},
Stmts: []node.Node{},
@ -294,21 +293,21 @@ func TestElseElseIf(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 15,
StartPos: 14,
EndPos: 28,
},
Cond: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 23,
StartPos: 22,
EndPos: 24,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 23,
StartPos: 22,
EndPos: 24,
},
Value: "b",
@ -318,7 +317,7 @@ func TestElseElseIf(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 27,
StartPos: 26,
EndPos: 28,
},
Stmts: []node.Node{},
@ -328,21 +327,21 @@ func TestElseElseIf(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 30,
StartPos: 29,
EndPos: 43,
},
Cond: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 38,
StartPos: 37,
EndPos: 39,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 38,
StartPos: 37,
EndPos: 39,
},
Value: "c",
@ -352,7 +351,7 @@ func TestElseElseIf(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 42,
StartPos: 41,
EndPos: 43,
},
Stmts: []node.Node{},
@ -363,14 +362,14 @@ func TestElseElseIf(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 45,
StartPos: 44,
EndPos: 51,
},
Stmt: &stmt.StmtList{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 50,
StartPos: 49,
EndPos: 51,
},
Stmts: []node.Node{},
@ -380,12 +379,12 @@ func TestElseElseIf(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -398,7 +397,7 @@ func TestElseIfElseIfElse(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 52,
},
Stmts: []node.Node{
@ -406,21 +405,21 @@ func TestElseIfElseIfElse(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 52,
},
Cond: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 8,
StartPos: 7,
EndPos: 9,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 8,
StartPos: 7,
EndPos: 9,
},
Value: "a",
@ -430,7 +429,7 @@ func TestElseIfElseIfElse(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 12,
StartPos: 11,
EndPos: 13,
},
Stmts: []node.Node{},
@ -440,21 +439,21 @@ func TestElseIfElseIfElse(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 15,
StartPos: 14,
EndPos: 28,
},
Cond: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 23,
StartPos: 22,
EndPos: 24,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 23,
StartPos: 22,
EndPos: 24,
},
Value: "b",
@ -464,7 +463,7 @@ func TestElseIfElseIfElse(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 27,
StartPos: 26,
EndPos: 28,
},
Stmts: []node.Node{},
@ -475,28 +474,28 @@ func TestElseIfElseIfElse(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 30,
StartPos: 29,
EndPos: 52,
},
Stmt: &stmt.If{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 35,
StartPos: 34,
EndPos: 52,
},
Cond: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 39,
StartPos: 38,
EndPos: 40,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 39,
StartPos: 38,
EndPos: 40,
},
Value: "c",
@ -506,7 +505,7 @@ func TestElseIfElseIfElse(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 43,
StartPos: 42,
EndPos: 44,
},
Stmts: []node.Node{},
@ -515,14 +514,14 @@ func TestElseIfElseIfElse(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 46,
StartPos: 45,
EndPos: 52,
},
Stmt: &stmt.StmtList{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 51,
StartPos: 50,
EndPos: 52,
},
Stmts: []node.Node{},
@ -534,12 +533,12 @@ func TestElseIfElseIfElse(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@ -1,7 +1,6 @@
package stmt_test
import (
"bytes"
"testing"
"gotest.tools/assert"
@ -20,7 +19,7 @@ func TestInlineHtml(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 17,
},
Stmts: []node.Node{
@ -28,7 +27,7 @@ func TestInlineHtml(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 5,
},
},
@ -36,20 +35,20 @@ func TestInlineHtml(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 7,
StartPos: 5,
EndPos: 17,
},
Value: "<div></div>",
Value: " <div></div>",
},
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@ -1,7 +1,6 @@
package stmt_test
import (
"bytes"
"testing"
"gotest.tools/assert"
@ -22,7 +21,7 @@ func TestInterface(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 19,
},
Stmts: []node.Node{
@ -30,7 +29,7 @@ func TestInterface(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 19,
},
PhpDocComment: "",
@ -38,7 +37,7 @@ func TestInterface(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 14,
StartPos: 13,
EndPos: 16,
},
Value: "Foo",
@ -48,12 +47,12 @@ func TestInterface(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -66,7 +65,7 @@ func TestInterfaceExtend(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 31,
},
Stmts: []node.Node{
@ -74,7 +73,7 @@ func TestInterfaceExtend(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 31,
},
PhpDocComment: "",
@ -82,7 +81,7 @@ func TestInterfaceExtend(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 14,
StartPos: 13,
EndPos: 16,
},
Value: "Foo",
@ -91,7 +90,7 @@ func TestInterfaceExtend(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 18,
StartPos: 17,
EndPos: 28,
},
InterfaceNames: []node.Node{
@ -99,7 +98,7 @@ func TestInterfaceExtend(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 26,
StartPos: 25,
EndPos: 28,
},
Parts: []node.Node{
@ -107,7 +106,7 @@ func TestInterfaceExtend(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 26,
StartPos: 25,
EndPos: 28,
},
Value: "Bar",
@ -121,12 +120,12 @@ func TestInterfaceExtend(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -139,7 +138,7 @@ func TestInterfaceExtends(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 36,
},
Stmts: []node.Node{
@ -147,7 +146,7 @@ func TestInterfaceExtends(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 36,
},
PhpDocComment: "",
@ -155,7 +154,7 @@ func TestInterfaceExtends(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 14,
StartPos: 13,
EndPos: 16,
},
Value: "Foo",
@ -164,7 +163,7 @@ func TestInterfaceExtends(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 18,
StartPos: 17,
EndPos: 33,
},
InterfaceNames: []node.Node{
@ -172,7 +171,7 @@ func TestInterfaceExtends(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 26,
StartPos: 25,
EndPos: 28,
},
Parts: []node.Node{
@ -180,7 +179,7 @@ func TestInterfaceExtends(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 26,
StartPos: 25,
EndPos: 28,
},
Value: "Bar",
@ -191,7 +190,7 @@ func TestInterfaceExtends(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 31,
StartPos: 30,
EndPos: 33,
},
Parts: []node.Node{
@ -199,7 +198,7 @@ func TestInterfaceExtends(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 31,
StartPos: 30,
EndPos: 33,
},
Value: "Baz",
@ -213,12 +212,12 @@ func TestInterfaceExtends(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@ -1,7 +1,6 @@
package stmt_test
import (
"bytes"
"testing"
"gotest.tools/assert"
@ -22,7 +21,7 @@ func TestNamespace(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 17,
},
Stmts: []node.Node{
@ -30,14 +29,14 @@ func TestNamespace(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 17,
},
NamespaceName: &name.Name{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 14,
StartPos: 13,
EndPos: 16,
},
Parts: []node.Node{
@ -45,7 +44,7 @@ func TestNamespace(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 14,
StartPos: 13,
EndPos: 16,
},
Value: "Foo",
@ -56,12 +55,12 @@ func TestNamespace(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -74,7 +73,7 @@ func TestNamespaceStmts(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 19,
},
Stmts: []node.Node{
@ -82,14 +81,14 @@ func TestNamespaceStmts(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 19,
},
NamespaceName: &name.Name{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 14,
StartPos: 13,
EndPos: 16,
},
Parts: []node.Node{
@ -97,7 +96,7 @@ func TestNamespaceStmts(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 14,
StartPos: 13,
EndPos: 16,
},
Value: "Foo",
@ -109,12 +108,12 @@ func TestNamespaceStmts(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -127,7 +126,7 @@ func TestAnonymousNamespace(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 15,
},
Stmts: []node.Node{
@ -135,7 +134,7 @@ func TestAnonymousNamespace(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 15,
},
Stmts: []node.Node{},
@ -143,12 +142,12 @@ func TestAnonymousNamespace(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@ -1,12 +1,12 @@
package stmt_test
import (
"bytes"
"testing"
"gotest.tools/assert"
"github.com/z7zmey/php-parser/node/expr"
"github.com/z7zmey/php-parser/node/name"
"github.com/z7zmey/php-parser/node/scalar"
"github.com/z7zmey/php-parser/position"
@ -23,7 +23,7 @@ func TestProperty(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 22,
},
Stmts: []node.Node{
@ -31,7 +31,7 @@ func TestProperty(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 22,
},
PhpDocComment: "",
@ -39,7 +39,7 @@ func TestProperty(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
StartPos: 9,
EndPos: 12,
},
Value: "foo",
@ -49,7 +49,7 @@ func TestProperty(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 15,
StartPos: 14,
EndPos: 21,
},
Modifiers: []node.Node{
@ -57,7 +57,7 @@ func TestProperty(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 15,
StartPos: 14,
EndPos: 17,
},
Value: "var",
@ -68,7 +68,7 @@ func TestProperty(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 19,
StartPos: 18,
EndPos: 20,
},
PhpDocComment: "",
@ -76,14 +76,14 @@ func TestProperty(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 19,
StartPos: 18,
EndPos: 20,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 19,
StartPos: 18,
EndPos: 20,
},
Value: "a",
@ -97,12 +97,12 @@ func TestProperty(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -115,7 +115,7 @@ func TestProperties(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 40,
},
Stmts: []node.Node{
@ -123,7 +123,7 @@ func TestProperties(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 40,
},
PhpDocComment: "",
@ -131,7 +131,7 @@ func TestProperties(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
StartPos: 9,
EndPos: 12,
},
Value: "foo",
@ -141,7 +141,7 @@ func TestProperties(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 15,
StartPos: 14,
EndPos: 39,
},
Modifiers: []node.Node{
@ -149,7 +149,7 @@ func TestProperties(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 15,
StartPos: 14,
EndPos: 20,
},
Value: "public",
@ -158,7 +158,7 @@ func TestProperties(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 22,
StartPos: 21,
EndPos: 27,
},
Value: "static",
@ -169,7 +169,7 @@ func TestProperties(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 29,
StartPos: 28,
EndPos: 30,
},
PhpDocComment: "",
@ -177,14 +177,14 @@ func TestProperties(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 29,
StartPos: 28,
EndPos: 30,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 29,
StartPos: 28,
EndPos: 30,
},
Value: "a",
@ -195,7 +195,7 @@ func TestProperties(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 33,
StartPos: 32,
EndPos: 38,
},
PhpDocComment: "",
@ -203,14 +203,14 @@ func TestProperties(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 33,
StartPos: 32,
EndPos: 34,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 33,
StartPos: 32,
EndPos: 34,
},
Value: "b",
@ -220,7 +220,7 @@ func TestProperties(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 38,
StartPos: 37,
EndPos: 38,
},
Value: "1",
@ -233,12 +233,12 @@ func TestProperties(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -251,7 +251,7 @@ func TestProperties2(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 40,
},
Stmts: []node.Node{
@ -259,7 +259,7 @@ func TestProperties2(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 40,
},
PhpDocComment: "",
@ -267,7 +267,7 @@ func TestProperties2(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
StartPos: 9,
EndPos: 12,
},
Value: "foo",
@ -277,7 +277,7 @@ func TestProperties2(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 15,
StartPos: 14,
EndPos: 39,
},
Modifiers: []node.Node{
@ -285,7 +285,7 @@ func TestProperties2(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 15,
StartPos: 14,
EndPos: 20,
},
Value: "public",
@ -294,7 +294,7 @@ func TestProperties2(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 22,
StartPos: 21,
EndPos: 27,
},
Value: "static",
@ -305,7 +305,7 @@ func TestProperties2(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 29,
StartPos: 28,
EndPos: 34,
},
PhpDocComment: "",
@ -313,14 +313,14 @@ func TestProperties2(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 29,
StartPos: 28,
EndPos: 30,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 29,
StartPos: 28,
EndPos: 30,
},
Value: "a",
@ -330,7 +330,7 @@ func TestProperties2(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 34,
StartPos: 33,
EndPos: 34,
},
Value: "1",
@ -340,7 +340,7 @@ func TestProperties2(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 37,
StartPos: 36,
EndPos: 38,
},
PhpDocComment: "",
@ -348,14 +348,14 @@ func TestProperties2(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 37,
StartPos: 36,
EndPos: 38,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 37,
StartPos: 36,
EndPos: 38,
},
Value: "b",
@ -369,13 +369,119 @@ func TestProperties2(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
}
func TestPropertyType(t *testing.T) {
src := `<? class foo {var bar $a;}`
expected := &node.Root{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 3,
EndPos: 26,
},
Stmts: []node.Node{
&stmt.Class{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 3,
EndPos: 26,
},
PhpDocComment: "",
ClassName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 9,
EndPos: 12,
},
Value: "foo",
},
Stmts: []node.Node{
&stmt.PropertyList{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 14,
EndPos: 25,
},
Modifiers: []node.Node{
&node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 14,
EndPos: 17,
},
Value: "var",
},
},
Type: &name.Name{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 18,
EndPos: 21,
},
Parts: []node.Node{
&name.NamePart{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 18,
EndPos: 21,
},
Value: "bar",
},
},
},
Properties: []node.Node{
&stmt.Property{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 22,
EndPos: 24,
},
PhpDocComment: "",
Variable: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 22,
EndPos: 24,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 22,
EndPos: 24,
},
Value: "a",
},
},
},
},
},
},
},
},
}
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
}

View File

@ -1,7 +1,6 @@
package stmt_test
import (
"bytes"
"testing"
"gotest.tools/assert"
@ -22,7 +21,7 @@ func TestStaticVar(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 13,
},
Stmts: []node.Node{
@ -30,7 +29,7 @@ func TestStaticVar(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 13,
},
Vars: []node.Node{
@ -38,21 +37,21 @@ func TestStaticVar(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 11,
StartPos: 10,
EndPos: 12,
},
Variable: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 11,
StartPos: 10,
EndPos: 12,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 11,
StartPos: 10,
EndPos: 12,
},
Value: "a",
@ -64,12 +63,12 @@ func TestStaticVar(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -82,7 +81,7 @@ func TestStaticVars(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 21,
},
Stmts: []node.Node{
@ -90,7 +89,7 @@ func TestStaticVars(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 21,
},
Vars: []node.Node{
@ -98,21 +97,21 @@ func TestStaticVars(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 11,
StartPos: 10,
EndPos: 12,
},
Variable: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 11,
StartPos: 10,
EndPos: 12,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 11,
StartPos: 10,
EndPos: 12,
},
Value: "a",
@ -123,21 +122,21 @@ func TestStaticVars(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 15,
StartPos: 14,
EndPos: 20,
},
Variable: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 15,
StartPos: 14,
EndPos: 16,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 15,
StartPos: 14,
EndPos: 16,
},
Value: "b",
@ -147,7 +146,7 @@ func TestStaticVars(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 20,
StartPos: 19,
EndPos: 20,
},
Value: "1",
@ -158,12 +157,12 @@ func TestStaticVars(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -176,7 +175,7 @@ func TestStaticVars2(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 21,
},
Stmts: []node.Node{
@ -184,7 +183,7 @@ func TestStaticVars2(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 21,
},
Vars: []node.Node{
@ -192,21 +191,21 @@ func TestStaticVars2(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 11,
StartPos: 10,
EndPos: 16,
},
Variable: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 11,
StartPos: 10,
EndPos: 12,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 11,
StartPos: 10,
EndPos: 12,
},
Value: "a",
@ -216,7 +215,7 @@ func TestStaticVars2(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 16,
StartPos: 15,
EndPos: 16,
},
Value: "1",
@ -226,21 +225,21 @@ func TestStaticVars2(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 19,
StartPos: 18,
EndPos: 20,
},
Variable: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 19,
StartPos: 18,
EndPos: 20,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 19,
StartPos: 18,
EndPos: 20,
},
Value: "b",
@ -252,12 +251,12 @@ func TestStaticVars2(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@ -1,7 +1,6 @@
package stmt_test
import (
"bytes"
"testing"
"gotest.tools/assert"
@ -28,7 +27,7 @@ func TestAltSwitch(t *testing.T) {
Position: &position.Position{
StartLine: 2,
EndLine: 6,
StartPos: 7,
StartPos: 6,
EndPos: 65,
},
Stmts: []node.Node{
@ -36,14 +35,116 @@ func TestAltSwitch(t *testing.T) {
Position: &position.Position{
StartLine: 2,
EndLine: 6,
StartPos: 7,
StartPos: 6,
EndPos: 65,
},
Cond: &scalar.Lnumber{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 15,
StartPos: 14,
EndPos: 15,
},
Value: "1",
},
CaseList: &stmt.CaseList{
Position: &position.Position{
StartLine: 3,
EndLine: -1,
StartPos: 22,
EndPos: -1,
},
Cases: []node.Node{
&stmt.Case{
Position: &position.Position{
StartLine: 3,
EndLine: -1,
StartPos: 22,
EndPos: -1,
},
Cond: &scalar.Lnumber{
Position: &position.Position{
StartLine: 3,
EndLine: 3,
StartPos: 27,
EndPos: 28,
},
Value: "1",
},
Stmts: []node.Node{},
},
&stmt.Default{
Position: &position.Position{
StartLine: 4,
EndLine: -1,
StartPos: 33,
EndPos: -1,
},
Stmts: []node.Node{},
},
&stmt.Case{
Position: &position.Position{
StartLine: 5,
EndLine: -1,
StartPos: 45,
EndPos: -1,
},
Cond: &scalar.Lnumber{
Position: &position.Position{
StartLine: 5,
EndLine: 5,
StartPos: 50,
EndPos: 51,
},
Value: "2",
},
Stmts: []node.Node{},
},
},
},
},
},
}
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
}
func TestAltSwitchSemicolon(t *testing.T) {
src := `<?
switch (1) :;
case 1;
case 2;
endswitch;
`
expected := &node.Root{
Position: &position.Position{
StartLine: 2,
EndLine: 5,
StartPos: 6,
EndPos: 54,
},
Stmts: []node.Node{
&stmt.AltSwitch{
Position: &position.Position{
StartLine: 2,
EndLine: 5,
StartPos: 6,
EndPos: 54,
},
Cond: &scalar.Lnumber{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 14,
EndPos: 15,
},
Value: "1",
@ -68,108 +169,6 @@ func TestAltSwitch(t *testing.T) {
StartLine: 3,
EndLine: 3,
StartPos: 28,
EndPos: 28,
},
Value: "1",
},
Stmts: []node.Node{},
},
&stmt.Default{
Position: &position.Position{
StartLine: 4,
EndLine: -1,
StartPos: 34,
EndPos: -1,
},
Stmts: []node.Node{},
},
&stmt.Case{
Position: &position.Position{
StartLine: 5,
EndLine: -1,
StartPos: 46,
EndPos: -1,
},
Cond: &scalar.Lnumber{
Position: &position.Position{
StartLine: 5,
EndLine: 5,
StartPos: 51,
EndPos: 51,
},
Value: "2",
},
Stmts: []node.Node{},
},
},
},
},
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
}
func TestAltSwitchSemicolon(t *testing.T) {
src := `<?
switch (1) :;
case 1;
case 2;
endswitch;
`
expected := &node.Root{
Position: &position.Position{
StartLine: 2,
EndLine: 5,
StartPos: 7,
EndPos: 54,
},
Stmts: []node.Node{
&stmt.AltSwitch{
Position: &position.Position{
StartLine: 2,
EndLine: 5,
StartPos: 7,
EndPos: 54,
},
Cond: &scalar.Lnumber{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 15,
EndPos: 15,
},
Value: "1",
},
CaseList: &stmt.CaseList{
Position: &position.Position{
StartLine: 3,
EndLine: -1,
StartPos: 24,
EndPos: -1,
},
Cases: []node.Node{
&stmt.Case{
Position: &position.Position{
StartLine: 3,
EndLine: -1,
StartPos: 24,
EndPos: -1,
},
Cond: &scalar.Lnumber{
Position: &position.Position{
StartLine: 3,
EndLine: 3,
StartPos: 29,
EndPos: 29,
},
Value: "1",
@ -180,14 +179,14 @@ func TestAltSwitchSemicolon(t *testing.T) {
Position: &position.Position{
StartLine: 4,
EndLine: -1,
StartPos: 35,
StartPos: 34,
EndPos: -1,
},
Cond: &scalar.Lnumber{
Position: &position.Position{
StartLine: 4,
EndLine: 4,
StartPos: 40,
StartPos: 39,
EndPos: 40,
},
Value: "2",
@ -200,12 +199,12 @@ func TestAltSwitchSemicolon(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -223,7 +222,7 @@ func TestSwitch(t *testing.T) {
Position: &position.Position{
StartLine: 2,
EndLine: 5,
StartPos: 7,
StartPos: 6,
EndPos: 58,
},
Stmts: []node.Node{
@ -231,14 +230,14 @@ func TestSwitch(t *testing.T) {
Position: &position.Position{
StartLine: 2,
EndLine: 5,
StartPos: 7,
StartPos: 6,
EndPos: 58,
},
Cond: &scalar.Lnumber{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 15,
StartPos: 14,
EndPos: 15,
},
Value: "1",
@ -247,7 +246,7 @@ func TestSwitch(t *testing.T) {
Position: &position.Position{
StartLine: 2,
EndLine: 5,
StartPos: 18,
StartPos: 17,
EndPos: 58,
},
Cases: []node.Node{
@ -255,14 +254,14 @@ func TestSwitch(t *testing.T) {
Position: &position.Position{
StartLine: 3,
EndLine: 3,
StartPos: 23,
StartPos: 22,
EndPos: 36,
},
Cond: &scalar.Lnumber{
Position: &position.Position{
StartLine: 3,
EndLine: 3,
StartPos: 28,
StartPos: 27,
EndPos: 28,
},
Value: "1",
@ -272,7 +271,7 @@ func TestSwitch(t *testing.T) {
Position: &position.Position{
StartLine: 3,
EndLine: 3,
StartPos: 31,
StartPos: 30,
EndPos: 36,
},
},
@ -282,14 +281,14 @@ func TestSwitch(t *testing.T) {
Position: &position.Position{
StartLine: 4,
EndLine: 4,
StartPos: 41,
StartPos: 40,
EndPos: 54,
},
Cond: &scalar.Lnumber{
Position: &position.Position{
StartLine: 4,
EndLine: 4,
StartPos: 46,
StartPos: 45,
EndPos: 46,
},
Value: "2",
@ -299,7 +298,7 @@ func TestSwitch(t *testing.T) {
Position: &position.Position{
StartLine: 4,
EndLine: 4,
StartPos: 49,
StartPos: 48,
EndPos: 54,
},
},
@ -311,12 +310,12 @@ func TestSwitch(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -334,7 +333,7 @@ func TestSwitchSemicolon(t *testing.T) {
Position: &position.Position{
StartLine: 2,
EndLine: 5,
StartPos: 7,
StartPos: 6,
EndPos: 59,
},
Stmts: []node.Node{
@ -342,14 +341,14 @@ func TestSwitchSemicolon(t *testing.T) {
Position: &position.Position{
StartLine: 2,
EndLine: 5,
StartPos: 7,
StartPos: 6,
EndPos: 59,
},
Cond: &scalar.Lnumber{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 15,
StartPos: 14,
EndPos: 15,
},
Value: "1",
@ -358,7 +357,7 @@ func TestSwitchSemicolon(t *testing.T) {
Position: &position.Position{
StartLine: 2,
EndLine: 5,
StartPos: 18,
StartPos: 17,
EndPos: 59,
},
Cases: []node.Node{
@ -366,14 +365,14 @@ func TestSwitchSemicolon(t *testing.T) {
Position: &position.Position{
StartLine: 3,
EndLine: 3,
StartPos: 24,
StartPos: 23,
EndPos: 37,
},
Cond: &scalar.Lnumber{
Position: &position.Position{
StartLine: 3,
EndLine: 3,
StartPos: 29,
StartPos: 28,
EndPos: 29,
},
Value: "1",
@ -383,7 +382,7 @@ func TestSwitchSemicolon(t *testing.T) {
Position: &position.Position{
StartLine: 3,
EndLine: 3,
StartPos: 32,
StartPos: 31,
EndPos: 37,
},
},
@ -393,14 +392,14 @@ func TestSwitchSemicolon(t *testing.T) {
Position: &position.Position{
StartLine: 4,
EndLine: 4,
StartPos: 42,
StartPos: 41,
EndPos: 55,
},
Cond: &scalar.Lnumber{
Position: &position.Position{
StartLine: 4,
EndLine: 4,
StartPos: 47,
StartPos: 46,
EndPos: 47,
},
Value: "2",
@ -410,7 +409,7 @@ func TestSwitchSemicolon(t *testing.T) {
Position: &position.Position{
StartLine: 4,
EndLine: 4,
StartPos: 50,
StartPos: 49,
EndPos: 55,
},
},
@ -422,12 +421,12 @@ func TestSwitchSemicolon(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@ -1,7 +1,6 @@
package stmt_test
import (
"bytes"
"testing"
"gotest.tools/assert"
@ -21,7 +20,7 @@ func TestThrow(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 12,
},
Stmts: []node.Node{
@ -29,21 +28,21 @@ func TestThrow(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 12,
},
Expr: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
StartPos: 9,
EndPos: 11,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
StartPos: 9,
EndPos: 11,
},
Value: "e",
@ -53,12 +52,12 @@ func TestThrow(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@ -1,7 +1,6 @@
package stmt_test
import (
"bytes"
"testing"
"gotest.tools/assert"
@ -20,7 +19,7 @@ func TestTrait(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 15,
},
Stmts: []node.Node{
@ -28,7 +27,7 @@ func TestTrait(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 15,
},
PhpDocComment: "",
@ -36,7 +35,7 @@ func TestTrait(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
StartPos: 9,
EndPos: 12,
},
Value: "Foo",
@ -46,12 +45,12 @@ func TestTrait(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@ -1,7 +1,6 @@
package stmt_test
import (
"bytes"
"testing"
"gotest.tools/assert"
@ -22,7 +21,7 @@ func TestTraitUse(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 25,
},
Stmts: []node.Node{
@ -30,7 +29,7 @@ func TestTraitUse(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 25,
},
PhpDocComment: "",
@ -38,7 +37,7 @@ func TestTraitUse(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
StartPos: 9,
EndPos: 12,
},
Value: "Foo",
@ -48,7 +47,7 @@ func TestTraitUse(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 16,
StartPos: 15,
EndPos: 23,
},
Traits: []node.Node{
@ -56,7 +55,7 @@ func TestTraitUse(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 20,
StartPos: 19,
EndPos: 22,
},
Parts: []node.Node{
@ -64,7 +63,7 @@ func TestTraitUse(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 20,
StartPos: 19,
EndPos: 22,
},
Value: "Bar",
@ -76,7 +75,7 @@ func TestTraitUse(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 23,
StartPos: 22,
EndPos: 23,
},
},
@ -86,12 +85,12 @@ func TestTraitUse(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -104,7 +103,7 @@ func TestTraitsUse(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 30,
},
Stmts: []node.Node{
@ -112,7 +111,7 @@ func TestTraitsUse(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 30,
},
PhpDocComment: "",
@ -120,7 +119,7 @@ func TestTraitsUse(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
StartPos: 9,
EndPos: 12,
},
Value: "Foo",
@ -130,7 +129,7 @@ func TestTraitsUse(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 16,
StartPos: 15,
EndPos: 28,
},
Traits: []node.Node{
@ -138,7 +137,7 @@ func TestTraitsUse(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 20,
StartPos: 19,
EndPos: 22,
},
Parts: []node.Node{
@ -146,7 +145,7 @@ func TestTraitsUse(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 20,
StartPos: 19,
EndPos: 22,
},
Value: "Bar",
@ -157,7 +156,7 @@ func TestTraitsUse(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 25,
StartPos: 24,
EndPos: 27,
},
Parts: []node.Node{
@ -165,7 +164,7 @@ func TestTraitsUse(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 25,
StartPos: 24,
EndPos: 27,
},
Value: "Baz",
@ -177,7 +176,7 @@ func TestTraitsUse(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 28,
StartPos: 27,
EndPos: 28,
},
},
@ -187,12 +186,12 @@ func TestTraitsUse(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -205,7 +204,7 @@ func TestTraitsUseEmptyAdaptations(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 32,
},
Stmts: []node.Node{
@ -213,7 +212,7 @@ func TestTraitsUseEmptyAdaptations(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 32,
},
PhpDocComment: "",
@ -221,7 +220,7 @@ func TestTraitsUseEmptyAdaptations(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
StartPos: 9,
EndPos: 12,
},
Value: "Foo",
@ -231,7 +230,7 @@ func TestTraitsUseEmptyAdaptations(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 16,
StartPos: 15,
EndPos: 30,
},
Traits: []node.Node{
@ -239,7 +238,7 @@ func TestTraitsUseEmptyAdaptations(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 20,
StartPos: 19,
EndPos: 22,
},
Parts: []node.Node{
@ -247,7 +246,7 @@ func TestTraitsUseEmptyAdaptations(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 20,
StartPos: 19,
EndPos: 22,
},
Value: "Bar",
@ -258,7 +257,7 @@ func TestTraitsUseEmptyAdaptations(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 25,
StartPos: 24,
EndPos: 27,
},
Parts: []node.Node{
@ -266,7 +265,7 @@ func TestTraitsUseEmptyAdaptations(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 25,
StartPos: 24,
EndPos: 27,
},
Value: "Baz",
@ -278,7 +277,7 @@ func TestTraitsUseEmptyAdaptations(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 29,
StartPos: 28,
EndPos: 30,
},
},
@ -288,12 +287,12 @@ func TestTraitsUseEmptyAdaptations(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -306,7 +305,7 @@ func TestTraitsUseModifier(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 48,
},
Stmts: []node.Node{
@ -314,7 +313,7 @@ func TestTraitsUseModifier(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 48,
},
PhpDocComment: "",
@ -322,7 +321,7 @@ func TestTraitsUseModifier(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
StartPos: 9,
EndPos: 12,
},
Value: "Foo",
@ -332,7 +331,7 @@ func TestTraitsUseModifier(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 16,
StartPos: 15,
EndPos: 46,
},
Traits: []node.Node{
@ -340,7 +339,7 @@ func TestTraitsUseModifier(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 20,
StartPos: 19,
EndPos: 22,
},
Parts: []node.Node{
@ -348,7 +347,7 @@ func TestTraitsUseModifier(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 20,
StartPos: 19,
EndPos: 22,
},
Value: "Bar",
@ -359,7 +358,7 @@ func TestTraitsUseModifier(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 25,
StartPos: 24,
EndPos: 27,
},
Parts: []node.Node{
@ -367,7 +366,7 @@ func TestTraitsUseModifier(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 25,
StartPos: 24,
EndPos: 27,
},
Value: "Baz",
@ -379,7 +378,7 @@ func TestTraitsUseModifier(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 29,
StartPos: 28,
EndPos: 46,
},
Adaptations: []node.Node{
@ -387,21 +386,21 @@ func TestTraitsUseModifier(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 31,
StartPos: 30,
EndPos: 43,
},
Ref: &stmt.TraitMethodRef{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 31,
StartPos: 30,
EndPos: 33,
},
Method: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 31,
StartPos: 30,
EndPos: 33,
},
Value: "one",
@ -411,7 +410,7 @@ func TestTraitsUseModifier(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 38,
StartPos: 37,
EndPos: 43,
},
Value: "public",
@ -425,12 +424,12 @@ func TestTraitsUseModifier(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -443,7 +442,7 @@ func TestTraitsUseAliasModifier(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 52,
},
Stmts: []node.Node{
@ -451,7 +450,7 @@ func TestTraitsUseAliasModifier(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 52,
},
PhpDocComment: "",
@ -459,7 +458,7 @@ func TestTraitsUseAliasModifier(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
StartPos: 9,
EndPos: 12,
},
Value: "Foo",
@ -469,7 +468,7 @@ func TestTraitsUseAliasModifier(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 16,
StartPos: 15,
EndPos: 50,
},
Traits: []node.Node{
@ -477,7 +476,7 @@ func TestTraitsUseAliasModifier(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 20,
StartPos: 19,
EndPos: 22,
},
Parts: []node.Node{
@ -485,7 +484,7 @@ func TestTraitsUseAliasModifier(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 20,
StartPos: 19,
EndPos: 22,
},
Value: "Bar",
@ -496,7 +495,7 @@ func TestTraitsUseAliasModifier(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 25,
StartPos: 24,
EndPos: 27,
},
Parts: []node.Node{
@ -504,7 +503,7 @@ func TestTraitsUseAliasModifier(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 25,
StartPos: 24,
EndPos: 27,
},
Value: "Baz",
@ -516,7 +515,7 @@ func TestTraitsUseAliasModifier(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 29,
StartPos: 28,
EndPos: 50,
},
Adaptations: []node.Node{
@ -524,21 +523,21 @@ func TestTraitsUseAliasModifier(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 31,
StartPos: 30,
EndPos: 47,
},
Ref: &stmt.TraitMethodRef{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 31,
StartPos: 30,
EndPos: 33,
},
Method: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 31,
StartPos: 30,
EndPos: 33,
},
Value: "one",
@ -548,7 +547,7 @@ func TestTraitsUseAliasModifier(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 38,
StartPos: 37,
EndPos: 43,
},
Value: "public",
@ -557,7 +556,7 @@ func TestTraitsUseAliasModifier(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 45,
StartPos: 44,
EndPos: 47,
},
Value: "two",
@ -571,12 +570,12 @@ func TestTraitsUseAliasModifier(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -589,7 +588,7 @@ func TestTraitsUseAdaptions(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 80,
},
Stmts: []node.Node{
@ -597,7 +596,7 @@ func TestTraitsUseAdaptions(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 80,
},
PhpDocComment: "",
@ -605,7 +604,7 @@ func TestTraitsUseAdaptions(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
StartPos: 9,
EndPos: 12,
},
Value: "Foo",
@ -615,7 +614,7 @@ func TestTraitsUseAdaptions(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 16,
StartPos: 15,
EndPos: 78,
},
Traits: []node.Node{
@ -623,7 +622,7 @@ func TestTraitsUseAdaptions(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 20,
StartPos: 19,
EndPos: 22,
},
Parts: []node.Node{
@ -631,7 +630,7 @@ func TestTraitsUseAdaptions(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 20,
StartPos: 19,
EndPos: 22,
},
Value: "Bar",
@ -642,7 +641,7 @@ func TestTraitsUseAdaptions(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 25,
StartPos: 24,
EndPos: 27,
},
Parts: []node.Node{
@ -650,7 +649,7 @@ func TestTraitsUseAdaptions(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 25,
StartPos: 24,
EndPos: 27,
},
Value: "Baz",
@ -662,7 +661,7 @@ func TestTraitsUseAdaptions(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 29,
StartPos: 28,
EndPos: 78,
},
Adaptations: []node.Node{
@ -670,21 +669,21 @@ func TestTraitsUseAdaptions(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 31,
StartPos: 30,
EndPos: 58,
},
Ref: &stmt.TraitMethodRef{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 31,
StartPos: 30,
EndPos: 38,
},
Trait: &name.Name{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 31,
StartPos: 30,
EndPos: 33,
},
Parts: []node.Node{
@ -692,7 +691,7 @@ func TestTraitsUseAdaptions(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 31,
StartPos: 30,
EndPos: 33,
},
Value: "Bar",
@ -703,7 +702,7 @@ func TestTraitsUseAdaptions(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 36,
StartPos: 35,
EndPos: 38,
},
Value: "one",
@ -714,7 +713,7 @@ func TestTraitsUseAdaptions(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 50,
StartPos: 49,
EndPos: 52,
},
Parts: []node.Node{
@ -722,7 +721,7 @@ func TestTraitsUseAdaptions(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 50,
StartPos: 49,
EndPos: 52,
},
Value: "Baz",
@ -733,7 +732,7 @@ func TestTraitsUseAdaptions(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 55,
StartPos: 54,
EndPos: 58,
},
Parts: []node.Node{
@ -741,7 +740,7 @@ func TestTraitsUseAdaptions(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 55,
StartPos: 54,
EndPos: 58,
},
Value: "Quux",
@ -754,21 +753,21 @@ func TestTraitsUseAdaptions(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 61,
StartPos: 60,
EndPos: 75,
},
Ref: &stmt.TraitMethodRef{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 61,
StartPos: 60,
EndPos: 68,
},
Trait: &name.Name{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 61,
StartPos: 60,
EndPos: 63,
},
Parts: []node.Node{
@ -776,7 +775,7 @@ func TestTraitsUseAdaptions(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 61,
StartPos: 60,
EndPos: 63,
},
Value: "Baz",
@ -787,7 +786,7 @@ func TestTraitsUseAdaptions(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 66,
StartPos: 65,
EndPos: 68,
},
Value: "one",
@ -797,7 +796,7 @@ func TestTraitsUseAdaptions(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 73,
StartPos: 72,
EndPos: 75,
},
Value: "two",
@ -811,12 +810,12 @@ func TestTraitsUseAdaptions(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@ -1,7 +1,6 @@
package stmt_test
import (
"bytes"
"testing"
"gotest.tools/assert"
@ -25,7 +24,7 @@ func TestTry(t *testing.T) {
Position: &position.Position{
StartLine: 2,
EndLine: -1,
StartPos: 7,
StartPos: 6,
EndPos: -1,
},
Stmts: []node.Node{
@ -33,7 +32,7 @@ func TestTry(t *testing.T) {
Position: &position.Position{
StartLine: 2,
EndLine: -1,
StartPos: 7,
StartPos: 6,
EndPos: -1,
},
Stmts: []node.Node{},
@ -42,12 +41,12 @@ func TestTry(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -62,7 +61,7 @@ func TestTryCatch(t *testing.T) {
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 7,
StartPos: 6,
EndPos: 36,
},
Stmts: []node.Node{
@ -70,7 +69,7 @@ func TestTryCatch(t *testing.T) {
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 7,
StartPos: 6,
EndPos: 36,
},
Stmts: []node.Node{},
@ -79,7 +78,7 @@ func TestTryCatch(t *testing.T) {
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 14,
StartPos: 13,
EndPos: 36,
},
Types: []node.Node{
@ -87,7 +86,7 @@ func TestTryCatch(t *testing.T) {
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 21,
StartPos: 20,
EndPos: 29,
},
Parts: []node.Node{
@ -95,7 +94,7 @@ func TestTryCatch(t *testing.T) {
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 21,
StartPos: 20,
EndPos: 29,
},
Value: "Exception",
@ -107,14 +106,14 @@ func TestTryCatch(t *testing.T) {
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 31,
StartPos: 30,
EndPos: 32,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 31,
StartPos: 30,
EndPos: 32,
},
Value: "e",
@ -127,12 +126,12 @@ func TestTryCatch(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -147,7 +146,7 @@ func TestPhp7TryCatch(t *testing.T) {
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 7,
StartPos: 6,
EndPos: 53,
},
Stmts: []node.Node{
@ -155,7 +154,7 @@ func TestPhp7TryCatch(t *testing.T) {
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 7,
StartPos: 6,
EndPos: 53,
},
Stmts: []node.Node{},
@ -164,7 +163,7 @@ func TestPhp7TryCatch(t *testing.T) {
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 14,
StartPos: 13,
EndPos: 53,
},
Types: []node.Node{
@ -172,7 +171,7 @@ func TestPhp7TryCatch(t *testing.T) {
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 21,
StartPos: 20,
EndPos: 29,
},
Parts: []node.Node{
@ -180,7 +179,7 @@ func TestPhp7TryCatch(t *testing.T) {
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 21,
StartPos: 20,
EndPos: 29,
},
Value: "Exception",
@ -191,7 +190,7 @@ func TestPhp7TryCatch(t *testing.T) {
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 31,
StartPos: 30,
EndPos: 46,
},
Parts: []node.Node{
@ -199,7 +198,7 @@ func TestPhp7TryCatch(t *testing.T) {
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 31,
StartPos: 30,
EndPos: 46,
},
Value: "RuntimeException",
@ -211,14 +210,14 @@ func TestPhp7TryCatch(t *testing.T) {
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 48,
StartPos: 47,
EndPos: 49,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 48,
StartPos: 47,
EndPos: 49,
},
Value: "e",
@ -231,7 +230,7 @@ func TestPhp7TryCatch(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -246,7 +245,7 @@ func TestTryCatchCatch(t *testing.T) {
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 7,
StartPos: 6,
EndPos: 67,
},
Stmts: []node.Node{
@ -254,7 +253,7 @@ func TestTryCatchCatch(t *testing.T) {
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 7,
StartPos: 6,
EndPos: 67,
},
Stmts: []node.Node{},
@ -263,7 +262,7 @@ func TestTryCatchCatch(t *testing.T) {
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 14,
StartPos: 13,
EndPos: 36,
},
Types: []node.Node{
@ -271,7 +270,7 @@ func TestTryCatchCatch(t *testing.T) {
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 21,
StartPos: 20,
EndPos: 29,
},
Parts: []node.Node{
@ -279,7 +278,7 @@ func TestTryCatchCatch(t *testing.T) {
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 21,
StartPos: 20,
EndPos: 29,
},
Value: "Exception",
@ -291,14 +290,14 @@ func TestTryCatchCatch(t *testing.T) {
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 31,
StartPos: 30,
EndPos: 32,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 31,
StartPos: 30,
EndPos: 32,
},
Value: "e",
@ -310,7 +309,7 @@ func TestTryCatchCatch(t *testing.T) {
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 38,
StartPos: 37,
EndPos: 67,
},
Types: []node.Node{
@ -318,7 +317,7 @@ func TestTryCatchCatch(t *testing.T) {
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 45,
StartPos: 44,
EndPos: 60,
},
Parts: []node.Node{
@ -326,7 +325,7 @@ func TestTryCatchCatch(t *testing.T) {
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 45,
StartPos: 44,
EndPos: 60,
},
Value: "RuntimeException",
@ -338,14 +337,14 @@ func TestTryCatchCatch(t *testing.T) {
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 62,
StartPos: 61,
EndPos: 63,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 62,
StartPos: 61,
EndPos: 63,
},
Value: "e",
@ -358,12 +357,12 @@ func TestTryCatchCatch(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -378,7 +377,7 @@ func TestTryCatchFinally(t *testing.T) {
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 7,
StartPos: 6,
EndPos: 47,
},
Stmts: []node.Node{
@ -386,7 +385,7 @@ func TestTryCatchFinally(t *testing.T) {
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 7,
StartPos: 6,
EndPos: 47,
},
Stmts: []node.Node{},
@ -395,7 +394,7 @@ func TestTryCatchFinally(t *testing.T) {
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 14,
StartPos: 13,
EndPos: 36,
},
Types: []node.Node{
@ -403,7 +402,7 @@ func TestTryCatchFinally(t *testing.T) {
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 21,
StartPos: 20,
EndPos: 29,
},
Parts: []node.Node{
@ -411,7 +410,7 @@ func TestTryCatchFinally(t *testing.T) {
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 21,
StartPos: 20,
EndPos: 29,
},
Value: "Exception",
@ -423,14 +422,14 @@ func TestTryCatchFinally(t *testing.T) {
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 31,
StartPos: 30,
EndPos: 32,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 31,
StartPos: 30,
EndPos: 32,
},
Value: "e",
@ -443,7 +442,7 @@ func TestTryCatchFinally(t *testing.T) {
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 38,
StartPos: 37,
EndPos: 47,
},
Stmts: []node.Node{},
@ -452,12 +451,12 @@ func TestTryCatchFinally(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -470,7 +469,7 @@ func TestTryCatchCatchCatch(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 107,
},
Stmts: []node.Node{
@ -478,7 +477,7 @@ func TestTryCatchCatchCatch(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 107,
},
Stmts: []node.Node{},
@ -487,7 +486,7 @@ func TestTryCatchCatchCatch(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 11,
StartPos: 10,
EndPos: 33,
},
Types: []node.Node{
@ -495,7 +494,7 @@ func TestTryCatchCatchCatch(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 18,
StartPos: 17,
EndPos: 26,
},
Parts: []node.Node{
@ -503,7 +502,7 @@ func TestTryCatchCatchCatch(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 18,
StartPos: 17,
EndPos: 26,
},
Value: "Exception",
@ -515,14 +514,14 @@ func TestTryCatchCatchCatch(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 28,
StartPos: 27,
EndPos: 29,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 28,
StartPos: 27,
EndPos: 29,
},
Value: "e",
@ -534,7 +533,7 @@ func TestTryCatchCatchCatch(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 35,
StartPos: 34,
EndPos: 65,
},
Types: []node.Node{
@ -542,7 +541,7 @@ func TestTryCatchCatchCatch(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 42,
StartPos: 41,
EndPos: 58,
},
Parts: []node.Node{
@ -550,7 +549,7 @@ func TestTryCatchCatchCatch(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 43,
StartPos: 42,
EndPos: 58,
},
Value: "RuntimeException",
@ -562,14 +561,14 @@ func TestTryCatchCatchCatch(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 60,
StartPos: 59,
EndPos: 61,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 60,
StartPos: 59,
EndPos: 61,
},
Value: "e",
@ -581,7 +580,7 @@ func TestTryCatchCatchCatch(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 67,
StartPos: 66,
EndPos: 107,
},
Types: []node.Node{
@ -589,7 +588,7 @@ func TestTryCatchCatchCatch(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 74,
StartPos: 73,
EndPos: 100,
},
Parts: []node.Node{
@ -597,7 +596,7 @@ func TestTryCatchCatchCatch(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 84,
StartPos: 83,
EndPos: 100,
},
Value: "AdditionException",
@ -609,14 +608,14 @@ func TestTryCatchCatchCatch(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 102,
StartPos: 101,
EndPos: 103,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 102,
StartPos: 101,
EndPos: 103,
},
Value: "e",
@ -629,12 +628,12 @@ func TestTryCatchCatchCatch(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

View File

@ -1,7 +1,6 @@
package stmt_test
import (
"bytes"
"testing"
"gotest.tools/assert"
@ -21,7 +20,7 @@ func TestUnset(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 13,
},
Stmts: []node.Node{
@ -29,7 +28,7 @@ func TestUnset(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 13,
},
Vars: []node.Node{
@ -37,14 +36,14 @@ func TestUnset(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
StartPos: 9,
EndPos: 11,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
StartPos: 9,
EndPos: 11,
},
Value: "a",
@ -55,12 +54,12 @@ func TestUnset(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -73,7 +72,7 @@ func TestUnsetVars(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 17,
},
Stmts: []node.Node{
@ -81,7 +80,7 @@ func TestUnsetVars(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 17,
},
Vars: []node.Node{
@ -89,14 +88,14 @@ func TestUnsetVars(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
StartPos: 9,
EndPos: 11,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
StartPos: 9,
EndPos: 11,
},
Value: "a",
@ -106,14 +105,14 @@ func TestUnsetVars(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 14,
StartPos: 13,
EndPos: 15,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 14,
StartPos: 13,
EndPos: 15,
},
Value: "b",
@ -124,12 +123,12 @@ func TestUnsetVars(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -142,7 +141,7 @@ func TestUnsetTrailingComma(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 18,
},
Stmts: []node.Node{
@ -150,7 +149,7 @@ func TestUnsetTrailingComma(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 18,
},
Vars: []node.Node{
@ -158,14 +157,14 @@ func TestUnsetTrailingComma(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
StartPos: 9,
EndPos: 11,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
StartPos: 9,
EndPos: 11,
},
Value: "a",
@ -175,14 +174,14 @@ func TestUnsetTrailingComma(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 14,
StartPos: 13,
EndPos: 15,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 14,
StartPos: 13,
EndPos: 15,
},
Value: "b",
@ -193,7 +192,7 @@ func TestUnsetTrailingComma(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

File diff suppressed because it is too large Load Diff

View File

@ -129,9 +129,10 @@ var nodesToTest = []struct {
&stmt.Declare{
Consts: []node.Node{&stmt.Expression{}},
Stmt: &stmt.StmtList{},
Alt: true,
},
[]string{"Consts", "Stmt"},
nil,
map[string]interface{}{"Alt": true},
},
{
&stmt.Default{
@ -322,9 +323,10 @@ var nodesToTest = []struct {
{
&stmt.PropertyList{
Modifiers: []node.Node{&stmt.Expression{}},
Type: &name.Name{},
Properties: []node.Node{&stmt.Expression{}},
},
[]string{"Modifiers", "Properties"},
[]string{"Modifiers", "Type", "Properties"},
nil,
},
{

View File

@ -1,7 +1,6 @@
package stmt_test
import (
"bytes"
"testing"
"gotest.tools/assert"
@ -22,7 +21,7 @@ func TestBreakEmpty(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 23,
},
Stmts: []node.Node{
@ -30,14 +29,14 @@ func TestBreakEmpty(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 23,
},
Cond: &scalar.Lnumber{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 11,
StartPos: 10,
EndPos: 11,
},
Value: "1",
@ -46,7 +45,7 @@ func TestBreakEmpty(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 14,
StartPos: 13,
EndPos: 23,
},
Stmts: []node.Node{
@ -54,7 +53,7 @@ func TestBreakEmpty(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 16,
StartPos: 15,
EndPos: 21,
},
},
@ -64,12 +63,12 @@ func TestBreakEmpty(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -82,7 +81,7 @@ func TestBreakLight(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 25,
},
Stmts: []node.Node{
@ -90,14 +89,14 @@ func TestBreakLight(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 25,
},
Cond: &scalar.Lnumber{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 11,
StartPos: 10,
EndPos: 11,
},
Value: "1",
@ -106,7 +105,7 @@ func TestBreakLight(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 14,
StartPos: 13,
EndPos: 25,
},
Stmts: []node.Node{
@ -114,14 +113,14 @@ func TestBreakLight(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 16,
StartPos: 15,
EndPos: 23,
},
Expr: &scalar.Lnumber{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 22,
StartPos: 21,
EndPos: 22,
},
Value: "2",
@ -133,12 +132,12 @@ func TestBreakLight(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -151,7 +150,7 @@ func TestBreak(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 34,
},
Stmts: []node.Node{
@ -159,14 +158,14 @@ func TestBreak(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 34,
},
Cond: &scalar.Lnumber{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 11,
StartPos: 10,
EndPos: 11,
},
Value: "1",
@ -175,7 +174,7 @@ func TestBreak(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 16,
StartPos: 15,
EndPos: 24,
},
Stmts: []node.Node{
@ -183,14 +182,14 @@ func TestBreak(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 16,
StartPos: 15,
EndPos: 24,
},
Expr: &scalar.Lnumber{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 22,
StartPos: 21,
EndPos: 22,
},
Value: "3",
@ -202,12 +201,12 @@ func TestBreak(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src), "7.4")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)

File diff suppressed because it is too large Load Diff

View File

@ -9,7 +9,7 @@ import (
)
func TestPosition(t *testing.T) {
expected := position.NewPosition(1, 1, 1, 1)
expected := position.NewPosition(1, 1, 0, 1)
for _, n := range nodes {
n.SetPosition(expected)
actual := n.GetPosition()

View File

@ -3,13 +3,32 @@ package parser
import (
"github.com/z7zmey/php-parser/errors"
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/php5"
"github.com/z7zmey/php-parser/php7"
"github.com/z7zmey/php-parser/version"
)
// Parser interface
type Parser interface {
Parse() int
GetPath() string
GetRootNode() node.Node
GetErrors() []*errors.Error
WithFreeFloating()
}
func NewParser(src []byte, v string) (Parser, error) {
var parser Parser
r, err := version.Compare(v, "7.0")
if err != nil {
return nil, err
}
if r == -1 {
parser = php5.NewParser(src, v)
} else {
parser = php7.NewParser(src, v)
}
return parser, nil
}

View File

@ -1,15 +1,13 @@
package php5
import (
"io"
"strings"
"github.com/z7zmey/php-parser/freefloating"
"github.com/z7zmey/php-parser/errors"
"github.com/z7zmey/php-parser/freefloating"
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/parser"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/positionbuilder"
"github.com/z7zmey/php-parser/scanner"
)
@ -19,20 +17,19 @@ func (lval *yySymType) Token(t *scanner.Token) {
// Parser structure
type Parser struct {
*scanner.Lexer
path string
Lexer scanner.Scanner
currentToken *scanner.Token
positionBuilder *parser.PositionBuilder
positionBuilder *positionbuilder.PositionBuilder
rootNode node.Node
}
// NewParser creates and returns new Parser
func NewParser(src io.Reader, path string) *Parser {
lexer := scanner.NewLexer(src, path)
func NewParser(src []byte, v string) *Parser {
lexer := scanner.NewLexer(src)
lexer.PHPVersion = v
return &Parser{
lexer,
path,
nil,
nil,
nil,
@ -54,30 +51,25 @@ func (l *Parser) Error(msg string) {
EndPos: l.currentToken.EndPos,
}
l.Lexer.Errors = append(l.Lexer.Errors, errors.NewError(msg, pos))
l.Lexer.AddError(errors.NewError(msg, pos))
}
func (l *Parser) WithFreeFloating() {
l.Lexer.WithFreeFloating = true
l.Lexer.SetWithFreeFloating(true)
}
// Parse the php7 Parser entrypoint
func (l *Parser) Parse() int {
// init
l.Lexer.Errors = nil
l.Lexer.SetErrors(nil)
l.rootNode = nil
l.positionBuilder = &parser.PositionBuilder{}
l.positionBuilder = &positionbuilder.PositionBuilder{}
// parse
return yyParse(l)
}
// GetPath return path to file
func (l *Parser) GetPath() string {
return l.path
}
// GetRootNode returns root node
func (l *Parser) GetRootNode() node.Node {
return l.rootNode
@ -85,7 +77,7 @@ func (l *Parser) GetRootNode() node.Node {
// GetErrors returns errors list
func (l *Parser) GetErrors() []*errors.Error {
return l.Lexer.Errors
return l.Lexer.GetErrors()
}
// helpers
@ -106,7 +98,7 @@ func isDollar(r rune) bool {
}
func (l *Parser) MoveFreeFloating(src node.Node, dst node.Node) {
if l.Lexer.WithFreeFloating == false {
if l.Lexer.GetWithFreeFloating() == false {
return
}
@ -119,7 +111,7 @@ func (l *Parser) MoveFreeFloating(src node.Node, dst node.Node) {
}
func (l *Parser) setFreeFloating(dst node.Node, p freefloating.Position, strings []freefloating.String) {
if l.Lexer.WithFreeFloating == false {
if l.Lexer.GetWithFreeFloating() == false {
return
}
@ -136,7 +128,7 @@ func (l *Parser) setFreeFloating(dst node.Node, p freefloating.Position, strings
}
func (l *Parser) GetFreeFloatingToken(t *scanner.Token) []freefloating.String {
if l.Lexer.WithFreeFloating == false {
if l.Lexer.GetWithFreeFloating() == false {
return []freefloating.String{}
}
@ -144,7 +136,7 @@ func (l *Parser) GetFreeFloatingToken(t *scanner.Token) []freefloating.String {
}
func (l *Parser) addDollarToken(v node.Node) {
if l.Lexer.WithFreeFloating == false {
if l.Lexer.GetWithFreeFloating() == false {
return
}
@ -163,7 +155,7 @@ func (l *Parser) addDollarToken(v node.Node) {
}
func (l *Parser) splitSemiColonAndPhpCloseTag(htmlNode node.Node, prevNode node.Node) {
if l.Lexer.WithFreeFloating == false {
if l.Lexer.GetWithFreeFloating() == false {
return
}
@ -226,7 +218,7 @@ func (l *Parser) splitSemiColonAndPhpCloseTag(htmlNode node.Node, prevNode node.
func (p *Parser) returnTokenToPool(yyDollar []yySymType, yyVAL *yySymType) {
for i := 1; i < len(yyDollar); i++ {
if yyDollar[i].token != nil {
p.TokenPool.Put(yyDollar[i].token)
p.Lexer.ReturnTokenToPool(yyDollar[i].token)
}
yyDollar[i].token = nil
}

File diff suppressed because it is too large Load Diff

View File

@ -66,6 +66,7 @@ import (
%token <token> T_CONTINUE
%token <token> T_GOTO
%token <token> T_FUNCTION
%token <token> T_FN
%token <token> T_CONST
%token <token> T_RETURN
%token <token> T_TRY
@ -157,6 +158,7 @@ import (
%token <token> T_XOR_EQUAL
%token <token> T_SL_EQUAL
%token <token> T_SR_EQUAL
%token <token> T_COALESCE_EQUAL
%token <token> T_BOOLEAN_OR
%token <token> T_BOOLEAN_AND
%token <token> T_POW
@ -282,11 +284,9 @@ start:
yylex.(*Parser).rootNode = node.NewRoot($1)
yylex.(*Parser).rootNode.SetPosition(yylex.(*Parser).positionBuilder.NewNodeListPosition($1))
yylex.(*Parser).setFreeFloating(yylex.(*Parser).rootNode, freefloating.End, yylex.(*Parser).currentToken.FreeFloating)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
if yylex.(*Parser).currentToken.Value == "\xff" {
yylex.(*Parser).setFreeFloating(yylex.(*Parser).rootNode, freefloating.End, yylex.(*Parser).currentToken.FreeFloating)
}
}
;
@ -383,8 +383,6 @@ top_statement:
yylex.(*Parser).setFreeFloating($$, freefloating.SemiColon, yylex.(*Parser).GetFreeFloatingToken($4))
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
yylex.(*Parser).Begin(scanner.HALT_COMPILER)
}
| T_NAMESPACE namespace_name ';'
{
@ -871,8 +869,6 @@ inner_statement:
yylex.(*Parser).setFreeFloating($$, freefloating.SemiColon, yylex.(*Parser).GetFreeFloatingToken($4))
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
yylex.(*Parser).Begin(scanner.HALT_COMPILER)
}
;
@ -2705,7 +2701,7 @@ class_statement_list:
class_statement:
variable_modifiers class_variable_declaration ';'
{
$$ = stmt.NewPropertyList($1, $2)
$$ = stmt.NewPropertyList($1, nil, $2)
// save position
$$.SetPosition(yylex.(*Parser).positionBuilder.NewNodeListTokenPosition($1, $3))
@ -5921,7 +5917,7 @@ possible_comma:
non_empty_static_array_pair_list:
non_empty_static_array_pair_list ',' static_scalar_value T_DOUBLE_ARROW static_scalar_value
{
arrayItem := expr.NewArrayItem($3, $5)
arrayItem := expr.NewArrayItem($3, $5, false)
$$ = append($1, arrayItem)
// save position
@ -5936,7 +5932,7 @@ non_empty_static_array_pair_list:
}
| non_empty_static_array_pair_list ',' static_scalar_value
{
arrayItem := expr.NewArrayItem(nil, $3)
arrayItem := expr.NewArrayItem(nil, $3, false)
$$ = append($1, arrayItem)
// save position
@ -5950,7 +5946,7 @@ non_empty_static_array_pair_list:
}
| static_scalar_value T_DOUBLE_ARROW static_scalar_value
{
arrayItem := expr.NewArrayItem($1, $3)
arrayItem := expr.NewArrayItem($1, $3, false)
$$ = []node.Node{arrayItem}
// save position
@ -5964,7 +5960,7 @@ non_empty_static_array_pair_list:
}
| static_scalar_value
{
arrayItem := expr.NewArrayItem(nil, $1)
arrayItem := expr.NewArrayItem(nil, $1, false)
$$ = []node.Node{arrayItem}
// save position
@ -6573,7 +6569,7 @@ assignment_list:
assignment_list ',' assignment_list_element
{
if len($1) == 0 {
$1 = []node.Node{expr.NewArrayItem(nil, nil)}
$1 = []node.Node{expr.NewArrayItem(nil, nil, false)}
}
$$ = append($1, $3)
@ -6599,7 +6595,7 @@ assignment_list:
assignment_list_element:
variable
{
$$ = expr.NewArrayItem(nil, $1)
$$ = expr.NewArrayItem(nil, $1, false)
// save position
$$.SetPosition(yylex.(*Parser).positionBuilder.NewNodePosition($1))
@ -6612,7 +6608,7 @@ assignment_list_element:
| T_LIST '(' assignment_list ')'
{
listNode := expr.NewList($3)
$$ = expr.NewArrayItem(nil, listNode)
$$ = expr.NewArrayItem(nil, listNode, false)
// save position
listNode.SetPosition(yylex.(*Parser).positionBuilder.NewTokensPosition($1, $4))
@ -6627,7 +6623,7 @@ assignment_list_element:
}
| /* empty */
{
$$ = expr.NewArrayItem(nil, nil)
$$ = expr.NewArrayItem(nil, nil, false)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
@ -6646,7 +6642,7 @@ array_pair_list:
$$ = $1
if $2 != nil {
$$ = append($1, expr.NewArrayItem(nil, nil))
$$ = append($1, expr.NewArrayItem(nil, nil, false))
}
// save comments
@ -6661,7 +6657,7 @@ array_pair_list:
non_empty_array_pair_list:
non_empty_array_pair_list ',' expr T_DOUBLE_ARROW expr
{
arrayItem := expr.NewArrayItem($3, $5)
arrayItem := expr.NewArrayItem($3, $5, false)
$$ = append($1, arrayItem)
// save position
@ -6676,7 +6672,7 @@ non_empty_array_pair_list:
}
| non_empty_array_pair_list ',' expr
{
arrayItem := expr.NewArrayItem(nil, $3)
arrayItem := expr.NewArrayItem(nil, $3, false)
$$ = append($1, arrayItem)
// save position
@ -6690,7 +6686,7 @@ non_empty_array_pair_list:
}
| expr T_DOUBLE_ARROW expr
{
arrayItem := expr.NewArrayItem($1, $3)
arrayItem := expr.NewArrayItem($1, $3, false)
$$ = []node.Node{arrayItem}
// save position
@ -6704,7 +6700,7 @@ non_empty_array_pair_list:
}
| expr
{
arrayItem := expr.NewArrayItem(nil, $1)
arrayItem := expr.NewArrayItem(nil, $1, false)
$$ = []node.Node{arrayItem}
// save position
@ -6718,7 +6714,7 @@ non_empty_array_pair_list:
| non_empty_array_pair_list ',' expr T_DOUBLE_ARROW '&' w_variable
{
reference := expr.NewReference($6)
arrayItem := expr.NewArrayItem($3, reference)
arrayItem := expr.NewArrayItem($3, reference, false)
$$ = append($1, arrayItem)
// save position
@ -6736,7 +6732,7 @@ non_empty_array_pair_list:
| non_empty_array_pair_list ',' '&' w_variable
{
reference := expr.NewReference($4)
arrayItem := expr.NewArrayItem(nil, reference)
arrayItem := expr.NewArrayItem(nil, reference, false)
$$ = append($1, arrayItem)
// save position
@ -6752,7 +6748,7 @@ non_empty_array_pair_list:
| expr T_DOUBLE_ARROW '&' w_variable
{
reference := expr.NewReference($4)
arrayItem := expr.NewArrayItem($1, reference)
arrayItem := expr.NewArrayItem($1, reference, false)
$$ = []node.Node{arrayItem}
// save position
@ -6769,7 +6765,7 @@ non_empty_array_pair_list:
| '&' w_variable
{
reference := expr.NewReference($2)
arrayItem := expr.NewArrayItem(nil, reference)
arrayItem := expr.NewArrayItem(nil, reference, false)
$$ = []node.Node{arrayItem}
// save position

View File

@ -1,7 +1,6 @@
package php5_test
import (
"bytes"
"testing"
"github.com/z7zmey/php-parser/php5"
@ -414,7 +413,7 @@ CAD;
`
for n := 0; n < b.N; n++ {
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
}
}

File diff suppressed because it is too large Load Diff

View File

@ -1,14 +1,13 @@
package php7
import (
"io"
"strings"
"github.com/z7zmey/php-parser/errors"
"github.com/z7zmey/php-parser/freefloating"
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/parser"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/positionbuilder"
"github.com/z7zmey/php-parser/scanner"
)
@ -18,27 +17,25 @@ func (lval *yySymType) Token(t *scanner.Token) {
// Parser structure
type Parser struct {
*scanner.Lexer
path string
Lexer scanner.Scanner
currentToken *scanner.Token
positionBuilder *parser.PositionBuilder
positionBuilder *positionbuilder.PositionBuilder
rootNode node.Node
}
// NewParser creates and returns new Parser
func NewParser(src io.Reader, path string) *Parser {
lexer := scanner.NewLexer(src, path)
func NewParser(src []byte, v string) *Parser {
lexer := scanner.NewLexer(src)
lexer.PHPVersion = v
return &Parser{
lexer,
path,
nil,
nil,
nil,
}
}
// Lex proxy to lexer Lex
func (l *Parser) Lex(lval *yySymType) int {
t := l.Lexer.Lex(lval)
l.currentToken = lval.token
@ -53,30 +50,25 @@ func (l *Parser) Error(msg string) {
EndPos: l.currentToken.EndPos,
}
l.Lexer.Errors = append(l.Lexer.Errors, errors.NewError(msg, pos))
l.Lexer.AddError(errors.NewError(msg, pos))
}
func (l *Parser) WithFreeFloating() {
l.Lexer.WithFreeFloating = true
l.Lexer.SetWithFreeFloating(true)
}
// Parse the php7 Parser entrypoint
func (l *Parser) Parse() int {
// init
l.Lexer.Errors = nil
l.Lexer.SetErrors(nil)
l.rootNode = nil
l.positionBuilder = &parser.PositionBuilder{}
l.positionBuilder = &positionbuilder.PositionBuilder{}
// parse
return yyParse(l)
}
// GetPath return path to file
func (l *Parser) GetPath() string {
return l.path
}
// GetRootNode returns root node
func (l *Parser) GetRootNode() node.Node {
return l.rootNode
@ -84,7 +76,7 @@ func (l *Parser) GetRootNode() node.Node {
// GetErrors returns errors list
func (l *Parser) GetErrors() []*errors.Error {
return l.Lexer.Errors
return l.Lexer.GetErrors()
}
// helpers
@ -105,7 +97,7 @@ func isDollar(r rune) bool {
}
func (l *Parser) MoveFreeFloating(src node.Node, dst node.Node) {
if l.Lexer.WithFreeFloating == false {
if l.Lexer.GetWithFreeFloating() == false {
return
}
@ -118,7 +110,7 @@ func (l *Parser) MoveFreeFloating(src node.Node, dst node.Node) {
}
func (l *Parser) setFreeFloating(dst node.Node, p freefloating.Position, strings []freefloating.String) {
if l.Lexer.WithFreeFloating == false {
if l.Lexer.GetWithFreeFloating() == false {
return
}
@ -135,7 +127,7 @@ func (l *Parser) setFreeFloating(dst node.Node, p freefloating.Position, strings
}
func (l *Parser) GetFreeFloatingToken(t *scanner.Token) []freefloating.String {
if l.Lexer.WithFreeFloating == false {
if l.Lexer.GetWithFreeFloating() == false {
return []freefloating.String{}
}
@ -143,7 +135,7 @@ func (l *Parser) GetFreeFloatingToken(t *scanner.Token) []freefloating.String {
}
func (l *Parser) addDollarToken(v node.Node) {
if l.Lexer.WithFreeFloating == false {
if l.Lexer.GetWithFreeFloating() == false {
return
}
@ -162,7 +154,7 @@ func (l *Parser) addDollarToken(v node.Node) {
}
func (l *Parser) splitSemiColonAndPhpCloseTag(htmlNode node.Node, prevNode node.Node) {
if l.Lexer.WithFreeFloating == false {
if l.Lexer.GetWithFreeFloating() == false {
return
}
@ -225,7 +217,7 @@ func (l *Parser) splitSemiColonAndPhpCloseTag(htmlNode node.Node, prevNode node.
func (p *Parser) returnTokenToPool(yyDollar []yySymType, yyVAL *yySymType) {
for i := 1; i < len(yyDollar); i++ {
if yyDollar[i].token != nil {
p.TokenPool.Put(yyDollar[i].token)
p.Lexer.ReturnTokenToPool(yyDollar[i].token)
}
yyDollar[i].token = nil
}

File diff suppressed because it is too large Load Diff

Some files were not shown because too many files have changed in this diff Show More