(t *testing.T)
| 1367 | } |
| 1368 | |
| 1369 | func TestTimeTrunc(t *testing.T) { |
| 1370 | // 2024-01-15 10:30:45.123456789 UTC |
| 1371 | nanos := int64(1705314645123456789) |
| 1372 | |
| 1373 | tests := []struct { |
| 1374 | unit string |
| 1375 | wantNanos int64 |
| 1376 | }{ |
| 1377 | {"/day", 1705276800000000000}, // 2024-01-15 00:00:00 UTC |
| 1378 | {"/hour", 1705312800000000000}, // 2024-01-15 10:00:00 UTC |
| 1379 | {"/minute", 1705314600000000000}, // 2024-01-15 10:30:00 UTC |
| 1380 | {"/second", 1705314645000000000}, // 2024-01-15 10:30:45 UTC |
| 1381 | {"/millisecond", 1705314645123000000}, |
| 1382 | {"/microsecond", 1705314645123456000}, |
| 1383 | {"/nanosecond", 1705314645123456789}, |
| 1384 | } |
| 1385 | |
| 1386 | for _, test := range tests { |
| 1387 | t.Run(test.unit, func(t *testing.T) { |
| 1388 | expr := ast.ApplyFn{symbols.TimeTrunc, []ast.BaseTerm{ |
| 1389 | ast.Time(nanos), |
| 1390 | name(test.unit), |
| 1391 | }} |
| 1392 | got, err := EvalApplyFn(expr, ast.ConstSubstMap{}) |
| 1393 | if err != nil { |
| 1394 | t.Fatalf("EvalApplyFn(%v) failed with %v", expr, err) |
| 1395 | } |
| 1396 | want := ast.Time(test.wantNanos) |
| 1397 | if !got.Equals(want) { |
| 1398 | t.Errorf("EvalApplyFn(%v) = %v, want %v", expr, got, want) |
| 1399 | } |
| 1400 | }) |
| 1401 | } |
| 1402 | } |
| 1403 | |
| 1404 | func TestTimeTruncInvalid(t *testing.T) { |
| 1405 | nanos := int64(1705314600000000000) |
nothing calls this directly
no test coverage detected