remove nodesWithEndToken type

This commit is contained in:
z7zmey
2018-06-03 09:35:44 +03:00
parent 2abe1dfb84
commit a488f43496
17 changed files with 1393 additions and 1251 deletions

View File

@@ -174,6 +174,16 @@ func (b *PositionBuilder) NewNodeNodeListPosition(n node.Node, list []node.Node)
)
}
// NewNodeListNodePosition returns new Position
func (b *PositionBuilder) NewNodeListNodePosition(list []node.Node, n node.Node) *position.Position {
return position.NewPosition(
b.getListStartPos(list).startLine,
b.getNodeEndPos(n).endLine,
b.getListStartPos(list).startPos,
b.getNodeEndPos(n).endPos,
)
}
// NewOptionalListTokensPosition returns new Position
func (b *PositionBuilder) NewOptionalListTokensPosition(list []node.Node, t *scanner.Token, endToken *scanner.Token) *position.Position {
if list == nil {

View File

@@ -259,6 +259,41 @@ func TestNewNodeNodeListPosition(t *testing.T) {
}
}
func TestNewNodeListNodePosition(t *testing.T) {
n1 := node.NewIdentifier("test node")
n2 := node.NewIdentifier("test node")
n3 := node.NewIdentifier("test node")
builder := parser.PositionBuilder{
Positions: &parser.Positions{
n1: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 0,
EndPos: 8,
},
n2: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 9,
EndPos: 17,
},
n3: &position.Position{
StartLine: 3,
EndLine: 3,
StartPos: 18,
EndPos: 26,
},
},
}
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")
}
}
func TestNewOptionalListTokensPosition(t *testing.T) {
builder := parser.PositionBuilder{}