(t *testing.T)
| 251 | } |
| 252 | |
| 253 | func TestAnalyzePositive(t *testing.T) { |
| 254 | privateDecl := makeDecl(t, atom("foo.baz(X)"), []ast.Atom{atom("private()")}, nil, nil) |
| 255 | privateDeclEmptyPackage := makeDecl(t, atom("baz(X)"), []ast.Atom{atom("private()")}, nil, nil) |
| 256 | tests := []struct { |
| 257 | descr string |
| 258 | knownPredicates map[ast.PredicateSym]ast.Decl |
| 259 | decls []ast.Decl |
| 260 | program []ast.Clause |
| 261 | want ProgramInfo |
| 262 | }{ |
| 263 | { |
| 264 | descr: "self-contained program with two clauses, no decls.", |
| 265 | knownPredicates: nil, |
| 266 | decls: nil, |
| 267 | program: []ast.Clause{ |
| 268 | clause("foo(/bar)."), |
| 269 | clause("sna(X) :- foo(X)."), |
| 270 | }, |
| 271 | want: ProgramInfo{ |
| 272 | IdbPredicates: map[ast.PredicateSym]struct{}{ |
| 273 | ast.PredicateSym{"sna", 1}: {}, |
| 274 | }, |
| 275 | EdbPredicates: map[ast.PredicateSym]struct{}{ |
| 276 | ast.PredicateSym{"foo", 1}: {}, |
| 277 | }, |
| 278 | InitialFacts: []ast.Atom{atom("foo(/bar)")}, |
| 279 | InitialFactTimes: []*ast.Interval{nil}, |
| 280 | Rules: []ast.Clause{clause("sna(X) :- foo(X).")}, |
| 281 | Decls: mustDesugar(t, map[ast.PredicateSym]ast.Decl{ |
| 282 | ast.PredicateSym{"foo", 1}: makeSyntheticDecl(t, atom("foo(X0)")), |
| 283 | ast.PredicateSym{"sna", 1}: makeSyntheticDecl(t, atom("sna(X)")), |
| 284 | }), |
| 285 | }, |
| 286 | }, |
| 287 | { |
| 288 | descr: "overriding a synthetic decl is permitted", |
| 289 | decls: []ast.Decl{makeDecl(t, atom("foo(X,Y)"), nil, nil, nil)}, |
| 290 | knownPredicates: map[ast.PredicateSym]ast.Decl{ |
| 291 | ast.PredicateSym{"foo", 2}: makeSyntheticDecl(t, atom("foo(X,Y)")), |
| 292 | }, |
| 293 | program: nil, |
| 294 | want: ProgramInfo{ |
| 295 | IdbPredicates: map[ast.PredicateSym]struct{}{}, |
| 296 | EdbPredicates: map[ast.PredicateSym]struct{}{}, |
| 297 | Decls: mustDesugar(t, map[ast.PredicateSym]ast.Decl{ |
| 298 | ast.PredicateSym{"foo", 2}: makeDecl(t, atom("foo(X,Y)"), nil, nil, nil), |
| 299 | }), |
| 300 | }, |
| 301 | }, |
| 302 | { |
| 303 | descr: "foo.baz is private, but referencing predicate has same prefix", |
| 304 | knownPredicates: nil, |
| 305 | decls: []ast.Decl{privateDecl}, |
| 306 | program: []ast.Clause{ |
| 307 | clause("foo.baz(1)."), |
| 308 | clause("foo.bar(X) :- foo.baz(X)."), |
| 309 | }, |
| 310 | want: ProgramInfo{ |
nothing calls this directly
no test coverage detected