This repository has been archived on 2026-10-03. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files

49 lines
963 B
Go
Raw Permalink Normal View History

2023-10-07 10:22:56 +01:00
package arango
import "testing"
func TestReadParams(t *testing.T) {
type TestCase struct {
Input string
Output []string
}
testCases := []TestCase{
2023-10-08 15:55:20 +01:00
{
Input: "FOR doc IN recipes FILTER doc.title == \"Spaghetti\" RETURN doc",
},
{
Input: "FOR doc IN recipes FILTER doc.title == @title RETURN doc",
Output: []string{"title"},
},
2023-10-07 10:22:56 +01:00
{
Input: "FOR doc IN @@collection FILTER doc.title == @title RETURN doc",
2023-10-13 07:59:04 +01:00
Output: []string{"@collection", "title"},
2023-10-07 10:22:56 +01:00
},
}
2023-10-08 16:20:21 +01:00
for n, tc := range testCases {
t.Logf("(%d) Testing %q", n, tc.Input)
2023-10-07 10:22:56 +01:00
2023-10-07 10:44:47 +01:00
params := ReadParams(tc.Input)
2023-10-07 10:22:56 +01:00
2023-10-08 15:55:20 +01:00
if params == nil {
t.Errorf("Expected empty slice, got nil")
continue
}
2023-10-08 16:04:03 +01:00
2023-10-07 10:44:47 +01:00
if len(params) != len(tc.Output) {
t.Errorf("Expected %d parameters", len(tc.Output))
2023-10-07 10:22:56 +01:00
}
2023-10-07 10:44:47 +01:00
for i, name := range tc.Output {
2023-10-08 15:55:20 +01:00
if i == len(params) {
break
}
if name != params[i] {
t.Errorf("Expected %s for parameter %d, got %s", name, i, params[i])
2023-10-07 10:22:56 +01:00
}
}
}
}