MCPcopy
hub / github.com/expr-lang/expr / TestTime

Function TestTime

test/time/time_test.go:18–104  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

16)
17
18func TestTime(t *testing.T) {
19 testTime := time.Date(2000, time.Month(1), 1, 0, 0, 0, 0, time.UTC)
20 testDuration := time.Duration(1)
21
22 tests := []struct {
23 a any
24 b any
25 op string
26 want any
27 wantErr bool
28 }{
29 {a: testTime, b: testTime, op: "<", wantErr: false, want: false},
30 {a: testTime, b: testTime, op: ">", wantErr: false, want: false},
31 {a: testTime, b: testTime, op: "<=", wantErr: false, want: true},
32 {a: testTime, b: testTime, op: ">=", wantErr: false, want: true},
33 {a: testTime, b: testTime, op: "==", wantErr: false, want: true},
34 {a: testTime, b: testTime, op: "!=", wantErr: false, want: false},
35 {a: testTime, b: testTime, op: "-", wantErr: false},
36 {a: testTime, b: testDuration, op: "+", wantErr: false},
37 {a: testTime, b: testDuration, op: "-", wantErr: false},
38
39 // error cases
40 {a: testTime, b: int64(1), op: "<", wantErr: true},
41 {a: testTime, b: float64(1), op: "<", wantErr: true},
42 {a: testTime, b: testDuration, op: "<", wantErr: true},
43
44 {a: testTime, b: int64(1), op: ">", wantErr: true},
45 {a: testTime, b: float64(1), op: ">", wantErr: true},
46 {a: testTime, b: testDuration, op: ">", wantErr: true},
47
48 {a: testTime, b: int64(1), op: "<=", wantErr: true},
49 {a: testTime, b: float64(1), op: "<=", wantErr: true},
50 {a: testTime, b: testDuration, op: "<=", wantErr: true},
51
52 {a: testTime, b: int64(1), op: ">=", wantErr: true},
53 {a: testTime, b: float64(1), op: ">=", wantErr: true},
54 {a: testTime, b: testDuration, op: ">=", wantErr: true},
55
56 {a: testTime, b: int64(1), op: "==", wantErr: false, want: false},
57 {a: testTime, b: float64(1), op: "==", wantErr: false, want: false},
58 {a: testTime, b: testDuration, op: "==", wantErr: false, want: false},
59
60 {a: testTime, b: int64(1), op: "!=", wantErr: false, want: true},
61 {a: testTime, b: float64(1), op: "!=", wantErr: false, want: true},
62 {a: testTime, b: testDuration, op: "!=", wantErr: false, want: true},
63
64 {a: testTime, b: int64(1), op: "-", wantErr: true},
65 {a: testTime, b: float64(1), op: "-", wantErr: true},
66
67 {a: testTime, b: testTime, op: "+", wantErr: true},
68 {a: testTime, b: int64(1), op: "+", wantErr: true},
69 {a: testTime, b: float64(1), op: "+", wantErr: true},
70 {a: testDuration, b: testTime, op: "+", wantErr: false},
71 }
72
73 for _, tt := range tests {
74 t.Run(fmt.Sprintf("time helper test `%T %s %T`", tt.a, tt.op, tt.b), func(t *testing.T) {
75 input := fmt.Sprintf("a %v b", tt.op)

Callers

nothing calls this directly

Calls 11

CreateNewFunction · 0.92
ParseFunction · 0.92
NoErrorFunction · 0.92
CheckFunction · 0.92
CompileFunction · 0.92
RunFunction · 0.92
ErrorFunction · 0.92
EqualFunction · 0.92
DurationMethod · 0.80
RunMethod · 0.80
SprintfMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…