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

Function TestParseTemporalFact

parse/temporal_test.go:25–163  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

23)
24
25func TestParseTemporalFact(t *testing.T) {
26 tests := []struct {
27 name string
28 str string
29 wantHead ast.Atom
30 wantTime *ast.Interval
31 wantErr bool
32 }{
33 {
34 name: "simple fact without temporal annotation",
35 str: "foo(/bar).",
36 wantHead: ast.NewAtom("foo", name("/bar")),
37 wantTime: nil,
38 wantErr: false,
39 },
40 {
41 name: "fact with date interval",
42 str: "foo(/bar)@[2024-01-15, 2024-06-30].",
43 wantHead: ast.NewAtom("foo", name("/bar")),
44 wantTime: func() *ast.Interval {
45 start := ast.NewTimestampBound(time.Date(2024, 1, 15, 0, 0, 0, 0, time.UTC))
46 end := ast.NewTimestampBound(time.Date(2024, 6, 30, 0, 0, 0, 0, time.UTC))
47 i := ast.NewInterval(start, end)
48 return &i
49 }(),
50 wantErr: false,
51 },
52 {
53 name: "fact with datetime interval",
54 str: "foo(/bar)@[2024-01-15T10:30:00, 2024-01-15T18:00:00].",
55 wantHead: ast.NewAtom("foo", name("/bar")),
56 wantTime: func() *ast.Interval {
57 start := ast.NewTimestampBound(time.Date(2024, 1, 15, 10, 30, 0, 0, time.UTC))
58 end := ast.NewTimestampBound(time.Date(2024, 1, 15, 18, 0, 0, 0, time.UTC))
59 i := ast.NewInterval(start, end)
60 return &i
61 }(),
62 wantErr: false,
63 },
64 {
65 name: "fact with point interval (single timestamp)",
66 str: "login(/alice)@[2024-03-15].",
67 wantHead: ast.NewAtom("login", name("/alice")),
68 wantTime: func() *ast.Interval {
69 t := ast.NewTimestampBound(time.Date(2024, 3, 15, 0, 0, 0, 0, time.UTC))
70 i := ast.NewInterval(t, t)
71 return &i
72 }(),
73 wantErr: false,
74 },
75 {
76 name: "fact with unbounded start (negative infinity)",
77 str: "admin(/bob)@[_, 2024-12-31].",
78 wantHead: ast.NewAtom("admin", name("/bob")),
79 wantTime: func() *ast.Interval {
80 start := ast.NegativeInfinity()
81 end := ast.NewTimestampBound(time.Date(2024, 12, 31, 0, 0, 0, 0, time.UTC))
82 i := ast.NewInterval(start, end)

Callers

nothing calls this directly

Calls 10

NewAtomFunction · 0.92
NewTimestampBoundFunction · 0.92
NewIntervalFunction · 0.92
NegativeInfinityFunction · 0.92
PositiveInfinityFunction · 0.92
NewVariableBoundFunction · 0.92
NowFunction · 0.92
nameFunction · 0.70
ClauseFunction · 0.70
EqualsMethod · 0.65

Tested by

no test coverage detected