(t *testing.T)
| 163 | } |
| 164 | |
| 165 | func 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 | |
| 222 | func TestParseTimestamp(t *testing.T) { |
nothing calls this directly
no test coverage detected