| 568 | } |
| 569 | |
| 570 | func TestParseClauseNegative(t *testing.T) { |
| 571 | tests := []struct { |
| 572 | name string |
| 573 | str string |
| 574 | }{ |
| 575 | { |
| 576 | name: "missing end", |
| 577 | str: "foo(/bar)", |
| 578 | }, |
| 579 | { |
| 580 | name: "bad predicate name", |
| 581 | str: "_(/bar).", |
| 582 | }, |
| 583 | { |
| 584 | name: "variable as head?!", |
| 585 | str: "X :- X = /foo, /foo != X.", |
| 586 | }, |
| 587 | { |
| 588 | name: "constant as head?!", |
| 589 | str: "/foo :- foo(/bar).", |
| 590 | }, |
| 591 | { |
| 592 | name: "missing body", |
| 593 | str: "a(B) :-", |
| 594 | }, |
| 595 | } |
| 596 | for _, test := range tests { |
| 597 | t.Run(test.name, func(t *testing.T) { |
| 598 | got, err := Clause(test.str) |
| 599 | if err == nil { // if no error |
| 600 | t.Errorf("Clause(%v)=%v want error", test.str, got) |
| 601 | } |
| 602 | }) |
| 603 | } |
| 604 | } |
| 605 | |
| 606 | func TestParseLiteralOrFormulaPositive(t *testing.T) { |
| 607 | tests := []struct { |