string like array access
Some checks failed
Build / build (push) Failing after 1m25s
Test / build (push) Has been cancelled

This commit is contained in:
Chuck Smith
2024-03-15 14:14:34 -04:00
parent 997f0865f4
commit d7938e59e4
4 changed files with 83 additions and 0 deletions

View File

@@ -647,3 +647,53 @@ func TestExamples(t *testing.T) {
testEval(string(b))
}
}
func TestStringIndexExpressions(t *testing.T) {
tests := []struct {
input string
expected interface{}
}{
{
`"abc"[0]`,
"a",
},
{
`"abc"[1]`,
"b",
},
{
`"abc"[2]`,
"c",
},
{
`let i = 0; "abc"[i];`,
"a",
},
{
`"abc"[1 + 1];`,
"c",
},
{
`let myString = "abc"; myString[0] + myString[1] + myString[2];`,
"abc",
},
{
`"abc"[3]`,
"",
},
{
`"foo"[-1]`,
"",
},
}
for _, tt := range tests {
evaluated := testEval(tt.input)
str, ok := tt.expected.(string)
if ok {
testStringObject(t, evaluated, string(str))
} else {
testNullObject(t, evaluated)
}
}
}