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

Function TestTimeParse

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

Source from the content-addressed store, hash-verified

1194}
1195
1196func TestTimeParse(t *testing.T) {
1197 tests := []struct {
1198 timeString string
1199 wantNanos int64
1200 }{
1201 {
1202 timeString: "2024-01-15T10:30:00Z",
1203 wantNanos: 1705314600000000000,
1204 },
1205 {
1206 timeString: "2024-01-15T10:30:00+02:00",
1207 wantNanos: 1705307400000000000,
1208 },
1209 }
1210 for _, test := range tests {
1211 t.Run(test.timeString, func(t *testing.T) {
1212 // Argument is time_string in RFC3339 format.
1213 expr := ast.ApplyFn{symbols.TimeParseRFC3339, []ast.BaseTerm{
1214 ast.String(test.timeString),
1215 }}
1216 got, err := EvalApplyFn(expr, ast.ConstSubstMap{})
1217 if err != nil {
1218 t.Fatalf("EvalApplyFn(%v) failed with %v", expr, err)
1219 }
1220 want := ast.Time(test.wantNanos)
1221 if !got.Equals(want) {
1222 t.Errorf("EvalApplyFn(%v) = %v, want %v", expr, got, want)
1223 }
1224 })
1225 }
1226}
1227
1228func TestTimeParseCivil(t *testing.T) {
1229 // 2024-01-15 10:30:00 UTC = 1705314600000000000

Callers

nothing calls this directly

Calls 4

StringFunction · 0.92
TimeFunction · 0.92
EvalApplyFnFunction · 0.85
EqualsMethod · 0.65

Tested by

no test coverage detected