forked from comunica/comunica
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b88a89f
commit 4de1891
Showing
24 changed files
with
187 additions
and
390 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 32 additions & 67 deletions
99
packages/expression-evaluator/test/integration/evaluators/Evaluator-test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,93 +1,58 @@ | ||
import { BindingsFactory } from '@comunica/bindings-factory'; | ||
import { ActionContext } from '@comunica/core'; | ||
import { DataFactory } from 'rdf-data-factory'; | ||
import { translate } from 'sparqlalgebrajs'; | ||
import { AsyncEvaluator, SyncEvaluator } from '../../../lib'; | ||
import type { ExpressionEvaluatorFactory } from '../../../lib'; | ||
import { IntegerLiteral } from '../../../lib/expressions'; | ||
import { TypeURL as DT } from '../../../lib/util/Consts'; | ||
import * as Err from '../../../lib/util/Errors'; | ||
import { getMockEEFactory, getMockExpression } from '../../util/utils'; | ||
|
||
const DF = new DataFactory(); | ||
const BF = new BindingsFactory(); | ||
const two = DF.literal('2', DF.namedNode(DT.XSD_INTEGER)); | ||
|
||
function parse(expr: string) { | ||
return translate(`SELECT * WHERE { ?s ?p ?o FILTER (${expr})}`).input.expression; | ||
} | ||
|
||
describe('evaluators', () => { | ||
describe('SyncEvaluator', () => { | ||
describe('evaluate', () => { | ||
it('is able to evaluate', () => { | ||
const evaluator = new SyncEvaluator(parse('1 + 1')); | ||
expect(evaluator.evaluate(BF.bindings())).toEqual(two); | ||
}); | ||
|
||
it('has proper default extended XSD type support', () => { | ||
const evaluator = new SyncEvaluator(parse('1 + 1')); | ||
expect(evaluator.evaluate(BF.bindings())).toEqual(two); | ||
}); | ||
let factory: ExpressionEvaluatorFactory; | ||
let actionContext: ActionContext; | ||
beforeEach(() => { | ||
factory = getMockEEFactory(); | ||
actionContext = new ActionContext({}); | ||
}); | ||
|
||
it('has proper extended XSD type support', () => { | ||
const evaluator = new SyncEvaluator(parse('1 + "1"^^<http://example.com>')); | ||
expect(() => evaluator.evaluate(BF.bindings())).toThrow(Err.InvalidArgumentTypes); | ||
}); | ||
describe('evaluate', () => { | ||
it('is able to evaluate', async() => { | ||
const evaluator = factory.createEvaluator(getMockExpression('1 + 1'), actionContext); | ||
expect(await evaluator.evaluate(BF.bindings())).toEqual(two); | ||
}); | ||
|
||
describe('evaluateAsEBV', () => { | ||
it('is able to evaluate to true', () => { | ||
const evaluator = new SyncEvaluator(parse('1 + 1')); | ||
expect(evaluator.evaluateAsEBV(BF.bindings())).toEqual(true); | ||
}); | ||
|
||
it('is able to evaluate to false', () => { | ||
const evaluator = new SyncEvaluator(parse('0')); | ||
expect(evaluator.evaluateAsEBV(BF.bindings())).toEqual(false); | ||
}); | ||
it('has proper default extended XSD type support', async() => { | ||
const evaluator = factory.createEvaluator(getMockExpression('1 + 1'), actionContext); | ||
expect(await evaluator.evaluate(BF.bindings())).toEqual(two); | ||
}); | ||
|
||
describe('evaluateAsInternal', () => { | ||
it('is able to evaluate', () => { | ||
const evaluator = new SyncEvaluator(parse('1 + 1')); | ||
expect(evaluator.evaluateAsInternal(BF.bindings())).toEqual(new IntegerLiteral(2)); | ||
}); | ||
it('has proper extended XSD type support', async() => { | ||
const evaluator = factory.createEvaluator(getMockExpression('1 + "1"^^<http://example.com>'), | ||
actionContext); | ||
await expect(evaluator.evaluate(BF.bindings())).rejects.toThrow(Err.InvalidArgumentTypes); | ||
}); | ||
}); | ||
|
||
describe('AsyncEvaluator', () => { | ||
describe('evaluate', () => { | ||
it('is able to evaluate', async() => { | ||
const evaluator = new AsyncEvaluator(parse('1 + 1')); | ||
expect(await evaluator.evaluate(BF.bindings())).toEqual(two); | ||
}); | ||
|
||
it('has proper default extended XSD type support', async() => { | ||
const evaluator = new AsyncEvaluator(parse('1 + 1')); | ||
expect(await evaluator.evaluate(BF.bindings())).toEqual(two); | ||
}); | ||
|
||
it('has proper extended XSD type support', async() => { | ||
const evaluator = new AsyncEvaluator(parse('1 + "1"^^<http://example.com>')); | ||
await expect(evaluator.evaluate(BF.bindings())).rejects.toThrow(Err.InvalidArgumentTypes); | ||
}); | ||
describe('evaluateAsEBV', () => { | ||
it('is able to evaluate to true', async() => { | ||
const evaluator = factory.createEvaluator(getMockExpression('1 + 1'), actionContext); | ||
expect(await evaluator.evaluateAsEBV(BF.bindings())).toEqual(true); | ||
}); | ||
|
||
describe('evaluateAsEBV', () => { | ||
it('is able to evaluate to true', async() => { | ||
const evaluator = new AsyncEvaluator(parse('1 + 1')); | ||
expect(await evaluator.evaluateAsEBV(BF.bindings())).toEqual(true); | ||
}); | ||
|
||
it('is able to evaluate to false', async() => { | ||
const evaluator = new AsyncEvaluator(parse('0')); | ||
expect(await evaluator.evaluateAsEBV(BF.bindings())).toEqual(false); | ||
}); | ||
it('is able to evaluate to false', async() => { | ||
const evaluator = factory.createEvaluator(getMockExpression('0'), actionContext); | ||
expect(await evaluator.evaluateAsEBV(BF.bindings())).toEqual(false); | ||
}); | ||
}); | ||
|
||
describe('evaluateAsInternal', () => { | ||
it('is able to evaluate', async() => { | ||
const evaluator = new AsyncEvaluator(parse('1 + 1')); | ||
expect(await evaluator.evaluateAsInternal(BF.bindings())).toEqual(new IntegerLiteral(2)); | ||
}); | ||
describe('evaluateAsInternal', () => { | ||
it('is able to evaluate', async() => { | ||
const evaluator = factory.createEvaluator(getMockExpression('1 + 1'), actionContext); | ||
expect(await evaluator.evaluateAsInternal(BF.bindings())).toEqual(new IntegerLiteral(2)); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.