Merge pull request #83 from z7zmey/ragel

#80 implement Ragel based lexer
This commit is contained in:
Vadym Slizov 2019-03-20 21:10:59 +02:00 committed by GitHub
commit b00a785bfb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
108 changed files with 30415 additions and 18534 deletions

View File

@ -27,8 +27,8 @@ compile: ./php5/php5.go ./php7/php7.go ./scanner/scanner.go fmt
sed -i '' -e 's/yyErrorVerbose = false/yyErrorVerbose = true/g' ./php5/php5.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)
@ -62,7 +62,6 @@ package main
import (
"fmt"
"bytes"
"os"
"github.com/z7zmey/php-parser/php7"
@ -70,9 +69,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)
parser.Parse()
for _, e := range parser.GetErrors() {
@ -82,12 +81,10 @@ func main() {
visitor := visitor.Dumper{
Writer: os.Stdout,
Indent: "",
Comments: parser.GetComments(),
Positions: parser.GetPositions(),
}
rootNode := parser.GetRootNode()
rootNode.Walk(visitor)
rootNode.Walk(&visitor)
}
```

47
main.go
View File

@ -34,6 +34,11 @@ type file struct {
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")
@ -44,7 +49,7 @@ func main() {
flag.Parse()
if len(flag.Args()) == 0{
if len(flag.Args()) == 0 {
flag.Usage()
return
}
@ -58,10 +63,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++ {
@ -98,7 +103,7 @@ func processPath(pathList []string, fileCh chan<- *file) {
}
}
func parserWorker(fileCh <-chan *file, result chan<- parser.Parser) {
func parserWorker(fileCh <-chan *file, r chan<- result) {
var parserWorker parser.Parser
for {
@ -107,12 +112,10 @@ func parserWorker(fileCh <-chan *file, result chan<- parser.Parser) {
return
}
src := bytes.NewReader(f.content)
if *usePhp5 {
parserWorker = php5.NewParser(src, f.path)
parserWorker = php5.NewParser(f.content)
} else {
parserWorker = php7.NewParser(src, f.path)
parserWorker = php7.NewParser(f.content)
}
if *withFreeFloating {
@ -121,17 +124,17 @@ 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
@ -139,25 +142,29 @@ func printerWorker(result <-chan parser.Parser) {
counter++
fmt.Fprintf(w, "==> [%d] %s\n", counter, parserWorker.GetPath())
fmt.Fprintf(w, "==> [%d] %s\n", counter, res.path)
for _, e := range parserWorker.GetErrors() {
for _, e := range res.parser.GetErrors() {
// if !strings.Contains(e.Msg, "WARNING") {
// fmt.Print("\n\n\n" + parserWorker.GetPath() + "\n ")
// panic(e.Msg)
// }
fmt.Fprintln(w, 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 {
@ -167,22 +174,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()

File diff suppressed because it is too large Load Diff

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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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 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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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,12 +208,12 @@ func TestArrayItems(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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 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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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"
@ -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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
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))
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))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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 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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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

@ -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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
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))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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"
@ -23,7 +22,7 @@ func TestProperty(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 22,
},
Stmts: []node.Node{
@ -31,7 +30,7 @@ func TestProperty(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 22,
},
PhpDocComment: "",
@ -39,7 +38,7 @@ func TestProperty(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
StartPos: 9,
EndPos: 12,
},
Value: "foo",
@ -49,7 +48,7 @@ func TestProperty(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 15,
StartPos: 14,
EndPos: 21,
},
Modifiers: []node.Node{
@ -57,7 +56,7 @@ func TestProperty(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 15,
StartPos: 14,
EndPos: 17,
},
Value: "var",
@ -68,7 +67,7 @@ func TestProperty(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 19,
StartPos: 18,
EndPos: 20,
},
PhpDocComment: "",
@ -76,14 +75,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 +96,12 @@ func TestProperty(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -115,7 +114,7 @@ func TestProperties(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 40,
},
Stmts: []node.Node{
@ -123,7 +122,7 @@ func TestProperties(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 40,
},
PhpDocComment: "",
@ -131,7 +130,7 @@ func TestProperties(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
StartPos: 9,
EndPos: 12,
},
Value: "foo",
@ -141,7 +140,7 @@ func TestProperties(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 15,
StartPos: 14,
EndPos: 39,
},
Modifiers: []node.Node{
@ -149,7 +148,7 @@ func TestProperties(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 15,
StartPos: 14,
EndPos: 20,
},
Value: "public",
@ -158,7 +157,7 @@ func TestProperties(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 22,
StartPos: 21,
EndPos: 27,
},
Value: "static",
@ -169,7 +168,7 @@ func TestProperties(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 29,
StartPos: 28,
EndPos: 30,
},
PhpDocComment: "",
@ -177,14 +176,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 +194,7 @@ func TestProperties(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 33,
StartPos: 32,
EndPos: 38,
},
PhpDocComment: "",
@ -203,14 +202,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 +219,7 @@ func TestProperties(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 38,
StartPos: 37,
EndPos: 38,
},
Value: "1",
@ -233,12 +232,12 @@ func TestProperties(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@ -251,7 +250,7 @@ func TestProperties2(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 40,
},
Stmts: []node.Node{
@ -259,7 +258,7 @@ func TestProperties2(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
StartPos: 3,
EndPos: 40,
},
PhpDocComment: "",
@ -267,7 +266,7 @@ func TestProperties2(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
StartPos: 9,
EndPos: 12,
},
Value: "foo",
@ -277,7 +276,7 @@ func TestProperties2(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 15,
StartPos: 14,
EndPos: 39,
},
Modifiers: []node.Node{
@ -285,7 +284,7 @@ func TestProperties2(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 15,
StartPos: 14,
EndPos: 20,
},
Value: "public",
@ -294,7 +293,7 @@ func TestProperties2(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 22,
StartPos: 21,
EndPos: 27,
},
Value: "static",
@ -305,7 +304,7 @@ func TestProperties2(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 29,
StartPos: 28,
EndPos: 34,
},
PhpDocComment: "",
@ -313,14 +312,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 +329,7 @@ func TestProperties2(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 34,
StartPos: 33,
EndPos: 34,
},
Value: "1",
@ -340,7 +339,7 @@ func TestProperties2(t *testing.T) {
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 37,
StartPos: 36,
EndPos: 38,
},
PhpDocComment: "",
@ -348,14 +347,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,12 +368,12 @@ func TestProperties2(t *testing.T) {
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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 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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
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{

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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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))
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
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

@ -8,7 +8,6 @@ import (
// Parser interface
type Parser interface {
Parse() int
GetPath() string
GetRootNode() node.Node
GetErrors() []*errors.Error
WithFreeFloating()

View File

@ -1,12 +1,10 @@
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"
@ -19,20 +17,18 @@ 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
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) *Parser {
lexer := scanner.NewLexer(src)
return &Parser{
lexer,
path,
nil,
nil,
nil,
@ -54,17 +50,17 @@ 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{}
@ -73,11 +69,6 @@ func (l *Parser) Parse() int {
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 +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
@ -106,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
}
@ -119,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
}
@ -136,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{}
}
@ -144,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
}
@ -163,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
}
@ -226,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

View File

@ -282,11 +282,9 @@ start:
yylex.(*Parser).rootNode = node.NewRoot($1)
yylex.(*Parser).rootNode.SetPosition(yylex.(*Parser).positionBuilder.NewNodeListPosition($1))
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
yylex.(*Parser).setFreeFloating(yylex.(*Parser).rootNode, freefloating.End, yylex.(*Parser).currentToken.FreeFloating)
if yylex.(*Parser).currentToken.Value == "\xff" {
yylex.(*Parser).setFreeFloating(yylex.(*Parser).rootNode, freefloating.End, yylex.(*Parser).currentToken.FreeFloating)
}
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
;
@ -383,8 +381,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 +867,6 @@ inner_statement:
yylex.(*Parser).setFreeFloating($$, freefloating.SemiColon, yylex.(*Parser).GetFreeFloatingToken($4))
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
yylex.(*Parser).Begin(scanner.HALT_COMPILER)
}
;

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))
php5parser.Parse()
}
}

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +1,6 @@
package php7
import (
"io"
"strings"
"github.com/z7zmey/php-parser/errors"
@ -18,27 +17,24 @@ 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
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) *Parser {
lexer := scanner.NewLexer(src)
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,17 +49,17 @@ 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{}
@ -72,11 +68,6 @@ func (l *Parser) Parse() int {
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 +75,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 +96,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 +109,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 +126,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 +134,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 +153,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 +216,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

@ -303,11 +303,9 @@ start:
// save position
yylex.(*Parser).rootNode.SetPosition(yylex.(*Parser).positionBuilder.NewNodeListPosition($1))
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
yylex.(*Parser).setFreeFloating(yylex.(*Parser).rootNode, freefloating.End, yylex.(*Parser).currentToken.FreeFloating)
if yylex.(*Parser).currentToken.Value == "\xff" {
yylex.(*Parser).setFreeFloating(yylex.(*Parser).rootNode, freefloating.End, yylex.(*Parser).currentToken.FreeFloating)
}
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}
;
@ -485,8 +483,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 ';'
{
@ -4194,8 +4190,8 @@ expr_without_variable:
backup_doc_comment:
/* empty */
{
$$ = yylex.(*Parser).PhpDocComment
yylex.(*Parser).PhpDocComment = ""
$$ = yylex.(*Parser).Lexer.GetPhpDocComment()
yylex.(*Parser).Lexer.SetPhpDocComment("")
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
}

View File

@ -1,7 +1,6 @@
package php7_test
import (
"bytes"
"testing"
"github.com/z7zmey/php-parser/php7"
@ -382,7 +381,7 @@ CAD;
`
for n := 0; n < b.N; n++ {
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src))
php7parser.Parse()
}
}

File diff suppressed because it is too large Load Diff

View File

@ -569,9 +569,7 @@ func (p *PrettyPrinter) printScalarEncapsed(n node.Node) {
func (p *PrettyPrinter) printScalarHeredoc(n node.Node) {
nn := n.(*scalar.Heredoc)
io.WriteString(p.w, "<<<")
io.WriteString(p.w, nn.Label)
io.WriteString(p.w, "\n")
for _, part := range nn.Parts {
switch part.(type) {
@ -584,7 +582,7 @@ func (p *PrettyPrinter) printScalarHeredoc(n node.Node) {
}
}
io.WriteString(p.w, strings.Trim(nn.Label, "\"'"))
io.WriteString(p.w, strings.Trim(nn.Label, "<\"'\n"))
}
func (p *PrettyPrinter) printScalarMagicConstant(n node.Node) {

View File

@ -87,7 +87,7 @@ func TestPrintFileInlineHtml(t *testing.T) {
&stmt.InlineHtml{Value: "<div>HTML</div>"},
&stmt.Expression{
Expr: &scalar.Heredoc{
Label: "\"LBL\"",
Label: "<<<\"LBL\"\n",
Parts: []node.Node{
&scalar.EncapsedStringPart{Value: "hello world\n"},
},
@ -356,7 +356,7 @@ func TestPrintScalarHeredoc(t *testing.T) {
p := printer.NewPrettyPrinter(o, " ")
p.Print(&scalar.Heredoc{
Label: "LBL",
Label: "<<<LBL\n",
Parts: []node.Node{
&scalar.EncapsedStringPart{Value: "hello "},
&expr.Variable{VarName: &node.Identifier{Value: "var"}},
@ -379,7 +379,7 @@ func TestPrintScalarNowdoc(t *testing.T) {
p := printer.NewPrettyPrinter(o, " ")
p.Print(&scalar.Heredoc{
Label: "'LBL'",
Label: "<<<'LBL'\n",
Parts: []node.Node{
&scalar.EncapsedStringPart{Value: "hello world\n"},
},

View File

@ -618,9 +618,7 @@ func (p *Printer) printScalarHeredoc(n node.Node) {
nn := n.(*scalar.Heredoc)
p.printFreeFloating(nn, freefloating.Start)
io.WriteString(p.w, "<<<")
io.WriteString(p.w, nn.Label)
io.WriteString(p.w, "\n")
for _, part := range nn.Parts {
switch part.(type) {
@ -643,8 +641,7 @@ func (p *Printer) printScalarHeredoc(n node.Node) {
}
}
io.WriteString(p.w, "\n")
io.WriteString(p.w, strings.Trim(nn.Label, "\"'"))
io.WriteString(p.w, strings.Trim(nn.Label, "<\"'\n"))
p.printFreeFloating(nn, freefloating.End)
}

View File

@ -10,7 +10,7 @@ import (
)
func parsePhp5(src string) node.Node {
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser := php5.NewParser([]byte(src))
php5parser.WithFreeFloating()
php5parser.Parse()

View File

@ -29,7 +29,7 @@ abstract class Bar extends Baz
// parse
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src))
php7parser.WithFreeFloating()
php7parser.Parse()
@ -61,7 +61,7 @@ abstract class Bar extends Baz
}
func parse(src string) node.Node {
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser := php7.NewParser([]byte(src))
php7parser.WithFreeFloating()
php7parser.Parse()

View File

@ -425,13 +425,13 @@ func TestPrinterPrintScalarHeredoc(t *testing.T) {
p := printer.NewPrinter(o)
p.Print(&scalar.Heredoc{
Label: "LBL",
Label: "<<<LBL\n",
Parts: []node.Node{
&scalar.EncapsedStringPart{Value: "hello "},
&expr.Variable{
VarName: &node.Identifier{Value: "var"},
},
&scalar.EncapsedStringPart{Value: " world"},
&scalar.EncapsedStringPart{Value: " world\n"},
},
})
@ -450,9 +450,9 @@ func TestPrinterPrintScalarNowdoc(t *testing.T) {
p := printer.NewPrinter(o)
p.Print(&scalar.Heredoc{
Label: "'LBL'",
Label: "<<<'LBL'\n",
Parts: []node.Node{
&scalar.EncapsedStringPart{Value: "hello world"},
&scalar.EncapsedStringPart{Value: "hello world\n"},
},
})

View File

@ -1,188 +1,232 @@
// Package scanner transforms an input string into a stream of PHP tokens.
package scanner
import (
"bufio"
"bytes"
t "go/token"
"io"
"unicode"
"strings"
"github.com/z7zmey/php-parser/errors"
"github.com/z7zmey/php-parser/freefloating"
"github.com/z7zmey/php-parser/position"
"github.com/cznic/golex/lex"
)
// Allocate Character classes anywhere in [0x80, 0xFF].
const (
classUnicodeLeter = iota + 0x80
classUnicodeDigit
classUnicodeGraphic
classOther
)
type Scanner interface {
Lex(lval Lval) int
ReturnTokenToPool(t *Token)
GetPhpDocComment() string
SetPhpDocComment(string)
GetErrors() []*errors.Error
GetWithFreeFloating() bool
SetWithFreeFloating(bool)
AddError(e *errors.Error)
SetErrors(e []*errors.Error)
}
// Lval parsers yySymType must implement this interface
type Lval interface {
Token(tkn *Token)
}
// Lexer php lexer
type Lexer struct {
*lex.Lexer
StateStack []int
PhpDocComment string
FreeFloating []freefloating.String
heredocLabel string
tokenBytesBuf *bytes.Buffer
data []byte
p, pe, cs int
ts, te, act int
stack []int
top int
heredocLabel []byte
TokenPool *TokenPool
FreeFloating []freefloating.String
WithFreeFloating bool
PhpDocComment string
lastToken *Token
Errors []*errors.Error
NewLines NewLines
}
// Rune2Class returns the rune integer id
func Rune2Class(r rune) int {
if r >= 0 && r < 0x80 { // Keep ASCII as it is.
return int(r)
}
if unicode.IsLetter(r) {
return classUnicodeLeter
}
if unicode.IsDigit(r) {
return classUnicodeDigit
}
if unicode.IsGraphic(r) {
return classUnicodeGraphic
}
if r == lex.RuneEOF {
return int(r)
}
return classOther
func (l *Lexer) ReturnTokenToPool(t *Token) {
l.TokenPool.Put(t)
}
// NewLexer the Lexer constructor
func NewLexer(src io.Reader, fName string) *Lexer {
file := t.NewFileSet().AddFile(fName, -1, 1<<31-3)
lx, err := lex.New(file, bufio.NewReader(src), lex.RuneClass(Rune2Class))
if err != nil {
panic(err)
}
return &Lexer{
Lexer: lx,
StateStack: []int{0},
PhpDocComment: "",
FreeFloating: nil,
heredocLabel: "",
tokenBytesBuf: &bytes.Buffer{},
TokenPool: &TokenPool{},
}
func (l *Lexer) GetPhpDocComment() string {
return l.PhpDocComment
}
func (l *Lexer) Error(msg string) {
chars := l.Token()
firstChar := chars[0]
lastChar := chars[len(chars)-1]
pos := position.NewPosition(
l.File.Line(firstChar.Pos()),
l.File.Line(lastChar.Pos()),
int(firstChar.Pos()),
int(lastChar.Pos()),
)
l.Errors = append(l.Errors, errors.NewError(msg, pos))
func (l *Lexer) SetPhpDocComment(s string) {
l.PhpDocComment = s
}
func (l *Lexer) ungetChars(n int) []lex.Char {
l.Unget(l.Lookahead())
chars := l.Token()
for i := 1; i <= n; i++ {
char := chars[len(chars)-i]
l.Unget(char)
}
buf := l.Token()
buf = buf[:len(buf)-n]
return buf
func (l *Lexer) GetErrors() []*errors.Error {
return l.Errors
}
func (l *Lexer) pushState(state int) {
l.StateStack = append(l.StateStack, state)
func (l *Lexer) GetWithFreeFloating() bool {
return l.WithFreeFloating
}
func (l *Lexer) popState() {
len := len(l.StateStack)
if len <= 1 {
return
}
l.StateStack = l.StateStack[:len-1]
func (l *Lexer) SetWithFreeFloating(b bool) {
l.WithFreeFloating = b
}
func (l *Lexer) Begin(state int) {
len := len(l.StateStack)
l.StateStack = l.StateStack[:len-1]
l.StateStack = append(l.StateStack, state)
func (l *Lexer) AddError(e *errors.Error) {
l.Errors = append(l.Errors, e)
}
func (l *Lexer) getCurrentState() int {
return l.StateStack[len(l.StateStack)-1]
func (l *Lexer) SetErrors(e []*errors.Error) {
l.Errors = e
}
func (l *Lexer) createToken(chars []lex.Char) *Token {
firstChar := chars[0]
lastChar := chars[len(chars)-1]
func (lex *Lexer) createToken(lval Lval) *Token {
token := lex.TokenPool.Get()
token.FreeFloating = lex.FreeFloating
token.Value = string(lex.data[lex.ts:lex.te])
token := l.TokenPool.Get()
token.FreeFloating = l.FreeFloating
token.Value = l.tokenString(chars)
// fmt.Println(l.tokenString(chars))
token.StartLine = l.File.Line(firstChar.Pos())
token.EndLine = l.File.Line(lastChar.Pos())
token.StartPos = int(firstChar.Pos())
token.EndPos = int(lastChar.Pos())
token.StartLine = lex.NewLines.GetLine(lex.ts)
token.EndLine = lex.NewLines.GetLine(lex.te - 1)
token.StartPos = lex.ts
token.EndPos = lex.te
lval.Token(token)
return token
}
func (l *Lexer) tokenString(chars []lex.Char) string {
l.tokenBytesBuf.Reset()
for _, c := range chars {
l.tokenBytesBuf.WriteRune(c.Rune)
}
return string(l.tokenBytesBuf.Bytes())
}
// free-floating
func (l *Lexer) addFreeFloating(t freefloating.StringType, chars []lex.Char) {
if !l.WithFreeFloating {
func (lex *Lexer) addFreeFloating(t freefloating.StringType, ps, pe int) {
if !lex.WithFreeFloating {
return
}
firstChar := chars[0]
lastChar := chars[len(chars)-1]
pos := position.NewPosition(
l.File.Line(firstChar.Pos()),
l.File.Line(lastChar.Pos()),
int(firstChar.Pos()),
int(lastChar.Pos()),
lex.NewLines.GetLine(lex.ts),
lex.NewLines.GetLine(lex.te-1),
lex.ts,
lex.te,
)
l.FreeFloating = append(l.FreeFloating, freefloating.String{
lex.FreeFloating = append(lex.FreeFloating, freefloating.String{
StringType: t,
Value: l.tokenString(chars),
Value: string(lex.data[ps:pe]),
Position: pos,
})
}
func (lex *Lexer) isNotStringVar() bool {
p := lex.p
if lex.data[p-1] == '\\' && lex.data[p-2] != '\\' {
return true
}
if len(lex.data) < p+1 {
return true
}
if lex.data[p] == '$' && (lex.data[p+1] == '{' || isValidVarNameStart(lex.data[p+1])) {
return false
}
if lex.data[p] == '{' && lex.data[p+1] == '$' {
return false
}
return true
}
func (lex *Lexer) isNotStringEnd(s byte) bool {
p := lex.p
if lex.data[p-1] == '\\' && lex.data[p-2] != '\\' {
return true
}
return !(lex.data[p] == s)
}
func (lex *Lexer) isHeredocEnd(p int) bool {
if lex.data[p-1] != '\r' && lex.data[p-1] != '\n' {
return false
}
l := len(lex.heredocLabel)
if len(lex.data) < p+l {
return false
}
if len(lex.data) > p+l && lex.data[p+l] != ';' && lex.data[p+l] != '\r' && lex.data[p+l] != '\n' {
return false
}
if len(lex.data) > p+l+1 && lex.data[p+l] == ';' && lex.data[p+l+1] != '\r' && lex.data[p+l+1] != '\n' {
return false
}
return bytes.Equal(lex.heredocLabel, lex.data[p:p+l])
}
func (lex *Lexer) isNotHeredocEnd(p int) bool {
return !lex.isHeredocEnd(p)
}
func (lex *Lexer) growCallStack() {
if lex.top == len(lex.stack) {
lex.stack = append(lex.stack, 0)
}
}
func (lex *Lexer) isNotPhpCloseToken() bool {
if lex.p+1 == len(lex.data) {
return true
}
return lex.data[lex.p] != '?' || lex.data[lex.p+1] != '>'
}
func (lex *Lexer) isNotNewLine() bool {
if lex.data[lex.p] == '\n' && lex.data[lex.p-1] == '\r' {
return true
}
return lex.data[lex.p-1] != '\n' && lex.data[lex.p-1] != '\r'
}
func (lex *Lexer) call(state int, fnext int) {
lex.growCallStack()
lex.stack[lex.top] = state
lex.top++
lex.p++
lex.cs = fnext
}
func (lex *Lexer) ret(n int) {
lex.top = lex.top - n
if lex.top < 0 {
lex.top = 0
}
lex.cs = lex.stack[lex.top]
lex.p++
}
func (lex *Lexer) ungetStr(s string) {
tokenStr := string(lex.data[lex.ts:lex.te])
if strings.HasSuffix(tokenStr, s) {
lex.ungetCnt(len(s))
}
}
func (lex *Lexer) ungetCnt(n int) {
lex.p = lex.p - n
lex.te = lex.te - n
}
func (lex *Lexer) Error(msg string) {
pos := position.NewPosition(
lex.NewLines.GetLine(lex.ts),
lex.NewLines.GetLine(lex.te-1),
lex.ts,
lex.te,
)
lex.Errors = append(lex.Errors, errors.NewError(msg, pos))
}
func isValidVarNameStart(r byte) bool {
return r >= 'A' && r <= 'Z' || r == '_' || r >= 'a' && r <= 'z' || r >= '\u007f' && r <= 'ÿ'
}

View File

@ -1,10 +1,10 @@
package scanner
type LexerToken int
type TokenID int
//go:generate stringer -type=LexerToken -output ./lexer_tokens_string.go
//go:generate stringer -type=TokenID -output ./tokenid_string.go
const (
T_INCLUDE LexerToken = iota + 57346
T_INCLUDE TokenID = iota + 57346
T_INCLUDE_ONCE
T_EXIT
T_IF

View File

@ -1,17 +0,0 @@
// Code generated by "stringer -type=LexerToken -output ./lexer_tokens_string.go"; DO NOT EDIT.
package scanner
import "strconv"
const _LexerToken_name = "T_INCLUDET_INCLUDE_ONCET_EXITT_IFT_LNUMBERT_DNUMBERT_STRINGT_STRING_VARNAMET_VARIABLET_NUM_STRINGT_INLINE_HTMLT_CHARACTERT_BAD_CHARACTERT_ENCAPSED_AND_WHITESPACET_CONSTANT_ENCAPSED_STRINGT_ECHOT_DOT_WHILET_ENDWHILET_FORT_ENDFORT_FOREACHT_ENDFOREACHT_DECLARET_ENDDECLARET_AST_SWITCHT_ENDSWITCHT_CASET_DEFAULTT_BREAKT_CONTINUET_GOTOT_FUNCTIONT_CONSTT_RETURNT_TRYT_CATCHT_FINALLYT_THROWT_USET_INSTEADOFT_GLOBALT_VART_UNSETT_ISSETT_EMPTYT_HALT_COMPILERT_CLASST_TRAITT_INTERFACET_EXTENDST_IMPLEMENTST_OBJECT_OPERATORT_DOUBLE_ARROWT_LISTT_ARRAYT_CALLABLET_CLASS_CT_TRAIT_CT_METHOD_CT_FUNC_CT_LINET_FILET_COMMENTT_DOC_COMMENTT_OPEN_TAGT_OPEN_TAG_WITH_ECHOT_CLOSE_TAGT_WHITESPACET_START_HEREDOCT_END_HEREDOCT_DOLLAR_OPEN_CURLY_BRACEST_CURLY_OPENT_PAAMAYIM_NEKUDOTAYIMT_NAMESPACET_NS_CT_DIRT_NS_SEPARATORT_ELLIPSIST_EVALT_REQUIRET_REQUIRE_ONCET_LOGICAL_ORT_LOGICAL_XORT_LOGICAL_ANDT_INSTANCEOFT_NEWT_CLONET_ELSEIFT_ELSET_ENDIFT_PRINTT_YIELDT_STATICT_ABSTRACTT_FINALT_PRIVATET_PROTECTEDT_PUBLICT_INCT_DECT_YIELD_FROMT_INT_CASTT_DOUBLE_CASTT_STRING_CASTT_ARRAY_CASTT_OBJECT_CASTT_BOOL_CASTT_UNSET_CASTT_COALESCET_SPACESHIPT_NOELSET_PLUS_EQUALT_MINUS_EQUALT_MUL_EQUALT_POW_EQUALT_DIV_EQUALT_CONCAT_EQUALT_MOD_EQUALT_AND_EQUALT_OR_EQUALT_XOR_EQUALT_SL_EQUALT_SR_EQUALT_BOOLEAN_ORT_BOOLEAN_ANDT_POWT_SLT_SRT_IS_IDENTICALT_IS_NOT_IDENTICALT_IS_EQUALT_IS_NOT_EQUALT_IS_SMALLER_OR_EQUALT_IS_GREATER_OR_EQUAL"
var _LexerToken_index = [...]uint16{0, 9, 23, 29, 33, 42, 51, 59, 75, 85, 97, 110, 121, 136, 161, 187, 193, 197, 204, 214, 219, 227, 236, 248, 257, 269, 273, 281, 292, 298, 307, 314, 324, 330, 340, 347, 355, 360, 367, 376, 383, 388, 399, 407, 412, 419, 426, 433, 448, 455, 462, 473, 482, 494, 511, 525, 531, 538, 548, 557, 566, 576, 584, 590, 596, 605, 618, 628, 648, 659, 671, 686, 699, 725, 737, 759, 770, 776, 781, 795, 805, 811, 820, 834, 846, 859, 872, 884, 889, 896, 904, 910, 917, 924, 931, 939, 949, 956, 965, 976, 984, 989, 994, 1006, 1016, 1029, 1042, 1054, 1067, 1078, 1090, 1100, 1111, 1119, 1131, 1144, 1155, 1166, 1177, 1191, 1202, 1213, 1223, 1234, 1244, 1254, 1266, 1279, 1284, 1288, 1292, 1306, 1324, 1334, 1348, 1369, 1390}
func (i LexerToken) String() string {
i -= 57346
if i < 0 || i >= LexerToken(len(_LexerToken_index)-1) {
return "LexerToken(" + strconv.FormatInt(int64(i+57346), 10) + ")"
}
return _LexerToken_name[_LexerToken_index[i]:_LexerToken_index[i+1]]
}

25
scanner/newline.go Normal file
View File

@ -0,0 +1,25 @@
package scanner
type NewLines struct {
data []int
}
func (nl *NewLines) Append(p int) {
if len(nl.data) == 0 || nl.data[len(nl.data)-1] < p {
nl.data = append(nl.data, p)
}
}
func (nl *NewLines) GetLine(p int) int {
line := len(nl.data) + 1
for i := len(nl.data) - 1; i >= 0; i-- {
if p < nl.data[i] {
line = i + 1
} else {
break
}
}
return line
}

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