Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rlaiola committed Apr 18, 2024
1 parent 1038784 commit 0746c61
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 0 deletions.
67 changes: 67 additions & 0 deletions src/db/tests/translate_tests_ra.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1223,3 +1223,70 @@ QUnit.test('groupby textgen', function (assert) {
"\t'a' , 1 \n" +
'} ) ');
});

QUnit.test('whitespace(s) between aggregate function and opening parenthesis', function (assert) {
const result = exec_ra("gamma ; sum (a)->total_a (R)", getTestRelations()).getResult();
result.eliminateDuplicateRows();

const reference = exec_ra('{total_a\n' +
'19\n' +
'}', {}).getResult();

assert.deepEqual(result, reference);
});

QUnit.test('whitespace(s) between count(*) function and opening parenthesis', function (assert) {
const result = exec_ra("gamma ; count (*)->n (R)", getTestRelations()).getResult();
result.eliminateDuplicateRows();

const reference = exec_ra('{n\n' +
'5\n' +
'}', {}).getResult();

assert.deepEqual(result, reference);
});

QUnit.test('whitespace(s) between n-ary text function and opening parenthesis', function (assert) {
const result = exec_ra("pi concat (a, b, c)->k (R)", getTestRelations()).getResult();
result.eliminateDuplicateRows();

const reference = exec_ra('{k\n' +
'1ad\n' +
'3cc\n' +
'4df\n' +
'5db\n' +
'6ef\n' +
'}', {}).getResult();

assert.deepEqual(result, reference);
});

QUnit.test('whitespace(s) between binary function and opening parenthesis', function (assert) {
const result = exec_ra("pi add (a, 5)->a_plus_5 (R)", getTestRelations()).getResult();
result.eliminateDuplicateRows();

const reference = exec_ra('{a_plus_5\n' +
'6\n' +
'8\n' +
'9\n' +
'10\n' +
'11\n' +
'}', {}).getResult();

assert.deepEqual(result, reference);
});

QUnit.test('whitespace(s) between unary function and opening parenthesis', function (assert) {
const result = exec_ra("pi a + length ( c )->x, upper ( b )->k (R)", getTestRelations()).getResult();
result.eliminateDuplicateRows();

const reference = exec_ra('{\tx:number, k:string\n' +
"\t2, 'A'\n" +
"\t4, 'C'\n" +
"\t5, 'D'\n" +
"\t6, 'D'\n" +
"\t7, 'E'\n" +
'}', {}).getResult();

assert.deepEqual(result, reference);
});
45 changes: 45 additions & 0 deletions src/db/tests/translate_tests_sql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -907,3 +907,48 @@ QUnit.skip('test aggregate function in value-expression', function (assert) {

assert.deepEqual(exec_sql(query).getResult(), exec_ra(queryRef).getResult());
});

QUnit.test('whitespace(s) between aggregate function and opening parenthesis', function (assert) {
const query = `
SELECT sum(a) AS total_a
FROM R`;
const queryRef = `gamma ; sum (a)->total_a (R)`;

assert.deepEqual(exec_sql(query).getResult(), exec_ra(queryRef).getResult());
});

QUnit.test('whitespace(s) between count(*) function and opening parenthesis', function (assert) {
const query = `
SELECT count (*) AS n
FROM R`;
const queryRef = `gamma ; count(*)->n (R)`;

assert.deepEqual(exec_sql(query).getResult(), exec_ra(queryRef).getResult());
});

QUnit.test('whitespace(s) between n-ary text function and opening parenthesis', function (assert) {
const query = `
SELECT concat (a, b, c) AS k
FROM R`;
const queryRef = `pi concat(a, b, c)->k (R)`;

assert.deepEqual(exec_sql(query).getResult(), exec_ra(queryRef).getResult());
});

QUnit.test('whitespace(s) between binary function and opening parenthesis', function (assert) {
const query = `
SELECT add (a, 5) AS a_plus_5
FROM R`;
const queryRef = `pi add(a, 5)->a_plus_5 (R)`;

assert.deepEqual(exec_sql(query).getResult(), exec_ra(queryRef).getResult());
});

QUnit.test('whitespace(s) between unary function and opening parenthesis', function (assert) {
const query = `
SELECT a + length ( c ) AS x, upper ( b ) AS k
FROM R`;
const queryRef = `pi a + length(c)->x, upper(b)->k (R)`;

assert.deepEqual(exec_sql(query).getResult(), exec_ra(queryRef).getResult());
});

0 comments on commit 0746c61

Please sign in to comment.