38 lines
1.1 KiB
TypeScript
38 lines
1.1 KiB
TypeScript
import test from "ava";
|
|
import { Any, Query, Variable } from "./query";
|
|
|
|
test("query matches simple", (t) => {
|
|
const query = Query.matches("entity", "attribute", "value");
|
|
t.is(query.toString(), '(matches entity "attribute" "value")');
|
|
});
|
|
|
|
test("query matches anything", (t) => {
|
|
const query = Query.matches(Any, Any, Any);
|
|
t.is(query.toString(), "(matches ? ? ?)");
|
|
});
|
|
|
|
test("query matches array", (t) => {
|
|
const query = Query.matches("entity", "attribute", ["value1", "value2"]);
|
|
t.is(query.toString(), '(matches entity "attribute" (in "value1" "value2"))');
|
|
});
|
|
|
|
test("query matches addresses", (t) => {
|
|
const query = Query.matches("entity", "attribute", [
|
|
"@address1",
|
|
"@address2",
|
|
]);
|
|
t.is(
|
|
query.toString(),
|
|
'(matches entity "attribute" (in @address1 @address2))'
|
|
);
|
|
});
|
|
|
|
test("query matches numbers", (t) => {
|
|
const query = Query.matches("entity", "attribute", [1, 2]);
|
|
t.is(query.toString(), '(matches entity "attribute" (in 1 2))');
|
|
});
|
|
|
|
test("query matches variables", (t) => {
|
|
const query = Query.matches("entity", "attribute", Variable("a"));
|
|
t.is(query.toString(), '(matches entity "attribute" ?a)');
|
|
});
|