(t *testing.T)
| 28 | ) |
| 29 | |
| 30 | func TestValidateDurationLiterals(t *testing.T) { |
| 31 | env, err := NewEnv( |
| 32 | Variable("x", types.StringType), |
| 33 | ASTValidators(ValidateDurationLiterals())) |
| 34 | if err != nil { |
| 35 | t.Fatalf("NewEnv(ValidateDurationLiterals()) failed: %v", err) |
| 36 | } |
| 37 | |
| 38 | tests := []struct { |
| 39 | expr string |
| 40 | iss string |
| 41 | }{ |
| 42 | { |
| 43 | expr: `duration('1')`, |
| 44 | iss: `ERROR: <input>:1:10: invalid duration argument |
| 45 | | duration('1') |
| 46 | | .........^`, |
| 47 | }, |
| 48 | { |
| 49 | expr: `duration('1d')`, |
| 50 | iss: `ERROR: <input>:1:10: invalid duration argument |
| 51 | | duration('1d') |
| 52 | | .........^`, |
| 53 | }, |
| 54 | { |
| 55 | expr: "duration('1us')\n < duration('1nns')", |
| 56 | iss: `ERROR: <input>:2:13: invalid duration argument |
| 57 | | < duration('1nns') |
| 58 | | ............^`, |
| 59 | }, |
| 60 | { |
| 61 | expr: `duration('2h3m4s5us')`, |
| 62 | }, |
| 63 | { |
| 64 | expr: `duration(x)`, |
| 65 | }, |
| 66 | } |
| 67 | for _, tst := range tests { |
| 68 | tc := tst |
| 69 | t.Run(tc.expr, func(t *testing.T) { |
| 70 | _, iss := env.Compile(tc.expr) |
| 71 | if tc.iss != "" { |
| 72 | if iss.Err() == nil { |
| 73 | t.Fatalf("e.Compile(%v) returned ast, expected error: %v", tc.expr, tc.iss) |
| 74 | } |
| 75 | if !test.Compare(iss.Err().Error(), tc.iss) { |
| 76 | t.Fatalf("e.Compile(%v) returned %v, expected error: %v", tc.expr, iss.Err(), tc.iss) |
| 77 | } |
| 78 | return |
| 79 | } |
| 80 | if iss.Err() != nil { |
| 81 | t.Fatalf("e.Compile(%v) failed: %v", tc.expr, iss.Err()) |
| 82 | } |
| 83 | }) |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | func TestValidateTimestampLiterals(t *testing.T) { |
nothing calls this directly
no test coverage detected