(t *testing.T)
| 130 | } |
| 131 | |
| 132 | func TestIntervalDuration(t *testing.T) { |
| 133 | tests := []struct { |
| 134 | name string |
| 135 | start int64 |
| 136 | end int64 |
| 137 | want int64 |
| 138 | wantErr bool |
| 139 | }{ |
| 140 | { |
| 141 | name: "simple interval", |
| 142 | start: 1000, |
| 143 | end: 2000, |
| 144 | want: 1000, |
| 145 | }, |
| 146 | { |
| 147 | name: "point interval", |
| 148 | start: 1500, |
| 149 | end: 1500, |
| 150 | want: 0, |
| 151 | }, |
| 152 | { |
| 153 | name: "large duration", |
| 154 | start: 0, |
| 155 | end: 1000000000, // 1 second in nanoseconds |
| 156 | want: 1000000000, |
| 157 | }, |
| 158 | } |
| 159 | |
| 160 | for _, tc := range tests { |
| 161 | t.Run(tc.name, func(t *testing.T) { |
| 162 | startConst := ast.Time(tc.start) |
| 163 | endConst := ast.Time(tc.end) |
| 164 | interval := ast.Pair(&startConst, &endConst) |
| 165 | |
| 166 | result, err := EvalApplyFn(ast.ApplyFn{ |
| 167 | Function: symbols.IntervalDuration, |
| 168 | Args: []ast.BaseTerm{interval}, |
| 169 | }, nil) |
| 170 | |
| 171 | if (err != nil) != tc.wantErr { |
| 172 | t.Fatalf("EvalApplyFn() error = %v, wantErr %v", err, tc.wantErr) |
| 173 | } |
| 174 | if err != nil { |
| 175 | return |
| 176 | } |
| 177 | |
| 178 | got, err := result.DurationValue() |
| 179 | if err != nil { |
| 180 | t.Fatalf("result.DurationValue() error = %v", err) |
| 181 | } |
| 182 | if got != tc.want { |
| 183 | t.Errorf("fn:interval:duration got %d, want %d", got, tc.want) |
| 184 | } |
| 185 | }) |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | func TestIntervalFunctionsErrors(t *testing.T) { |
nothing calls this directly
no test coverage detected