MCPcopy Index your code
hub / github.com/google/mangle / TestParseTemporalRule

Function TestParseTemporalRule

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

Source from the content-addressed store, hash-verified

163}
164
165func TestParseTemporalRule(t *testing.T) {
166 tests := []struct {
167 name string
168 str string
169 wantHead ast.Atom
170 wantTime *ast.Interval
171 wantErr bool
172 }{
173 {
174 name: "rule without temporal annotation",
175 str: "foo(X) :- bar(X).",
176 wantHead: ast.NewAtom("foo", ast.Variable{Symbol: "X"}),
177 wantTime: nil,
178 wantErr: false,
179 },
180 {
181 name: "rule with temporal annotation on head",
182 str: "active(X)@[T, T] :- login(X).",
183 wantHead: ast.NewAtom("active", ast.Variable{Symbol: "X"}),
184 wantTime: func() *ast.Interval {
185 bound := ast.NewVariableBound(ast.Variable{Symbol: "T"})
186 i := ast.NewInterval(bound, bound)
187 return &i
188 }(),
189 wantErr: false,
190 },
191 }
192
193 for _, test := range tests {
194 t.Run(test.name, func(t *testing.T) {
195 clause, err := Clause(test.str)
196 if (err != nil) != test.wantErr {
197 t.Fatalf("Clause(%q) error = %v, wantErr = %v", test.str, err, test.wantErr)
198 }
199 if err != nil {
200 return
201 }
202
203 if !clause.Head.Equals(test.wantHead) {
204 t.Errorf("Clause(%q).Head = %v, want %v", test.str, clause.Head, test.wantHead)
205 }
206
207 if test.wantTime == nil {
208 if clause.HeadTime != nil {
209 t.Errorf("Clause(%q).HeadTime = %v, want nil", test.str, clause.HeadTime)
210 }
211 } else {
212 if clause.HeadTime == nil {
213 t.Errorf("Clause(%q).HeadTime = nil, want %v", test.str, test.wantTime)
214 } else if !clause.HeadTime.Equals(*test.wantTime) {
215 t.Errorf("Clause(%q).HeadTime = %v, want %v", test.str, clause.HeadTime, test.wantTime)
216 }
217 }
218 })
219 }
220}
221
222func TestParseTimestamp(t *testing.T) {

Callers

nothing calls this directly

Calls 5

NewAtomFunction · 0.92
NewVariableBoundFunction · 0.92
NewIntervalFunction · 0.92
ClauseFunction · 0.70
EqualsMethod · 0.65

Tested by

no test coverage detected