| 321 | } |
| 322 | |
| 323 | func TestClauses(t *testing.T) { |
| 324 | tests := []struct { |
| 325 | desc string |
| 326 | input Package |
| 327 | want []ast.Clause |
| 328 | }{ |
| 329 | { |
| 330 | desc: "no package name, clauses are not rewritten", |
| 331 | input: Package{ |
| 332 | Name: "", |
| 333 | units: []parse.SourceUnit{ |
| 334 | { |
| 335 | Clauses: []ast.Clause{ |
| 336 | ast.NewClause(ast.NewAtom("clause_defined_here"), []ast.Term{ast.NewAtom("other_clause")}), |
| 337 | }, |
| 338 | }, |
| 339 | { |
| 340 | Clauses: []ast.Clause{ |
| 341 | ast.NewClause(ast.NewAtom("clause_also_defined_here"), []ast.Term{ast.NewAtom("other_clause")}), |
| 342 | }, |
| 343 | }, |
| 344 | }, |
| 345 | }, |
| 346 | want: []ast.Clause{ |
| 347 | ast.NewClause(ast.NewAtom("clause_defined_here"), []ast.Term{ast.NewAtom("other_clause")}), |
| 348 | ast.NewClause(ast.NewAtom("clause_also_defined_here"), []ast.Term{ast.NewAtom("other_clause")}), |
| 349 | }, |
| 350 | }, |
| 351 | { |
| 352 | desc: "references to predicates outside the package are left as-is", |
| 353 | input: Package{ |
| 354 | Name: "foo.bar", |
| 355 | units: []parse.SourceUnit{ |
| 356 | { |
| 357 | Clauses: []ast.Clause{ |
| 358 | ast.NewClause(ast.NewAtom("clause_defined_here"), []ast.Term{ast.NewAtom("other_clause")}), |
| 359 | }, |
| 360 | }, |
| 361 | { |
| 362 | Clauses: []ast.Clause{ |
| 363 | ast.NewClause(ast.NewAtom("clause_also_defined_here"), []ast.Term{ast.NewAtom("other_clause")}), |
| 364 | }, |
| 365 | }, |
| 366 | }, |
| 367 | }, |
| 368 | want: []ast.Clause{ |
| 369 | ast.NewClause(ast.NewAtom("foo.bar.clause_defined_here"), []ast.Term{ast.NewAtom("other_clause")}), |
| 370 | ast.NewClause(ast.NewAtom("foo.bar.clause_also_defined_here"), []ast.Term{ast.NewAtom("other_clause")}), |
| 371 | }, |
| 372 | }, |
| 373 | { |
| 374 | desc: "clauses defined in this package are rewritten", |
| 375 | input: Package{ |
| 376 | Name: "foo.bar", |
| 377 | units: []parse.SourceUnit{ |
| 378 | { |
| 379 | Clauses: []ast.Clause{ |
| 380 | ast.NewClause(ast.NewAtom("other_clause"), []ast.Term{ast.String("here")}), |