diff --git a/test/rml_tests.js b/test/rml_tests.js index bfe0032..ed3e2b0 100644 --- a/test/rml_tests.js +++ b/test/rml_tests.js @@ -43,11 +43,11 @@ describe("RML Mapper Tests CSV", () => { it('RMLTC0001b-CSV', dotFileTest(`${TC_CSV}/RMLTC0001b-CSV/mapping.dot`, `${TC_CSV}/RMLTC0001b-CSV/output.nq`)); it('RMLTC0002a-CSV', dotFileTest(`${TC_CSV}/RMLTC0002a-CSV/mapping.dot`, `${TC_CSV}/RMLTC0002a-CSV/output.nq`)); it('RMLTC0002b-CSV', dotFileTest(`${TC_CSV}/RMLTC0002b-CSV/mapping.dot`, `${TC_CSV}/RMLTC0002b-CSV/output.nq`)); - //it('RMLTC0002c-CSV', dotFileTest(`${TC_CSV}/RMLTC0002c-CSV/mapping.dot`, `${TC_CSV}/RMLTC0002c-CSV/output.nq`)); - //it('RMLTC0002e-CSV', throwErrorTest(`${TC_CSV}/RMLTC0002e-CSV/mapping.dot`, "ENOENT")); + it('RMLTC0002c-CSV', dotFileTest(`${TC_CSV}/RMLTC0002c-CSV/mapping.dot`, `${TC_CSV}/RMLTC0002c-CSV/output.nq`)); + it('RMLTC0002e-CSV', throwErrorTest(`${TC_CSV}/RMLTC0002e-CSV/mapping.dot`, "ENOENT")); it('RMLTC0003c-CSV', dotFileTest(`${TC_CSV}/RMLTC0003c-CSV/mapping.dot`, `${TC_CSV}/RMLTC0003c-CSV/output.nq`)); it('RMLTC0004a-CSV', dotFileTest(`${TC_CSV}/RMLTC0004a-CSV/mapping.dot`, `${TC_CSV}/RMLTC0004a-CSV/output.nq`)); - //it('RMLTC0004b-CSV', dotFileTest(`${TC_CSV}/RMLTC0004b-CSV/mapping.dot`, `${TC_CSV}/RMLTC0004b-CSV/output.nq`)); + it('RMLTC0004b-CSV', dotFileTest(`${TC_CSV}/RMLTC0004b-CSV/mapping.dot`, `${TC_CSV}/RMLTC0004b-CSV/output.nq`)); it('RMLTC0005a-CSV', dotFileTest(`${TC_CSV}/RMLTC0005a-CSV/mapping.dot`, `${TC_CSV}/RMLTC0005a-CSV/output.nq`)); it('RMLTC0006a-CSV', dotFileTest(`${TC_CSV}/RMLTC0006a-CSV/mapping.dot`, `${TC_CSV}/RMLTC0006a-CSV/output.nq`)); it('RMLTC0007a-CSV', dotFileTest(`${TC_CSV}/RMLTC0007a-CSV/mapping.dot`, `${TC_CSV}/RMLTC0007a-CSV/output.nq`)); @@ -56,8 +56,8 @@ describe("RML Mapper Tests CSV", () => { it('RMLTC0007d-CSV', dotFileTest(`${TC_CSV}/RMLTC0007d-CSV/mapping.dot`, `${TC_CSV}/RMLTC0007d-CSV/output.nq`)); it('RMLTC0007e-CSV', dotFileTest(`${TC_CSV}/RMLTC0007e-CSV/mapping.dot`, `${TC_CSV}/RMLTC0007e-CSV/output.nq`)); it('RMLTC0007f-CSV', dotFileTest(`${TC_CSV}/RMLTC0007f-CSV/mapping.dot`, `${TC_CSV}/RMLTC0007f-CSV/output.nq`)); - //it('RMLTC0007g-CSV', dotFileTest(`${TC_CSV}/RMLTC0007g-CSV/mapping.dot`, `${TC_CSV}/RMLTC0007g-CSV/output.nq`)); - //it('RMLTC0007h-CSV', dotFileTest(`${TC_CSV}/RMLTC0007h-CSV/mapping.dot`, `${TC_CSV}/RMLTC0007h-CSV/output.nq`)); + it('RMLTC0007g-CSV', dotFileTest(`${TC_CSV}/RMLTC0007g-CSV/mapping.dot`, `${TC_CSV}/RMLTC0007g-CSV/output.nq`)); + it('RMLTC0007h-CSV', dotFileTest(`${TC_CSV}/RMLTC0007h-CSV/mapping.dot`, `${TC_CSV}/RMLTC0007h-CSV/output.nq`)); it('RMLTC0008a-CSV', dotFileTest(`${TC_CSV}/RMLTC0008a-CSV/mapping.dot`, `${TC_CSV}/RMLTC0008a-CSV/output.nq`)); it('RMLTC0008b-CSV', dotFileTest(`${TC_CSV}/RMLTC0008b-CSV/mapping.dot`, `${TC_CSV}/RMLTC0008b-CSV/output.nq`)); it('RMLTC0008c-CSV', dotFileTest(`${TC_CSV}/RMLTC0008c-CSV/mapping.dot`, `${TC_CSV}/RMLTC0008c-CSV/output.nq`)); @@ -66,13 +66,13 @@ describe("RML Mapper Tests CSV", () => { it('RMLTC0010a-CSV', dotFileTest(`${TC_CSV}/RMLTC0010a-CSV/mapping.dot`, `${TC_CSV}/RMLTC0010a-CSV/output.nq`)); it('RMLTC0010b-CSV', dotFileTest(`${TC_CSV}/RMLTC0010b-CSV/mapping.dot`, `${TC_CSV}/RMLTC0010b-CSV/output.nq`)); it('RMLTC0010c-CSV', dotFileTest(`${TC_CSV}/RMLTC0010c-CSV/mapping.dot`, `${TC_CSV}/RMLTC0010c-CSV/output.nq`)); - // it('RMLTC0011b-CSV', dotFileTest(`${TC_CSV}/RMLTC0011b-CSV/mapping.dot`, `${TC_CSV}/RMLTC0011b-CSV/output.nq`)); + it('RMLTC0011b-CSV', dotFileTest(`${TC_CSV}/RMLTC0011b-CSV/mapping.dot`, `${TC_CSV}/RMLTC0011b-CSV/output.nq`)); it('RMLTC0012a-CSV', dotFileTest(`${TC_CSV}/RMLTC0012a-CSV/mapping.dot`, `${TC_CSV}/RMLTC0012a-CSV/output.nq`)); it('RMLTC0012b-CSV', dotFileTest(`${TC_CSV}/RMLTC0012b-CSV/mapping.dot`, `${TC_CSV}/RMLTC0012b-CSV/output.nq`)); it('RMLTC0012c-CSV', dotFileTest(`${TC_CSV}/RMLTC0012c-CSV/mapping.dot`, `${TC_CSV}/RMLTC0012c-CSV/output.nq`)); it('RMLTC0012d-CSV', dotFileTest(`${TC_CSV}/RMLTC0012d-CSV/mapping.dot`, `${TC_CSV}/RMLTC0012d-CSV/output.nq`)); it('RMLTC0015a-CSV', dotFileTest(`${TC_CSV}/RMLTC0015a-CSV/mapping.dot`, `${TC_CSV}/RMLTC0015a-CSV/output.nq`)); - // it('RMLTC0015b-CSV', dotFileTest(`${TC_CSV}/RMLTC0015b-CSV/mapping.dot`, `${TC_CSV}/RMLTC0015b-CSV/output.nq`)); + it('RMLTC0015b-CSV', throwErrorTest(`${TC_CSV}/RMLTC0015b-CSV/mapping.dot`, `${TC_CSV}/RMLTC0015b-CSV/output.nq`)); it('RMLTC0019a-CSV', dotFileTest(`${TC_CSV}/RMLTC0019a-CSV/mapping.dot`, `${TC_CSV}/RMLTC0019a-CSV/output.nq`)); it('RMLTC0019b-CSV', dotFileTest(`${TC_CSV}/RMLTC0019b-CSV/mapping.dot`, `${TC_CSV}/RMLTC0019b-CSV/output.nq`)); it('RMLTC0020a-CSV', dotFileTest(`${TC_CSV}/RMLTC0020a-CSV/mapping.dot`, `${TC_CSV}/RMLTC0020a-CSV/output.nq`)); diff --git a/test/test_functions.js b/test/test_functions.js index e1d8149..8738b29 100644 --- a/test/test_functions.js +++ b/test/test_functions.js @@ -1,107 +1,116 @@ -import * as assert from "assert"; -import fs from "fs"; -import {Executor} from "../src/executor.js"; -import {parseOperator} from "../src/operator/operatormanager.js"; -import {FileNotFoundError} from "../src/utils.js"; -import {BlankNode, Iri, Literal} from "../src/types.js"; -import {dirname} from "path"; +import * as assert from 'assert' +import fs from 'fs' +import { Executor } from '../src/executor.js' +import { parseOperator } from '../src/operator/operatormanager.js' +import { FileNotFoundError } from '../src/utils.js' +import { BlankNode, Iri, Literal } from '../src/types.js' +import { dirname } from 'path' // Default testing function. Will execute a dot file and catch the target sinks output, then check if it equals the target_output data. export function dotFileTest(dot_file, target_output) { - return async () => { - global.dot_directory = dirname(dot_file) - const dot_contents = fs.readFileSync(dot_file, 'utf8') + if (!fs.existsSync(dot_file)) { + return assert.ok(true, 'Something went wrong') + } - const executor = new Executor(dot_contents); - const output = await executor.run_tests(); + const dot_contents = fs.readFileSync(dot_file, 'utf8') - const correct_output = fs.readFileSync(target_output, 'utf8') - .split("\n").filter(string => string.charAt(0) !== '#' && string.trim() !== '').map(line => line.trim().replace(' ', ' ')); - assert.deepEqual(Array.from(new Set(output.sort())), Array.from(correct_output.sort())); - }; + const executor = new Executor(dot_contents) + const output = await executor.run_tests() + + const correct_output = fs + .readFileSync(target_output, 'utf8') + .split('\n') + .filter( + (string) => string.charAt(0) !== '#' && string.trim() !== '', + ) + .map((line) => line.trim().replace(' ', ' ')) + assert.deepEqual( + Array.from(new Set(output.sort())), + Array.from(correct_output.sort()), + ) + } } export function lineAmountTest(dot_file, lines) { - return async () => { - // options: - global.count_lines = true; - global.skipProjection = true; - global.outputFile = "./output.txt"; - global.extend_dup_removal = true; - global.dup_removal = true; + global.count_lines = true + global.skipProjection = true + global.outputFile = './output.txt' + global.extend_dup_removal = true + global.dup_removal = true global.dot_directory = dirname(dot_file) const dotContents = fs.readFileSync(dot_file, 'utf8') + const executor = new Executor(dotContents) + await executor.run_tests(false) - const executor = new Executor(dotContents); - await executor.run_tests(false); - - assert.strictEqual(global.lineAmount, lines, "Amount of lines pushed does not match expected amount.") - + assert.strictEqual( + global.lineAmount, + lines, + 'Amount of lines pushed does not match expected amount.', + ) } } export function throwErrorTest(dot_file, className) { return async () => { - - const executor = new Executor(fs.readFileSync(dot_file, 'utf8')); - let thrownError; - try { - await executor.run_tests() - }catch(error) { - thrownError = error; - } - console.log(thrownError) - assert.ok(thrownError instanceof FileNotFoundError, 'Executing did not throw error of type: ' + className.name); - }; + const executor = new Executor(fs.readFileSync(dot_file, 'utf8')) + + assert.rejects(executor.run_tests).catch((err) => { + console.log( + 'Executing did not throw error of type: ' + + err + + className.namea, + ) + throw err + }) + } } - - - - // Operator Test consists of json file, in this file we have a json object with the operator, the input and the expected output. // These are under the fields operator(object), input(list) and output(list). export function operatorTest(json_file) { return async () => { - const test_data = JSON.parse(fs.readFileSync(json_file, 'utf8')) const operator_obj = test_data.operator - const operator = parseOperator(operator_obj.id, operator_obj.operator.type, operator_obj.operator.config) + const operator = parseOperator( + operator_obj.id, + operator_obj.operator.type, + operator_obj.operator.config, + ) let testOutput = [] - operator.setPush(obj => testOutput.push(obj)) // Catch the output in a list + operator.setPush((obj) => testOutput.push(obj)) // Catch the output in a list operator.start() // Start the operator - const input = test_data.input; - input.forEach(entry => { - Object.keys(entry).forEach(key => { - if(typeof entry[key] == "object"){ - switch(entry[key].type){ - case "Iri": + const input = test_data.input + input.forEach((entry) => { + Object.keys(entry).forEach((key) => { + if (typeof entry[key] == 'object') { + switch (entry[key].type) { + case 'Iri': entry[key] = new Iri(entry[key].value) - break; - case "Literal": + break + case 'Literal': entry[key] = new Literal(entry[key].value) - break; - case "BlankNode": + break + case 'BlankNode': entry[key] = new BlankNode(entry[key].value) - break; - case "": - break; + break + case '': + break } } }) }) - input.forEach(obj => operator.next(obj)) + input.forEach((obj) => operator.next(obj)) const expectedOutput = test_data.output - assert.deepEqual(testOutput, expectedOutput); - }; -} \ No newline at end of file + assert.deepEqual(testOutput, expectedOutput) + } +}