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

Function TestDurationConstantString

ast/ast_test.go:823–845  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

821}
822
823func TestDurationConstantString(t *testing.T) {
824 tests := []struct {
825 nanos int64
826 want string
827 }{
828 {0, `fn:duration:parse("0s")`},
829 {1000000000, `fn:duration:parse("1s")`}, // 1 second
830 {60000000000, `fn:duration:parse("1m0s")`}, // 1 minute
831 {3600000000000, `fn:duration:parse("1h0m0s")`}, // 1 hour
832 {5400000000000, `fn:duration:parse("1h30m0s")`}, // 1.5 hours
833 {-1000000000, `fn:duration:parse("-1s")`}, // negative 1 second
834 {1500000, `fn:duration:parse("1.5ms")`}, // 1.5 milliseconds
835 {1500, `fn:duration:parse("1.5µs")`}, // 1.5 microseconds
836 {150, `fn:duration:parse("150ns")`}, // 150 nanoseconds
837 }
838 for _, test := range tests {
839 d := Duration(test.nanos)
840 got := d.String()
841 if got != test.want {
842 t.Errorf("Duration(%d).String() = %q, want %q", test.nanos, got, test.want)
843 }
844 }
845}
846
847func TestDurationValueError(t *testing.T) {
848 // DurationValue should fail on non-duration constants

Callers

nothing calls this directly

Calls 2

DurationFunction · 0.85
StringMethod · 0.65

Tested by

no test coverage detected