(t *testing.T)
| 108 | } |
| 109 | |
| 110 | func TestCheckRulePositive(t *testing.T) { |
| 111 | tests := []ast.Clause{ |
| 112 | clause("foo(/bar)."), |
| 113 | clause("foo(X) :- bar(X)."), |
| 114 | clause("foo(X) :- bar(X), bar(_)."), |
| 115 | clause("foo(X) :- X = /bar ."), |
| 116 | clause("foo(X) :- X = Y, bar(Y)."), |
| 117 | clause("foo(X) :- X = Y, Y = /bar ."), |
| 118 | clause("foo(X) :- Z = 2, bar(X), X < Z."), |
| 119 | clause("foo(X) :- X = fn:list:cons(fn:list:get([1], 1), [])."), |
| 120 | clause("foo([])."), |
| 121 | clause("foo([23])."), |
| 122 | clause("foo(fn:cons(1, [23]))."), |
| 123 | clause("foo({/foo: 37})."), |
| 124 | clause("foo([37: /foo])."), |
| 125 | clause("foo(X) :- X = [37]."), |
| 126 | clause("foo(X) :- Y = 2, X = [Y]."), |
| 127 | clause("foo(X) :- Y = 2 |> let X = [Y]."), |
| 128 | clause("foo(X) :- Y = 2, X = fn:list(Y)."), |
| 129 | clause("foo(X) :- X = {/foo: 37}."), |
| 130 | clause("foo(X) :- X = [37: /foo]."), |
| 131 | clause("foo(X) :- bar(X), 0 < X."), |
| 132 | clause("foo(Y) :- bar(X) |> let Y = fn:plus(X, X)."), |
| 133 | clause("foo(Y) :- bar(X) |> let Y = fn:list:get(X, 1)."), |
| 134 | clause("foo(Y) :- bar(X) |> do fn:group_by(X), let Y = fn:sum(X)."), |
| 135 | clause("c(R,S,T) :- bar(R), bar(S), bar(T), fn:plus(fn:mult(R, R), fn:mult(S,S)) = fn:mult(T,T)."), |
| 136 | clause("foo(X) :- bar(Y), bar(Z) |> do fn:group_by(Y), let X = fn:collect(Z)."), |
| 137 | clause("foo(A) :- bar(Y), bar(Z) |> do fn:group_by(Y), let X = fn:sum(Z), let A = fn:plus(X, 1)."), |
| 138 | } |
| 139 | for _, clause := range tests { |
| 140 | analyzer, _ := New(map[ast.PredicateSym]ast.Decl{ |
| 141 | ast.PredicateSym{"bar", 1}: makeSyntheticDecl(t, atom("bar(X)")), |
| 142 | }, nil, ErrorForBoundsMismatch) |
| 143 | if err := analyzer.CheckRule(clause); err != nil { |
| 144 | t.Errorf("Expected rule %v to be valid, got %v", clause, err) |
| 145 | } |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | func TestCheckRuleBindsByDecl(t *testing.T) { |
| 150 | d, err := ast.NewDecl( |
nothing calls this directly
no test coverage detected