Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions analysis/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"bytes"
"embed"
"fmt"
"path/filepath"
"path"
"strings"
"testing"

Expand Down Expand Up @@ -85,7 +85,7 @@ func TestCases(t *testing.T) {
for _, testCase := range entries {
t.Run(testCase.Name(), func(t *testing.T) {
file, err := testCases.ReadFile(
filepath.Join("test_cases", testCase.Name()))
path.Join("test_cases", testCase.Name()))
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -693,6 +693,12 @@ func TestBoundsAnalyzer(t *testing.T) {
makeSimpleDecl(atom("foo(X)"), ast.NumberBound),
makeSimpleDecl(atom("bar(Y)"), symbols.NewListType(ast.NumberBound)),
}),
newBoundsTestCase(t, []ast.Clause{
clause("foo(X) :- bar(X), :list:member(X, [/a, /b])."),
}, []ast.Decl{
makeSimpleDecl(atom("foo(X)"), ast.NameBound),
makeSimpleDecl(atom("bar(X)"), ast.NameBound),
}),
newBoundsTestCase(t, []ast.Clause{
clause("bar(T) :- T = fn:string:concat(\"A\", 123)."),
}, []ast.Decl{
Expand Down
2 changes: 1 addition & 1 deletion builtin/builtin.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ var (
symbols.FloatLe: {ast.ArgModeInput, ast.ArgModeInput},
symbols.FloatGt: {ast.ArgModeInput, ast.ArgModeInput},
symbols.FloatGe: {ast.ArgModeInput, ast.ArgModeInput},
symbols.ListMember: {ast.ArgModeOutput, ast.ArgModeInput},
symbols.ListMember: {ast.ArgModeInputOutput, ast.ArgModeInput},
symbols.WithinDistance: {ast.ArgModeInput, ast.ArgModeInput, ast.ArgModeInput},
symbols.MatchPair: {ast.ArgModeInput, ast.ArgModeOutput, ast.ArgModeOutput},
symbols.MatchCons: {ast.ArgModeInput, ast.ArgModeOutput, ast.ArgModeOutput},
Expand Down
26 changes: 26 additions & 0 deletions engine/seminaivebottomup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,32 @@ func TestNegation(t *testing.T) {
}
}

func TestListMemberBound(t *testing.T) {
store := factstore.NewSimpleInMemoryStore()
prog := []ast.Clause{
clause("seen(/a)."),
clause("seen(/c)."),
clause("approved(X) :- seen(X), :list:member(X, [/a, /b])."),
clause("is_member() :- :list:member(/a, [/a, /b])."),
}
if err := analyzeAndEvalProgram(t, prog, store); err != nil {
t.Fatalf("Program evaluation failed: %v", err)
}
expected := []ast.Atom{
atom("approved(/a)"),
atom("is_member()"),
}
for _, a := range expected {
if !store.Contains(a) {
t.Errorf("expected fact %v not found", a)
}
}
unexpected := atom("approved(/c)")
if store.Contains(unexpected) {
t.Errorf("unexpected fact %v found", unexpected)
}
}

func TestNegationOrder(t *testing.T) {
store := factstore.NewSimpleInMemoryStore()
negationProgram := []ast.Clause{
Expand Down