Skip to content

Commit

Permalink
Add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
TungstnBallon committed Jul 9, 2024
1 parent 76cd4d9 commit 9bd07e1
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ describe('Validation of CSVFileLoaderExecutor', () => {
{
columnName: 'Column1',
column: {
values: ['value 1'],
values: ['somestring'],
valueType: services.ValueTypeProvider.Primitives.Text,
},
},
Expand All @@ -112,7 +112,94 @@ describe('Validation of CSVFileLoaderExecutor', () => {
if (R.isOk(result)) {
expect(result.right.ioType).toEqual(IOType.NONE);
const expectedOutput = `Column1,Column2
value 1,20.2`;
somestring,20.2`;
const actualOutput = await fsPromise.readFile('test.csv');
expect(actualOutput.toString()).toEqual(expectedOutput);
}
});
it('should handle all allowed jayvee representations', async () => {
const text = readJvTestAsset('valid-csv-file-loader.jv');

const inputTable = constructTable(
[
{
columnName: 'Strings',
column: {
values: ['somestring'],
valueType: services.ValueTypeProvider.Primitives.Text,
},
},
{
columnName: 'Decimals',
column: {
values: [20.2],
valueType: services.ValueTypeProvider.Primitives.Decimal,
},
},
{
columnName: 'Booleans',
column: {
values: [true],
valueType: services.ValueTypeProvider.Primitives.Boolean,
},
},
{
columnName: 'Integers',
column: {
values: [-10],
valueType: services.ValueTypeProvider.Primitives.Integer,
},
},
],
1,
);
const result = await parseAndExecuteExecutor(text, inputTable);

expect(R.isErr(result)).toEqual(false);
if (R.isOk(result)) {
expect(result.right.ioType).toEqual(IOType.NONE);
const expectedOutput = `Strings,Decimals,Booleans,Integers
somestring,20.2,true,-10`;
const actualOutput = await fsPromise.readFile('test.csv');
expect(actualOutput.toString()).toEqual(expectedOutput);
}
});
it('should diagnose no error with user definded properties', async () => {
const text = readJvTestAsset('escaping-csv-file-loader.jv');

const inputTable = constructTable(
[
{
columnName: 'Quoted',
column: {
values: ['quoted;'],
valueType: services.ValueTypeProvider.Primitives.Text,
},
},
{
columnName: 'Escaped',
column: {
values: ['escaped"'],
valueType: services.ValueTypeProvider.Primitives.Text,
},
},
{
columnName: 'Regular',
column: {
values: ['regular'],
valueType: services.ValueTypeProvider.Primitives.Boolean,
},
},
],
1,
);
const result = await parseAndExecuteExecutor(text, inputTable);

expect(R.isErr(result)).toEqual(false);
if (R.isOk(result)) {
expect(result.right.ioType).toEqual(IOType.NONE);
const expectedOutput = `Quoted;Escaped;Regular
"quoted;";"escaped\\"";regular`;
const actualOutput = await fsPromise.readFile('test.csv');
expect(actualOutput.toString()).toEqual(expectedOutput);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// SPDX-FileCopyrightText: 2023 Friedrich-Alexander-Universitat Erlangen-Nurnberg
//
// SPDX-License-Identifier: AGPL-3.0-only

pipeline TestPipeline {

block TestExtractor oftype TestFileExtractor { }

block TestBlock oftype CSVFileLoader {
file: "./test.csv";
delimiter: ";";
enclosing: '"';
enclosingEscape: "\\";
}

TestExtractor
-> TestBlock;
}

This file was deleted.

This file was deleted.

0 comments on commit 9bd07e1

Please sign in to comment.