feat: add start column and end column to position struct
This commit is contained in:
@@ -10,7 +10,7 @@ import (
|
||||
)
|
||||
|
||||
func TestConstructor(t *testing.T) {
|
||||
pos := position.NewPosition(1, 2, 3, 4)
|
||||
pos := position.NewPosition(1, 2, 3, 4, 1, 2)
|
||||
|
||||
actual := errors.NewError("message", pos)
|
||||
|
||||
@@ -23,7 +23,7 @@ func TestConstructor(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestPrint(t *testing.T) {
|
||||
pos := position.NewPosition(1, 2, 3, 4)
|
||||
pos := position.NewPosition(1, 2, 3, 4, 1, 2)
|
||||
|
||||
Error := errors.NewError("message", pos)
|
||||
|
||||
|
||||
@@ -1,19 +1,64 @@
|
||||
package position
|
||||
|
||||
// Tests that were written before the addition of StartCol and EndCol can set this to false,
|
||||
// Which will not check if StartCol or EndCol are equal in the Equal function.
|
||||
var CheckColEquality = true
|
||||
|
||||
// Position represents node position
|
||||
type Position struct {
|
||||
StartLine int
|
||||
EndLine int
|
||||
StartCol int
|
||||
EndCol int
|
||||
StartPos int
|
||||
EndPos int
|
||||
}
|
||||
|
||||
// NewPosition Position constructor
|
||||
func NewPosition(StartLine int, EndLine int, StartPos int, EndPos int) *Position {
|
||||
func NewPosition(
|
||||
StartLine int,
|
||||
EndLine int,
|
||||
StartPos int,
|
||||
EndPos int,
|
||||
StartCol int,
|
||||
EndCol int,
|
||||
) *Position {
|
||||
return &Position{
|
||||
StartLine: StartLine,
|
||||
EndLine: EndLine,
|
||||
StartPos: StartPos,
|
||||
EndPos: EndPos,
|
||||
StartCol: StartCol,
|
||||
EndCol: EndCol,
|
||||
}
|
||||
}
|
||||
|
||||
func (p Position) Equal(other Position) bool {
|
||||
if p.StartLine != other.StartLine {
|
||||
return false
|
||||
}
|
||||
|
||||
if p.StartPos != other.StartPos {
|
||||
return false
|
||||
}
|
||||
|
||||
if p.EndLine != other.EndLine {
|
||||
return false
|
||||
}
|
||||
|
||||
if p.EndPos != other.EndPos {
|
||||
return false
|
||||
}
|
||||
|
||||
if CheckColEquality {
|
||||
if p.StartCol != other.StartCol {
|
||||
return false
|
||||
}
|
||||
|
||||
if p.EndCol != other.EndCol {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -148,6 +148,8 @@ func (v *Dumper) dumpPosition(pos *position.Position) {
|
||||
|
||||
v.print(v.indent, "StartLine: "+strconv.Itoa(pos.StartLine)+",\n")
|
||||
v.print(v.indent, "EndLine: "+strconv.Itoa(pos.EndLine)+",\n")
|
||||
v.print(v.indent, "StartCol: "+strconv.Itoa(pos.StartCol)+",\n")
|
||||
v.print(v.indent, "EndCol: "+strconv.Itoa(pos.EndCol)+",\n")
|
||||
v.print(v.indent, "StartPos: "+strconv.Itoa(pos.StartPos)+",\n")
|
||||
v.print(v.indent, "EndPos: "+strconv.Itoa(pos.EndPos)+",\n")
|
||||
|
||||
|
||||
@@ -2,10 +2,11 @@ package dumper_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"testing"
|
||||
|
||||
"github.com/VKCOM/php-parser/pkg/position"
|
||||
"github.com/VKCOM/php-parser/pkg/token"
|
||||
"github.com/VKCOM/php-parser/pkg/visitor/dumper"
|
||||
"testing"
|
||||
|
||||
"github.com/VKCOM/php-parser/pkg/ast"
|
||||
)
|
||||
@@ -45,6 +46,8 @@ func TestDumper_root(t *testing.T) {
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
EndLine: 2,
|
||||
StartCol: 0,
|
||||
EndCol: 0,
|
||||
StartPos: 3,
|
||||
EndPos: 4,
|
||||
},
|
||||
@@ -60,6 +63,8 @@ func TestDumper_root(t *testing.T) {
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
EndLine: 2,
|
||||
StartCol: 0,
|
||||
EndCol: 0,
|
||||
StartPos: 3,
|
||||
EndPos: 4,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user