2019-12-26 15:57:56 +00:00
|
|
|
package positionbuilder_test
|
2018-02-18 11:51:03 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/z7zmey/php-parser/node"
|
|
|
|
"github.com/z7zmey/php-parser/position"
|
2019-12-26 15:57:56 +00:00
|
|
|
"github.com/z7zmey/php-parser/positionbuilder"
|
2018-02-18 11:51:03 +00:00
|
|
|
|
2018-04-15 11:47:40 +00:00
|
|
|
"github.com/z7zmey/php-parser/scanner"
|
2018-02-18 11:51:03 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestNewTokenPosition(t *testing.T) {
|
2019-12-26 15:57:56 +00:00
|
|
|
builder := positionbuilder.PositionBuilder{}
|
2018-02-18 11:51:03 +00:00
|
|
|
|
2018-06-10 23:41:12 +00:00
|
|
|
tkn := &scanner.Token{
|
2018-06-24 07:19:44 +00:00
|
|
|
Value: `foo`,
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
|
|
|
StartPos: 0,
|
|
|
|
EndPos: 3,
|
2018-06-10 23:41:12 +00:00
|
|
|
}
|
2018-02-18 11:51:03 +00:00
|
|
|
|
|
|
|
pos := builder.NewTokenPosition(tkn)
|
|
|
|
|
|
|
|
if pos.String() != `Pos{Line: 1-1 Pos: 0-3}` {
|
|
|
|
t.Errorf("token value is not equal\n")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNewTokensPosition(t *testing.T) {
|
2019-12-26 15:57:56 +00:00
|
|
|
builder := positionbuilder.PositionBuilder{}
|
2018-02-18 11:51:03 +00:00
|
|
|
|
2018-06-10 23:41:12 +00:00
|
|
|
token1 := &scanner.Token{
|
2018-06-24 07:19:44 +00:00
|
|
|
Value: `foo`,
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
|
|
|
StartPos: 0,
|
|
|
|
EndPos: 3,
|
2018-06-10 23:41:12 +00:00
|
|
|
}
|
|
|
|
token2 := &scanner.Token{
|
2018-06-24 07:19:44 +00:00
|
|
|
Value: `foo`,
|
|
|
|
StartLine: 2,
|
|
|
|
EndLine: 2,
|
|
|
|
StartPos: 4,
|
|
|
|
EndPos: 6,
|
2018-06-10 23:41:12 +00:00
|
|
|
}
|
2018-02-18 11:51:03 +00:00
|
|
|
|
|
|
|
pos := builder.NewTokensPosition(token1, token2)
|
|
|
|
|
|
|
|
if pos.String() != `Pos{Line: 1-2 Pos: 0-6}` {
|
|
|
|
t.Errorf("token value is not equal\n")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNewNodePosition(t *testing.T) {
|
|
|
|
n := node.NewIdentifier("test node")
|
2018-06-24 07:19:44 +00:00
|
|
|
n.SetPosition(&position.Position{
|
2018-02-18 11:51:03 +00:00
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
|
|
|
StartPos: 0,
|
|
|
|
EndPos: 3,
|
|
|
|
})
|
|
|
|
|
2019-12-26 15:57:56 +00:00
|
|
|
builder := positionbuilder.PositionBuilder{}
|
2018-02-18 11:51:03 +00:00
|
|
|
|
|
|
|
pos := builder.NewNodePosition(n)
|
|
|
|
|
|
|
|
if pos.String() != `Pos{Line: 1-1 Pos: 0-3}` {
|
|
|
|
t.Errorf("token value is not equal\n")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNewTokenNodePosition(t *testing.T) {
|
2018-06-10 23:41:12 +00:00
|
|
|
tkn := &scanner.Token{
|
2018-06-24 07:19:44 +00:00
|
|
|
Value: `foo`,
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
|
|
|
StartPos: 0,
|
|
|
|
EndPos: 3,
|
2018-06-10 23:41:12 +00:00
|
|
|
}
|
2018-02-18 11:51:03 +00:00
|
|
|
n := node.NewIdentifier("test node")
|
2018-06-24 07:19:44 +00:00
|
|
|
n.SetPosition(&position.Position{
|
2018-02-18 11:51:03 +00:00
|
|
|
StartLine: 2,
|
|
|
|
EndLine: 2,
|
|
|
|
StartPos: 4,
|
|
|
|
EndPos: 12,
|
|
|
|
})
|
|
|
|
|
2019-12-26 15:57:56 +00:00
|
|
|
builder := positionbuilder.PositionBuilder{}
|
2018-02-18 11:51:03 +00:00
|
|
|
|
|
|
|
pos := builder.NewTokenNodePosition(tkn, n)
|
|
|
|
|
|
|
|
if pos.String() != `Pos{Line: 1-2 Pos: 0-12}` {
|
|
|
|
t.Errorf("token value is not equal\n")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNewNodeTokenPosition(t *testing.T) {
|
|
|
|
n := node.NewIdentifier("test node")
|
2018-06-24 07:19:44 +00:00
|
|
|
n.SetPosition(&position.Position{
|
2018-02-18 11:51:03 +00:00
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
|
|
|
StartPos: 0,
|
|
|
|
EndPos: 9,
|
|
|
|
})
|
|
|
|
|
2018-06-24 07:19:44 +00:00
|
|
|
tkn := &scanner.Token{
|
|
|
|
Value: `foo`,
|
|
|
|
StartLine: 2,
|
|
|
|
EndLine: 2,
|
|
|
|
StartPos: 10,
|
|
|
|
EndPos: 12,
|
2018-02-18 11:51:03 +00:00
|
|
|
}
|
|
|
|
|
2019-12-26 15:57:56 +00:00
|
|
|
builder := positionbuilder.PositionBuilder{}
|
2018-06-24 07:19:44 +00:00
|
|
|
|
2018-02-18 11:51:03 +00:00
|
|
|
pos := builder.NewNodeTokenPosition(n, tkn)
|
|
|
|
|
|
|
|
if pos.String() != `Pos{Line: 1-2 Pos: 0-12}` {
|
|
|
|
t.Errorf("token value is not equal\n")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNewNodeListPosition(t *testing.T) {
|
|
|
|
n1 := node.NewIdentifier("test node")
|
2018-06-24 07:19:44 +00:00
|
|
|
n1.SetPosition(&position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
|
|
|
StartPos: 0,
|
|
|
|
EndPos: 9,
|
|
|
|
})
|
|
|
|
|
2018-02-18 11:51:03 +00:00
|
|
|
n2 := node.NewIdentifier("test node")
|
2018-06-24 07:19:44 +00:00
|
|
|
n2.SetPosition(&position.Position{
|
|
|
|
StartLine: 2,
|
|
|
|
EndLine: 2,
|
|
|
|
StartPos: 10,
|
|
|
|
EndPos: 19,
|
|
|
|
})
|
2018-02-18 11:51:03 +00:00
|
|
|
|
2019-12-26 15:57:56 +00:00
|
|
|
builder := positionbuilder.PositionBuilder{}
|
2018-02-18 11:51:03 +00:00
|
|
|
|
|
|
|
pos := builder.NewNodeListPosition([]node.Node{n1, n2})
|
|
|
|
|
|
|
|
if pos.String() != `Pos{Line: 1-2 Pos: 0-19}` {
|
|
|
|
t.Errorf("token value is not equal\n")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNewNodesPosition(t *testing.T) {
|
|
|
|
n1 := node.NewIdentifier("test node")
|
2018-06-24 07:19:44 +00:00
|
|
|
n1.SetPosition(&position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
|
|
|
StartPos: 0,
|
|
|
|
EndPos: 9,
|
|
|
|
})
|
|
|
|
|
2018-02-18 11:51:03 +00:00
|
|
|
n2 := node.NewIdentifier("test node")
|
2018-06-24 07:19:44 +00:00
|
|
|
n2.SetPosition(&position.Position{
|
|
|
|
StartLine: 2,
|
|
|
|
EndLine: 2,
|
|
|
|
StartPos: 10,
|
|
|
|
EndPos: 19,
|
|
|
|
})
|
2018-02-18 11:51:03 +00:00
|
|
|
|
2019-12-26 15:57:56 +00:00
|
|
|
builder := positionbuilder.PositionBuilder{}
|
2018-02-18 11:51:03 +00:00
|
|
|
|
|
|
|
pos := builder.NewNodesPosition(n1, n2)
|
|
|
|
|
|
|
|
if pos.String() != `Pos{Line: 1-2 Pos: 0-19}` {
|
|
|
|
t.Errorf("token value is not equal\n")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNewNodeListTokenPosition(t *testing.T) {
|
|
|
|
n1 := node.NewIdentifier("test node")
|
2018-06-24 07:19:44 +00:00
|
|
|
n1.SetPosition(&position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
|
|
|
StartPos: 0,
|
|
|
|
EndPos: 9,
|
|
|
|
})
|
|
|
|
|
2018-02-18 11:51:03 +00:00
|
|
|
n2 := node.NewIdentifier("test node")
|
2018-06-24 07:19:44 +00:00
|
|
|
n2.SetPosition(&position.Position{
|
|
|
|
StartLine: 2,
|
|
|
|
EndLine: 2,
|
|
|
|
StartPos: 10,
|
|
|
|
EndPos: 19,
|
|
|
|
})
|
|
|
|
|
2018-06-10 23:41:12 +00:00
|
|
|
tkn := &scanner.Token{
|
2018-06-24 07:19:44 +00:00
|
|
|
Value: `foo`,
|
|
|
|
StartLine: 3,
|
|
|
|
EndLine: 3,
|
|
|
|
StartPos: 20,
|
|
|
|
EndPos: 22,
|
2018-06-10 23:41:12 +00:00
|
|
|
}
|
2018-02-18 11:51:03 +00:00
|
|
|
|
2019-12-26 15:57:56 +00:00
|
|
|
builder := positionbuilder.PositionBuilder{}
|
2018-02-18 11:51:03 +00:00
|
|
|
|
|
|
|
pos := builder.NewNodeListTokenPosition([]node.Node{n1, n2}, tkn)
|
|
|
|
|
|
|
|
if pos.String() != `Pos{Line: 1-3 Pos: 0-22}` {
|
|
|
|
t.Errorf("token value is not equal\n")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNewTokenNodeListPosition(t *testing.T) {
|
2018-06-10 23:41:12 +00:00
|
|
|
tkn := &scanner.Token{
|
2018-06-24 07:19:44 +00:00
|
|
|
Value: `foo`,
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
|
|
|
StartPos: 0,
|
|
|
|
EndPos: 2,
|
2018-06-10 23:41:12 +00:00
|
|
|
}
|
2018-06-24 07:19:44 +00:00
|
|
|
|
2018-02-18 11:51:03 +00:00
|
|
|
n1 := node.NewIdentifier("test node")
|
2018-06-24 07:19:44 +00:00
|
|
|
n1.SetPosition(&position.Position{
|
|
|
|
StartLine: 2,
|
|
|
|
EndLine: 2,
|
|
|
|
StartPos: 3,
|
|
|
|
EndPos: 10,
|
|
|
|
})
|
|
|
|
|
2018-02-18 11:51:03 +00:00
|
|
|
n2 := node.NewIdentifier("test node")
|
2018-06-24 07:19:44 +00:00
|
|
|
n2.SetPosition(&position.Position{
|
|
|
|
StartLine: 3,
|
|
|
|
EndLine: 3,
|
|
|
|
StartPos: 11,
|
|
|
|
EndPos: 20,
|
|
|
|
})
|
2018-02-18 11:51:03 +00:00
|
|
|
|
2019-12-26 15:57:56 +00:00
|
|
|
builder := positionbuilder.PositionBuilder{}
|
2018-02-18 11:51:03 +00:00
|
|
|
|
|
|
|
pos := builder.NewTokenNodeListPosition(tkn, []node.Node{n1, n2})
|
|
|
|
|
|
|
|
if pos.String() != `Pos{Line: 1-3 Pos: 0-20}` {
|
|
|
|
t.Errorf("token value is not equal\n")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNewNodeNodeListPosition(t *testing.T) {
|
|
|
|
n1 := node.NewIdentifier("test node")
|
2018-06-24 07:19:44 +00:00
|
|
|
n1.SetPosition(&position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
|
|
|
StartPos: 0,
|
|
|
|
EndPos: 8,
|
|
|
|
})
|
|
|
|
|
2018-02-18 11:51:03 +00:00
|
|
|
n2 := node.NewIdentifier("test node")
|
2018-06-24 07:19:44 +00:00
|
|
|
n2.SetPosition(&position.Position{
|
|
|
|
StartLine: 2,
|
|
|
|
EndLine: 2,
|
|
|
|
StartPos: 9,
|
|
|
|
EndPos: 17,
|
|
|
|
})
|
|
|
|
|
2018-02-18 11:51:03 +00:00
|
|
|
n3 := node.NewIdentifier("test node")
|
2018-06-24 07:19:44 +00:00
|
|
|
n3.SetPosition(&position.Position{
|
|
|
|
StartLine: 3,
|
|
|
|
EndLine: 3,
|
|
|
|
StartPos: 18,
|
|
|
|
EndPos: 26,
|
|
|
|
})
|
2018-02-18 11:51:03 +00:00
|
|
|
|
2019-12-26 15:57:56 +00:00
|
|
|
builder := positionbuilder.PositionBuilder{}
|
2018-02-18 11:51:03 +00:00
|
|
|
|
|
|
|
pos := builder.NewNodeNodeListPosition(n1, []node.Node{n2, n3})
|
|
|
|
|
|
|
|
if pos.String() != `Pos{Line: 1-3 Pos: 0-26}` {
|
|
|
|
t.Errorf("token value is not equal\n")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-03 06:35:44 +00:00
|
|
|
func TestNewNodeListNodePosition(t *testing.T) {
|
|
|
|
n1 := node.NewIdentifier("test node")
|
2018-06-24 07:19:44 +00:00
|
|
|
n1.SetPosition(&position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
|
|
|
StartPos: 0,
|
|
|
|
EndPos: 8,
|
|
|
|
})
|
2018-06-03 06:35:44 +00:00
|
|
|
n2 := node.NewIdentifier("test node")
|
2018-06-24 07:19:44 +00:00
|
|
|
n2.SetPosition(&position.Position{
|
|
|
|
StartLine: 2,
|
|
|
|
EndLine: 2,
|
|
|
|
StartPos: 9,
|
|
|
|
EndPos: 17,
|
|
|
|
})
|
2018-06-03 06:35:44 +00:00
|
|
|
n3 := node.NewIdentifier("test node")
|
2018-06-24 07:19:44 +00:00
|
|
|
n3.SetPosition(&position.Position{
|
|
|
|
StartLine: 3,
|
|
|
|
EndLine: 3,
|
|
|
|
StartPos: 18,
|
|
|
|
EndPos: 26,
|
|
|
|
})
|
2018-06-03 06:35:44 +00:00
|
|
|
|
2019-12-26 15:57:56 +00:00
|
|
|
builder := positionbuilder.PositionBuilder{}
|
2018-06-03 06:35:44 +00:00
|
|
|
|
|
|
|
pos := builder.NewNodeListNodePosition([]node.Node{n1, n2}, n3)
|
|
|
|
|
|
|
|
if pos.String() != `Pos{Line: 1-3 Pos: 0-26}` {
|
|
|
|
t.Errorf("token value is not equal\n")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-18 11:51:03 +00:00
|
|
|
func TestNewOptionalListTokensPosition(t *testing.T) {
|
2019-12-26 15:57:56 +00:00
|
|
|
builder := positionbuilder.PositionBuilder{}
|
2018-02-18 11:51:03 +00:00
|
|
|
|
2018-06-10 23:41:12 +00:00
|
|
|
token1 := &scanner.Token{
|
2018-06-24 07:19:44 +00:00
|
|
|
Value: `foo`,
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
|
|
|
StartPos: 0,
|
|
|
|
EndPos: 3,
|
2018-06-10 23:41:12 +00:00
|
|
|
}
|
|
|
|
token2 := &scanner.Token{
|
2018-06-24 07:19:44 +00:00
|
|
|
Value: `foo`,
|
|
|
|
StartLine: 2,
|
|
|
|
EndLine: 2,
|
|
|
|
StartPos: 4,
|
|
|
|
EndPos: 6,
|
2018-06-10 23:41:12 +00:00
|
|
|
}
|
2018-02-18 11:51:03 +00:00
|
|
|
|
|
|
|
pos := builder.NewOptionalListTokensPosition(nil, token1, token2)
|
|
|
|
|
|
|
|
if pos.String() != `Pos{Line: 1-2 Pos: 0-6}` {
|
|
|
|
t.Errorf("token value is not equal\n")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNewOptionalListTokensPosition2(t *testing.T) {
|
|
|
|
n1 := node.NewIdentifier("test node")
|
2018-06-24 07:19:44 +00:00
|
|
|
n1.SetPosition(&position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
|
|
|
StartPos: 0,
|
|
|
|
EndPos: 8,
|
|
|
|
})
|
2018-02-18 11:51:03 +00:00
|
|
|
n2 := node.NewIdentifier("test node")
|
2018-06-24 07:19:44 +00:00
|
|
|
n2.SetPosition(&position.Position{
|
|
|
|
StartLine: 2,
|
|
|
|
EndLine: 2,
|
|
|
|
StartPos: 9,
|
|
|
|
EndPos: 17,
|
|
|
|
})
|
2018-02-18 11:51:03 +00:00
|
|
|
n3 := node.NewIdentifier("test node")
|
2018-06-24 07:19:44 +00:00
|
|
|
n3.SetPosition(&position.Position{
|
|
|
|
StartLine: 3,
|
|
|
|
EndLine: 3,
|
|
|
|
StartPos: 18,
|
|
|
|
EndPos: 26,
|
|
|
|
})
|
2018-02-18 11:51:03 +00:00
|
|
|
|
2019-12-26 15:57:56 +00:00
|
|
|
builder := positionbuilder.PositionBuilder{}
|
2018-02-18 11:51:03 +00:00
|
|
|
|
2018-06-10 23:41:12 +00:00
|
|
|
token1 := &scanner.Token{
|
2018-06-24 07:19:44 +00:00
|
|
|
Value: `foo`,
|
|
|
|
StartLine: 4,
|
|
|
|
EndLine: 4,
|
|
|
|
StartPos: 27,
|
|
|
|
EndPos: 29,
|
2018-06-10 23:41:12 +00:00
|
|
|
}
|
|
|
|
token2 := &scanner.Token{
|
2018-06-24 07:19:44 +00:00
|
|
|
Value: `foo`,
|
|
|
|
StartLine: 5,
|
|
|
|
EndLine: 5,
|
|
|
|
StartPos: 30,
|
|
|
|
EndPos: 32,
|
2018-06-10 23:41:12 +00:00
|
|
|
}
|
2018-02-18 11:51:03 +00:00
|
|
|
|
|
|
|
pos := builder.NewOptionalListTokensPosition([]node.Node{n2, n3}, token1, token2)
|
|
|
|
|
|
|
|
if pos.String() != `Pos{Line: 2-5 Pos: 9-32}` {
|
|
|
|
t.Errorf("token value is not equal\n")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNilNodePos(t *testing.T) {
|
2019-12-26 15:57:56 +00:00
|
|
|
builder := positionbuilder.PositionBuilder{}
|
2018-02-18 11:51:03 +00:00
|
|
|
|
|
|
|
pos := builder.NewNodesPosition(nil, nil)
|
|
|
|
|
|
|
|
if pos.String() != `Pos{Line: -1--1 Pos: -1--1}` {
|
|
|
|
t.Errorf("token value is not equal\n")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNilNodeListPos(t *testing.T) {
|
|
|
|
n1 := node.NewIdentifier("test node")
|
2018-06-24 07:19:44 +00:00
|
|
|
n1.SetPosition(&position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
|
|
|
StartPos: 0,
|
|
|
|
EndPos: 8,
|
|
|
|
})
|
2018-02-18 11:51:03 +00:00
|
|
|
|
2019-12-26 15:57:56 +00:00
|
|
|
builder := positionbuilder.PositionBuilder{}
|
2018-02-18 11:51:03 +00:00
|
|
|
|
|
|
|
pos := builder.NewNodeNodeListPosition(n1, nil)
|
|
|
|
|
|
|
|
if pos.String() != `Pos{Line: 1--1 Pos: 0--1}` {
|
|
|
|
t.Errorf("token value is not equal\n")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNilNodeListTokenPos(t *testing.T) {
|
2018-06-10 23:41:12 +00:00
|
|
|
token := &scanner.Token{
|
2018-06-24 07:19:44 +00:00
|
|
|
Value: `foo`,
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
|
|
|
StartPos: 0,
|
|
|
|
EndPos: 3,
|
2018-06-10 23:41:12 +00:00
|
|
|
}
|
2018-02-18 11:51:03 +00:00
|
|
|
|
2019-12-26 15:57:56 +00:00
|
|
|
builder := positionbuilder.PositionBuilder{}
|
2018-02-18 11:51:03 +00:00
|
|
|
|
2018-06-10 23:41:12 +00:00
|
|
|
pos := builder.NewNodeListTokenPosition(nil, token)
|
2018-02-18 11:51:03 +00:00
|
|
|
|
|
|
|
if pos.String() != `Pos{Line: -1-1 Pos: -1-3}` {
|
|
|
|
t.Errorf("token value is not equal\n")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestEmptyNodeListPos(t *testing.T) {
|
|
|
|
n1 := node.NewIdentifier("test node")
|
2018-06-24 07:19:44 +00:00
|
|
|
n1.SetPosition(&position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
|
|
|
StartPos: 0,
|
|
|
|
EndPos: 8,
|
|
|
|
})
|
2018-02-18 11:51:03 +00:00
|
|
|
|
2019-12-26 15:57:56 +00:00
|
|
|
builder := positionbuilder.PositionBuilder{}
|
2018-02-18 11:51:03 +00:00
|
|
|
|
|
|
|
pos := builder.NewNodeNodeListPosition(n1, []node.Node{})
|
|
|
|
|
|
|
|
if pos.String() != `Pos{Line: 1--1 Pos: 0--1}` {
|
|
|
|
t.Errorf("token value is not equal\n")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestEmptyNodeListTokenPos(t *testing.T) {
|
2018-06-10 23:41:12 +00:00
|
|
|
token := &scanner.Token{
|
2018-06-24 07:19:44 +00:00
|
|
|
Value: `foo`,
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
|
|
|
StartPos: 0,
|
|
|
|
EndPos: 3,
|
2018-06-10 23:41:12 +00:00
|
|
|
}
|
2018-02-18 11:51:03 +00:00
|
|
|
|
2019-12-26 15:57:56 +00:00
|
|
|
builder := positionbuilder.PositionBuilder{}
|
2018-02-18 11:51:03 +00:00
|
|
|
|
2018-06-10 23:41:12 +00:00
|
|
|
pos := builder.NewNodeListTokenPosition([]node.Node{}, token)
|
2018-02-18 11:51:03 +00:00
|
|
|
|
|
|
|
if pos.String() != `Pos{Line: -1-1 Pos: -1-3}` {
|
|
|
|
t.Errorf("token value is not equal\n")
|
|
|
|
}
|
|
|
|
}
|