MCPcopy
hub / github.com/google/mangle / TestDurationFromUnits

Function TestDurationFromUnits

functional/functional_test.go:1481–1506  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1479}
1480
1481func TestDurationFromUnits(t *testing.T) {
1482 tests := []struct {
1483 name string
1484 fn ast.FunctionSym
1485 arg ast.BaseTerm
1486 want ast.Constant
1487 }{
1488 {"from_nanos", symbols.DurationFromNanos, ast.Number(1000000000), ast.Duration(1000000000)},
1489 {"from_seconds", symbols.DurationFromSeconds, ast.Number(60), ast.Duration(60000000000)},
1490 {"from_minutes", symbols.DurationFromMinutes, ast.Number(5), ast.Duration(300000000000)},
1491 {"from_hours", symbols.DurationFromHours, ast.Number(2), ast.Duration(7200000000000)},
1492 }
1493
1494 for _, test := range tests {
1495 t.Run(test.name, func(t *testing.T) {
1496 expr := ast.ApplyFn{test.fn, []ast.BaseTerm{test.arg}}
1497 got, err := EvalApplyFn(expr, ast.ConstSubstMap{})
1498 if err != nil {
1499 t.Fatalf("EvalApplyFn(%v) failed with %v", expr, err)
1500 }
1501 if !got.Equals(test.want) {
1502 t.Errorf("EvalApplyFn(%v) = %v, want %v", expr, got, test.want)
1503 }
1504 })
1505 }
1506}
1507
1508func TestDurationParse(t *testing.T) {
1509 tests := []struct {

Callers

nothing calls this directly

Calls 4

NumberFunction · 0.92
DurationFunction · 0.92
EvalApplyFnFunction · 0.85
EqualsMethod · 0.65

Tested by

no test coverage detected