Fix string literal slicing error (#543)

This commit is contained in:
Sergey
2024-01-31 18:07:26 +01:00
committed by GitHub
parent d645265cd1
commit a0e2fe3664
3 changed files with 13 additions and 2 deletions
+4
View File
@@ -1180,6 +1180,10 @@ func TestExpr(t *testing.T) {
`bitushr(-100, 5)`,
576460752303423484,
},
{
`"hello"[1:3]`,
"el",
},
}
for _, tt := range tests {
+1 -2
View File
@@ -369,9 +369,8 @@ func (p *parser) parseSecondary() Node {
return node
case String:
p.next()
node := &StringNode{Value: token.Value}
node = &StringNode{Value: token.Value}
node.SetLocation(token.Location)
return node
default:
if token.Is(Bracket, "[") {
+8
View File
@@ -523,6 +523,14 @@ world`},
Property: &IntegerNode{Value: 0},
},
},
{
`"hello"[1:3]`,
&SliceNode{
Node: &StringNode{Value: "hello"},
From: &IntegerNode{Value: 1},
To: &IntegerNode{Value: 3},
},
},
}
for _, test := range tests {
t.Run(test.input, func(t *testing.T) {