Skip to content

Commit

Permalink
Adjusted tests for new type paradigm
Browse files Browse the repository at this point in the history
  • Loading branch information
karelklima committed Nov 18, 2023
1 parent 8936800 commit c71290b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 74 deletions.
88 changes: 32 additions & 56 deletions tests/decoder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,14 @@ const evaluate = (

Deno.test("Decoder / Minimal resource", () => {
const input = `
x:A a ldkit:Resource, x:Item .
x:A a ldkit:Resource .
`;

const schema = { "@type": [x.Item] };
const schema = { "@type": [] };

const output = [
{
$id: x.A,
$type: [x.Item],
},
];

Expand All @@ -38,25 +37,22 @@ Deno.test("Decoder / Minimal resource", () => {

Deno.test("Decoder / Multiple minimal resources", () => {
const input = `
x:A a ldkit:Resource, x:Item .
x:B a ldkit:Resource, x:Item .
x:C a ldkit:Resource, x:Item .
x:A a ldkit:Resource .
x:B a ldkit:Resource .
x:C a ldkit:Resource .
`;

const schema = { "@type": [x.Item] };
const schema = { "@type": [] };

const output = [
{
$id: x.A,
$type: [x.Item],
},
{
$id: x.B,
$type: [x.Item],
},
{
$id: x.C,
$type: [x.Item],
},
];

Expand Down Expand Up @@ -175,7 +171,6 @@ Deno.test("Decoder / Basic types", () => {
const output = [
{
$id: x.A,
$type: [x.Item],
string: "LDKit",
integer: -5,
decimal: -5.0,
Expand All @@ -190,11 +185,11 @@ Deno.test("Decoder / Basic types", () => {

Deno.test("Decoder / Required property missing", () => {
const input = `
x:A a ldkit:Resource, x:Item .
x:A a ldkit:Resource .
`;

const schema = {
"@type": [x.Item],
"@type": [],
required: {
"@id": x.required,
},
Expand All @@ -205,11 +200,11 @@ Deno.test("Decoder / Required property missing", () => {

Deno.test("Decoder / Optional property missing", () => {
const input = `
x:A a ldkit:Resource, x:Item .
x:A a ldkit:Resource .
`;

const schema = {
"@type": [x.Item],
"@type": [],
optional: {
"@id": x.optional,
"@optional": true as const,
Expand All @@ -219,7 +214,6 @@ Deno.test("Decoder / Optional property missing", () => {
const output = [
{
$id: x.A,
$type: [x.Item],
},
];

Expand All @@ -228,11 +222,11 @@ Deno.test("Decoder / Optional property missing", () => {

Deno.test("Decoder / Optional array property missing", () => {
const input = `
x:A a ldkit:Resource, x:Item .
x:A a ldkit:Resource .
`;

const schema = {
"@type": [x.Item],
"@type": [],
optional: {
"@id": x.optional,
"@optional": true as const,
Expand All @@ -243,7 +237,6 @@ Deno.test("Decoder / Optional array property missing", () => {
const output = [
{
$id: x.A,
$type: [x.Item],
optional: [],
},
];
Expand All @@ -254,12 +247,12 @@ Deno.test("Decoder / Optional array property missing", () => {
Deno.test("Decoder / Array simple property", () => {
const input = `
x:A
a ldkit:Resource, x:Item ;
a ldkit:Resource ;
x:array 1, 2, 3 .
`;

const schema = {
"@type": [x.Item],
"@type": [],
array: {
"@id": x.array,
"@array": true as const,
Expand All @@ -269,7 +262,6 @@ Deno.test("Decoder / Array simple property", () => {
const output = [
{
$id: x.A,
$type: [x.Item],
array: [1, 2, 3],
},
];
Expand All @@ -280,22 +272,19 @@ Deno.test("Decoder / Array simple property", () => {
Deno.test("Decoder / Array subschema property", () => {
const input = `
x:A
a ldkit:Resource, x:Item ;
a ldkit:Resource ;
x:array x:B, x:C .
x:B
a x:SubItem ;
x:value "value B" .
x:C a x:SubItem ;
x:value "value C" .
x:B x:value "value B" .
x:C x:value "value C" .
`;

const schema = {
"@type": [x.Item],
"@type": [],
array: {
"@id": x.array,
"@array": true as const,
"@context": {
"@type": [x.SubItem],
"@type": [],
value: {
"@id": x.value,
},
Expand All @@ -306,16 +295,13 @@ Deno.test("Decoder / Array subschema property", () => {
const output = [
{
$id: x.A,
$type: [x.Item],
array: [
{
$id: x.B,
$type: [x.SubItem],
value: "value B",
},
{
$id: x.C,
$type: [x.SubItem],
value: "value C",
},
],
Expand All @@ -328,12 +314,12 @@ Deno.test("Decoder / Array subschema property", () => {
Deno.test("Decoder / Multilang property", () => {
const input = `
x:A
a ldkit:Resource, x:Item ;
a ldkit:Resource ;
x:multilang "CS"@cs, "EN"@en, "Unknown" .
`;

const schema = {
"@type": [x.Item],
"@type": [],
multilang: {
"@id": x.multilang,
"@multilang": true as const,
Expand All @@ -343,7 +329,6 @@ Deno.test("Decoder / Multilang property", () => {
const output = [
{
$id: x.A,
$type: [x.Item],
multilang: {
cs: "CS",
en: "EN",
Expand All @@ -358,12 +343,12 @@ Deno.test("Decoder / Multilang property", () => {
Deno.test("Decoder / Multilang array property", () => {
const input = `
x:A
a ldkit:Resource, x:Item ;
a ldkit:Resource;
x:multilang "CS 1"@cs, "CS 2"@cs, "CS 3"@cs, "EN"@en, "Unknown" .
`;

const schema = {
"@type": [x.Item],
"@type": [],
multilang: {
"@id": x.multilang,
"@multilang": true as const,
Expand All @@ -374,7 +359,6 @@ Deno.test("Decoder / Multilang array property", () => {
const output = [
{
$id: x.A,
$type: [x.Item],
multilang: {
cs: ["CS 1", "CS 2", "CS 3"],
en: ["EN"],
Expand All @@ -389,12 +373,12 @@ Deno.test("Decoder / Multilang array property", () => {
Deno.test("Decoder / Preferred language property", () => {
const input = `
x:A
a ldkit:Resource, x:Item ;
a ldkit:Resource ;
x:preferredLanguage "DE"@de, "CS"@cs, "EN"@en .
`;

const schema = {
"@type": [x.Item],
"@type": [],
preferredLanguage: {
"@id": x.preferredLanguage,
},
Expand All @@ -403,7 +387,6 @@ Deno.test("Decoder / Preferred language property", () => {
const output = [
{
$id: x.A,
$type: [x.Item],
preferredLanguage: "CS",
},
];
Expand All @@ -414,12 +397,12 @@ Deno.test("Decoder / Preferred language property", () => {
Deno.test("Decoder / Preferred first property", () => {
const input = `
x:A
a ldkit:Resource, x:Item ;
a ldkit:Resource ;
x:preferredFirst "DE"@de, "CS"@cs, "EN"@en .
`;

const schema = {
"@type": [x.Item],
"@type": [],
preferredFirst: {
"@id": x.preferredFirst,
},
Expand All @@ -428,7 +411,6 @@ Deno.test("Decoder / Preferred first property", () => {
const output = [
{
$id: x.A,
$type: [x.Item],
preferredFirst: "DE",
},
];
Expand All @@ -439,14 +421,14 @@ Deno.test("Decoder / Preferred first property", () => {
Deno.test("Decoder / One resource multiple schemas", () => {
const input = `
x:A
a ldkit:Resource, x:Item ;
a ldkit:Resource ;
x:nested x:A ;
x:rootProperty "Root property" ;
x:nestedProperty "Nested property" .
`;

const schema = {
"@type": [x.Item],
"@type": [],
rootProperty: {
"@id": x.rootProperty,
},
Expand All @@ -464,11 +446,9 @@ Deno.test("Decoder / One resource multiple schemas", () => {
const output = [
{
$id: x.A,
$type: [x.Item],
rootProperty: "Root property",
nested: {
$id: x.A,
$type: [x.Item],
nestedProperty: "Nested property",
},
},
Expand All @@ -480,17 +460,17 @@ Deno.test("Decoder / One resource multiple schemas", () => {
Deno.test("Decoder / Caching", () => {
const input = `
x:A
a ldkit:Resource, x:Item ;
a ldkit:Resource ;
x:nested x:C .
x:B
a ldkit:Resource, x:Item ;
a ldkit:Resource ;
x:nested x:C .
x:C
a x:Nested .
`;

const schema = {
"@type": [x.Item],
"@type": [],
nested: {
"@id": x.nested,
"@context": {
Expand All @@ -502,18 +482,14 @@ Deno.test("Decoder / Caching", () => {
const output = [
{
$id: x.A,
$type: [x.Item],
nested: {
$id: x.C,
$type: [x.Nested],
},
},
{
$id: x.B,
$type: [x.Item],
nested: {
$id: x.C,
$type: [x.Nested],
},
},
];
Expand Down
18 changes: 0 additions & 18 deletions tests/lens.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ const defaultStoreContent = ttl(`

const createDirector = ($id: string, name: string) => ({
$id: x[$id],
$type: [x.Director],
name,
});

Expand Down Expand Up @@ -239,7 +238,6 @@ Deno.test("Resource / Insert data", async () => {
const result = await directors.findByIri(x.ChristopherNolan);
assertEquals(result, {
$id: x.ChristopherNolan,
$type: [x.Director],
name: "Christopher Nolan",
});
});
Expand All @@ -248,7 +246,6 @@ Deno.test("Resource / Delete data", async () => {
const { directors } = init();
await directors.insert({
$id: x.ChristopherNolan,
$type: [x.Director, x.CustomType],
name: "Christopher Nolan",
});
await directors.deleteData(
Expand All @@ -261,21 +258,6 @@ Deno.test("Resource / Delete data", async () => {
const result = await directors.findByIri(x.ChristopherNolan);
assertEquals(result, {
$id: x.ChristopherNolan,
$type: [x.Director],
name: "Christopher Nolan",
});
});

// TODO Review and fix this test
/*Deno.test("Resource / Support for custom types", async () => {
const { movies } = init();
await movies.insert({
$id: x.KillBill,
$type: [x.TarantinoMovie],
name: "Kill Bill",
director: { $id: x.QuentinTarantino },
});
const result = await movies.findByIri(x.KillBill);
assertEquals(result?.$type, [x.Movie, x.TarantinoMovie]);
});*/

0 comments on commit c71290b

Please sign in to comment.