params_test.go 963 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package arango
  2. import "testing"
  3. func TestReadParams(t *testing.T) {
  4. type TestCase struct {
  5. Input string
  6. Output []string
  7. }
  8. testCases := []TestCase{
  9. {
  10. Input: "FOR doc IN recipes FILTER doc.title == \"Spaghetti\" RETURN doc",
  11. },
  12. {
  13. Input: "FOR doc IN recipes FILTER doc.title == @title RETURN doc",
  14. Output: []string{"title"},
  15. },
  16. {
  17. Input: "FOR doc IN @@collection FILTER doc.title == @title RETURN doc",
  18. Output: []string{"@collection", "title"},
  19. },
  20. }
  21. for n, tc := range testCases {
  22. t.Logf("(%d) Testing %q", n, tc.Input)
  23. params := ReadParams(tc.Input)
  24. if params == nil {
  25. t.Errorf("Expected empty slice, got nil")
  26. continue
  27. }
  28. if len(params) != len(tc.Output) {
  29. t.Errorf("Expected %d parameters", len(tc.Output))
  30. }
  31. for i, name := range tc.Output {
  32. if i == len(params) {
  33. break
  34. }
  35. if name != params[i] {
  36. t.Errorf("Expected %s for parameter %d, got %s", name, i, params[i])
  37. }
  38. }
  39. }
  40. }