(t *testing.T)
| 10 | ) |
| 11 | |
| 12 | func TestErrors(t *testing.T) { |
| 13 | t.Run("unknown function", func(t *testing.T) { |
| 14 | in := model.NewNullValue() |
| 15 | _, err := execution.ExecuteSelector(context.Background(), `unknownFunc123()`, in, execution.NewOptions()) |
| 16 | if err == nil { |
| 17 | t.Fatal("expected error for unknown function") |
| 18 | } |
| 19 | if !strings.Contains(err.Error(), "unknown function") { |
| 20 | t.Fatalf("unexpected error: %s", err) |
| 21 | } |
| 22 | }) |
| 23 | |
| 24 | t.Run("empty selector returns input", func(t *testing.T) { |
| 25 | in := model.NewStringValue("hello") |
| 26 | res, err := execution.ExecuteSelector(context.Background(), ``, in, execution.NewOptions()) |
| 27 | if err != nil { |
| 28 | t.Fatal(err) |
| 29 | } |
| 30 | got, err := res.StringValue() |
| 31 | if err != nil { |
| 32 | t.Fatal(err) |
| 33 | } |
| 34 | if got != "hello" { |
| 35 | t.Errorf("expected 'hello', got %s", got) |
| 36 | } |
| 37 | }) |
| 38 | |
| 39 | t.Run("filter on non-array", func(t *testing.T) { |
| 40 | in := model.NewStringValue("not a slice") |
| 41 | _, err := execution.ExecuteSelector(context.Background(), `filter($this == "x")`, in, execution.NewOptions()) |
| 42 | if err == nil { |
| 43 | t.Fatal("expected error for filter on non-array") |
| 44 | } |
| 45 | }) |
| 46 | |
| 47 | t.Run("each on non-array", func(t *testing.T) { |
| 48 | in := model.NewStringValue("not a slice") |
| 49 | _, err := execution.ExecuteSelector(context.Background(), `each($this = $this)`, in, execution.NewOptions()) |
| 50 | if err == nil { |
| 51 | t.Fatal("expected error for each on non-array") |
| 52 | } |
| 53 | }) |
| 54 | |
| 55 | t.Run("sortBy on non-array", func(t *testing.T) { |
| 56 | in := model.NewStringValue("not a slice") |
| 57 | _, err := execution.ExecuteSelector(context.Background(), `sortBy($this)`, in, execution.NewOptions()) |
| 58 | if err == nil { |
| 59 | t.Fatal("expected error for sortBy on non-array") |
| 60 | } |
| 61 | }) |
| 62 | |
| 63 | t.Run("map on non-array", func(t *testing.T) { |
| 64 | in := model.NewStringValue("not a slice") |
| 65 | _, err := execution.ExecuteSelector(context.Background(), `map($this)`, in, execution.NewOptions()) |
| 66 | if err == nil { |
| 67 | t.Fatal("expected error for map on non-array") |
| 68 | } |
| 69 | }) |
nothing calls this directly
no test coverage detected