MCPcopy Index your code
hub / github.com/google/mangle / TestIntervalDuration

Function TestIntervalDuration

functional/temporal_test.go:132–187  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

130}
131
132func 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
189func TestIntervalFunctionsErrors(t *testing.T) {

Callers

nothing calls this directly

Calls 4

TimeFunction · 0.92
PairFunction · 0.92
EvalApplyFnFunction · 0.85
DurationValueMethod · 0.80

Tested by

no test coverage detected