Skip to content

Commit

Permalink
almost all tests bakc up
Browse files Browse the repository at this point in the history
  • Loading branch information
jitsedesmet committed Apr 6, 2024
1 parent 7938868 commit 7bc642d
Show file tree
Hide file tree
Showing 67 changed files with 516 additions and 432 deletions.
19 changes: 2 additions & 17 deletions engines/query-sparql/test/QuerySparql-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,6 @@ describe('System test: QuerySparql', () => {
});

describe('query', () => {
it('playground', async() => {
// TODO: I do wonder how this ever passed... Should group concat know what to do with a language tag? Did it ever?
const res = await engine.queryBoolean(`
PREFIX : <http://www.example.org/>
ASK {
{SELECT (GROUP_CONCAT(?o) AS ?g) WHERE {
VALUES ?o { "1"@en "2"@en }
}
}
FILTER(?g = "1 2"@en || ?g = "2 1"@en)
}
`, { sources: [ 'https://www.rubensworks.net/' ]});
expect(res).toBe(true);
});

describe('simple SPO on a raw RDF document', () => {
it('with results', async() => {
const result = <QueryBindings> await engine.query(`SELECT * WHERE {
Expand Down Expand Up @@ -393,13 +378,13 @@ describe('System test: QuerySparql', () => {
it('rejects when record does not match', async() => {
const context = <any> { sources: [ store ]};
context.extensionFunctions = baseFunctions;
await expect(engine.query(baseQuery('nonExist'), context)).rejects.toThrow('Unknown named operator');
await expect(engine.query(baseQuery('nonExist'), context)).rejects.toThrow('actors rejected');
});

it('rejects when creator returns null', async() => {
const context = <any> { sources: [ store ]};
context.extensionFunctionCreator = () => null;
await expect(engine.query(baseQuery('nonExist'), context)).rejects.toThrow('Unknown named operator');
await expect(engine.query(baseQuery('nonExist'), context)).rejects.toThrow('actors rejected');
});

it('with results and pointless custom filter given by creator', async() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { createTermCompMediator } from '@comunica/actor-term-comparator-factory-inequality-functions-based/test/util';
import type { ActorExpressionEvaluatorFactory } from '@comunica/bus-expression-evaluator-factory';
import { ActionContext, Bus } from '@comunica/core';
import { BF, DF, getMockEEFactory, makeAggregate } from '@comunica/jest';
Expand Down Expand Up @@ -27,6 +28,7 @@ describe('ActorBindingsAggregatorFactoryMax', () => {
expressionEvaluatorFactory = getMockEEFactory({
mediatorQueryOperation,
mediatorBindingsAggregatorFactory: mediatorQueryOperation,
mediatorTermComparatorFactory: createTermCompMediator(),
});
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createFuncMediator } from '@comunica/actor-functions-wrapper-all/test/util';
import { createTermCompMediator } from '@comunica/actor-term-comparator-factory-inequality-functions-based/test/util';
import type { IBindingsAggregator } from '@comunica/bus-bindings-aggeregator-factory';
import type { ActorExpressionEvaluatorFactory } from '@comunica/bus-expression-evaluator-factory';
import { ActionContext } from '@comunica/core';
Expand Down Expand Up @@ -53,8 +53,7 @@ describe('MaxAggregator', () => {
expressionEvaluatorFactory = getMockEEFactory({
mediatorQueryOperation,
mediatorBindingsAggregatorFactory: mediatorQueryOperation,
// TODO: needs to get the comarator mediator!
mediatorFunctions: createFuncMediator(),
mediatorTermComparatorFactory: createTermCompMediator(),
});

context = new ActionContext();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { createTermCompMediator } from '@comunica/actor-term-comparator-factory-inequality-functions-based/test/util';
import type { ActorExpressionEvaluatorFactory } from '@comunica/bus-expression-evaluator-factory';
import { ActionContext, Bus } from '@comunica/core';
import { BF, DF, getMockEEFactory, makeAggregate } from '@comunica/jest';
Expand Down Expand Up @@ -27,6 +28,7 @@ describe('ActorBindingsAggregatorFactoryMin', () => {
expressionEvaluatorFactory = getMockEEFactory({
mediatorQueryOperation,
mediatorBindingsAggregatorFactory: mediatorQueryOperation,
mediatorTermComparatorFactory: createTermCompMediator(),
});
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { createTermCompMediator } from '@comunica/actor-term-comparator-factory-inequality-functions-based/test/util';
import type { IBindingsAggregator } from '@comunica/bus-bindings-aggeregator-factory';
import type { ActorExpressionEvaluatorFactory } from '@comunica/bus-expression-evaluator-factory';
import { ActionContext } from '@comunica/core';
Expand Down Expand Up @@ -51,6 +52,7 @@ describe('MinAggregator', () => {
expressionEvaluatorFactory = getMockEEFactory({
mediatorQueryOperation,
mediatorBindingsAggregatorFactory: mediatorQueryOperation,
mediatorTermComparatorFactory: createTermCompMediator(),
});

context = new ActionContext();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Bus } from '@comunica/core';
import { ActorExpressionEvaluatorFactoryBase } from '../lib/ActorExpressionEvaluatorFactoryBase';
import { getMockEEFactory } from '@comunica/jest';
import type { ActorExpressionEvaluatorFactoryBase } from '../lib/ActorExpressionEvaluatorFactoryBase';

describe('ActorExpressionEvaluatorFactoryBase', () => {
let bus: any;
Expand All @@ -12,15 +13,15 @@ describe('ActorExpressionEvaluatorFactoryBase', () => {
let actor: ActorExpressionEvaluatorFactoryBase;

beforeEach(() => {
actor = new ActorExpressionEvaluatorFactoryBase({ name: 'actor', bus });
actor = getMockEEFactory();
});

it('should test', () => {
return expect(actor.test({ todo: true })).resolves.toEqual({ todo: true }); // TODO
// Return expect(actor.test({ context: getMockEvaluatorContext() })).resolves.toEqual({ todo: true }); // TODO
});

it('should run', () => {
return expect(actor.run({ todo: true })).resolves.toMatchObject({ todo: true }); // TODO
// Return expect(actor.run({ todo: true })).resolves.toMatchObject({ todo: true }); // TODO
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { getMockExpression } from '@comunica/expression-evaluator/test/util/utils';
import { getMockEEActionContext, getMockMediatorFunctions } from '@comunica/jest';
import { DataFactory } from 'rdf-data-factory';
import type { Algebra } from 'sparqlalgebrajs';
import { AlgebraTransformer } from '../lib/AlgebraTransformer';

const DF = new DataFactory();

// https://www.w3.org/TR/sparql11-query/#ebv
// Using && as utility to force EBV
describe('the coercion of RDF terms to it\'s EBV like', () => {
const transformer = new AlgebraTransformer(getMockEEActionContext(), getMockMediatorFunctions());

function testCannotCoerce(expression: Algebra.Expression) {
it(`should not coerce ${expression.expressionType}`, async() => {
const transformed = await transformer.transformAlgebra(expression);
expect(() => (<any> transformed).coerceEBV()).toThrow();
});
}

describe('raw algebra test', () => {
testCannotCoerce(getMockExpression('?a'));
testCannotCoerce(getMockExpression('<http://example.com>'));
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,6 @@ export class ActorFunctionsWrapperAll extends ActorFunctions {
return <T extends { requireTermExpression: true } ? IActorFunctionsOutputTerm :
IActorFunctionsOutput><unknown> new NamedExtension(functionName, definition);
}
throw new Error('no');
throw new Error('Unknown function');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ describe('ActorFunctionsWrapperAll', () => {
});

it('should test', () => {
return expect(actor.test({ todo: true })).resolves.toEqual({ todo: true }); // TODO
// Return expect(actor.test({ todo: true })).resolves.toEqual({ todo: true }); // TODO
});

it('should run', () => {
return expect(actor.run({ todo: true })).resolves.toMatchObject({ todo: true }); // TODO
// Return expect(actor.run({ todo: true })).resolves.toMatchObject({ todo: true }); // TODO
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import {
yearMonthDurationTyped,
} from '@comunica/expression-evaluator/test/util/Aliases';
import { Notation } from '@comunica/expression-evaluator/test/util/TestTable';
import { runTestTable } from '@comunica/expression-evaluator/test/util/utils';
import { runFuncTestTable } from '../util';

describe('evaluation of XPath constructors', () => {
describe('to string', () => {
runTestTable({
runFuncTestTable({
arity: 1,
notation: Notation.Function,
operation: 'xsd:string',
Expand All @@ -33,7 +33,7 @@ describe('evaluation of XPath constructors', () => {
});

describe('to float', () => {
runTestTable({
runFuncTestTable({
arity: 1,
operation: 'xsd:float',
notation: Notation.Function,
Expand Down Expand Up @@ -82,7 +82,7 @@ describe('evaluation of XPath constructors', () => {
});

describe('to double', () => {
runTestTable({
runFuncTestTable({
arity: 1,
notation: Notation.Function,
operation: 'xsd:double',
Expand Down Expand Up @@ -131,7 +131,7 @@ describe('evaluation of XPath constructors', () => {
});

describe('to decimal', () => {
runTestTable({
runFuncTestTable({
arity: 1,
notation: Notation.Function,
operation: 'xsd:decimal',
Expand Down Expand Up @@ -184,7 +184,7 @@ describe('evaluation of XPath constructors', () => {
});

describe('to integer', () => {
runTestTable({
runFuncTestTable({
arity: 1,
notation: Notation.Function,
operation: 'xsd:integer',
Expand Down Expand Up @@ -230,7 +230,7 @@ describe('evaluation of XPath constructors', () => {
});

describe('to dateTime', () => {
runTestTable({
runFuncTestTable({
arity: 1,
notation: Notation.Function,
operation: 'xsd:dateTime',
Expand All @@ -255,7 +255,7 @@ describe('evaluation of XPath constructors', () => {
});

describe('to boolean', () => {
runTestTable({
runFuncTestTable({
arity: 1,
notation: Notation.Function,
operation: 'xsd:boolean',
Expand Down Expand Up @@ -299,7 +299,7 @@ describe('evaluation of XPath constructors', () => {
});

describe('to date', () => {
runTestTable({
runFuncTestTable({
arity: 1,
notation: Notation.Function,
operation: 'xsd:date',
Expand All @@ -319,7 +319,7 @@ describe('evaluation of XPath constructors', () => {
});

describe('to time', () => {
runTestTable({
runFuncTestTable({
arity: 1,
notation: Notation.Function,
operation: 'xsd:time',
Expand All @@ -339,7 +339,7 @@ describe('evaluation of XPath constructors', () => {
});

describe('to duration', () => {
runTestTable({
runFuncTestTable({
arity: 1,
notation: Notation.Function,
operation: 'xsd:duration',
Expand All @@ -350,7 +350,7 @@ describe('evaluation of XPath constructors', () => {
});

describe('to yearMonthDuration', () => {
runTestTable({
runFuncTestTable({
arity: 1,
notation: Notation.Function,
operation: 'xsd:yearMonthDuration',
Expand All @@ -367,7 +367,7 @@ describe('evaluation of XPath constructors', () => {
});

describe('to dayTimeDuration', () => {
runTestTable({
runFuncTestTable({
arity: 1,
notation: Notation.Function,
operation: 'xsd:dayTimeDuration',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
import { BindingsFactory } from '@comunica/bindings-factory';
import { KeysInitQuery } from '@comunica/context-entries';
import { ActionContext } from '@comunica/core';
import { bool, merge, numeric } from '@comunica/expression-evaluator/test/util/Aliases';
import { generalEvaluate } from '@comunica/expression-evaluator/test/util/generalEvaluation';
import { bool, compactTermString, merge, numeric } from '@comunica/expression-evaluator/test/util/Aliases';
import { Notation } from '@comunica/expression-evaluator/test/util/TestTable';
import { runTestTable } from '@comunica/expression-evaluator/test/util/utils';
import type { AsyncExtensionFunctionCreator } from '@comunica/types';
import type * as RDF from '@rdfjs/types';
import { DataFactory } from 'rdf-data-factory';
import { runFuncTestTable } from '../util';

const BF = new BindingsFactory();
const DF = new DataFactory();

describe('extension functions:', () => {
describe('term-equal', () => {
const extensionFunctions: AsyncExtensionFunctionCreator = async(functionNamedNode: RDF.NamedNode) => {
if (functionNamedNode.value === 'https://example.org/functions#equal') {
return async(args: RDF.Term[]) => {
const res = args[0].equals(args[1]);
const DF = new DataFactory();
const booleanType = DF.namedNode('http://www.w3.org/2001/XMLSchema#boolean');
if (res) {
return DF.literal('true', booleanType);
Expand All @@ -33,7 +32,7 @@ describe('extension functions:', () => {
};

describe('Can be evaluated', () => {
runTestTable({
runFuncTestTable({
arity: 2,
notation: Notation.Function,
operation: '<https://example.org/functions#equal>',
Expand Down Expand Up @@ -89,7 +88,7 @@ describe('extension functions:', () => {
NaN 3f = ${e}
3f NaN = ${e}
`;
runTestTable({
runFuncTestTable({
arity: 2,
notation: Notation.Function,
operation: '<https://example.org/functions#equal>',
Expand All @@ -99,7 +98,7 @@ describe('extension functions:', () => {
});

describe('throws error when providing a failing implementation', () => {
runTestTable({
runFuncTestTable({
arity: 1,
notation: Notation.Function,
operation: '<https://example.org/functions#bad>',
Expand All @@ -113,33 +112,26 @@ describe('extension functions:', () => {
});
});

it('upper case', async() => {
const complexQuery = `PREFIX func: <http://example.org/functions#>
SELECT ?caps WHERE {
?s ?p ?o.
BIND (func:to-upper-case(?o) AS ?caps)
}`;
const DF = new DataFactory();
describe('upper case', () => {
const stringType = DF.namedNode('http://www.w3.org/2001/XMLSchema#string');
const creator = () => async(args: RDF.Term[]) => {
const arg = args[0];
if (arg.termType === 'Literal' && arg.datatype.equals(DF.literal('', stringType).datatype)) {
return DF.literal(arg.value.toUpperCase(), stringType);
}
return arg;
};
const bindings = BF.bindings([
[ DF.variable('o'), DF.literal('AppLe', stringType) ],
]);
const evaluated = await generalEvaluate({
expression: complexQuery,
expectEquality: true,
bindings,
generalEvaluationConfig: new ActionContext({
[KeysInitQuery.extensionFunctionCreator.name]: creator,
runFuncTestTable({
arity: 1,
notation: Notation.Function,
operation: '<http://example.org/functions#to-upper-case>',
config: new ActionContext({
[KeysInitQuery.extensionFunctionCreator.name]: () => async(args: RDF.Term[]) => {
const arg = args[0];
if (arg.termType === 'Literal' && arg.datatype.equals(DF.literal('', stringType).datatype)) {
return DF.literal(arg.value.toUpperCase(), stringType);
}
return arg;
},
}),
aliases: merge(numeric, bool),
testTable: `
${compactTermString('AppLe', `<${stringType.value}>`)} = ${compactTermString('APPLE', stringType.value)}
`,
});
expect(evaluated.asyncResult).toEqual(DF.literal('APPLE', stringType));
});
});
});
Loading

0 comments on commit 7bc642d

Please sign in to comment.