Skip to content

Commit 3828af2

Browse files
Copilotmathiasrw
andauthored
Improve test coverage for JOINSTAR with qualified table names (#2198)
Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: mathiasrw <[email protected]> Co-authored-by: Mathias Wulff <[email protected]>
1 parent 9b3888d commit 3828af2

File tree

2 files changed

+116
-8
lines changed

2 files changed

+116
-8
lines changed

test/test2197.js

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
if (typeof exports === 'object') {
2+
var assert = require('assert');
3+
var alasql = require('..');
4+
}
5+
6+
// Test for JOINSTAR Feature Incompatibility with Qualified Table Names
7+
8+
describe('Test 2197 JOINSTAR with Qualified Table Names', function () {
9+
var testId = 2197;
10+
11+
before(function () {
12+
alasql('CREATE DATABASE test' + testId);
13+
});
14+
15+
after(function () {
16+
alasql.options.joinstar = 'overwrite';
17+
alasql('DROP DATABASE test' + testId);
18+
});
19+
20+
it('1. Create tables', () => {
21+
alasql('CREATE TABLE test' + testId + '.one (a INT)');
22+
alasql('INSERT INTO test' + testId + '.one VALUES (1),(2)');
23+
alasql('CREATE TABLE test' + testId + '.two (a INT)');
24+
alasql('INSERT INTO test' + testId + '.two VALUES (10),(20)');
25+
});
26+
27+
it('2. OVERWRITE JOINSTAR with qualified names', () => {
28+
alasql.options.joinstar = 'overwrite';
29+
var res = alasql('SELECT * FROM test' + testId + '.one, test' + testId + '.two');
30+
assert.deepEqual(res, [{a: 10}, {a: 20}, {a: 10}, {a: 20}]);
31+
});
32+
33+
it('3. JSON JOINSTAR with qualified names', () => {
34+
alasql.options.joinstar = 'json';
35+
alasql.databases.alasql.dbversion++; // Reset database cache (for current database context)
36+
var res = alasql('SELECT * FROM test' + testId + '.one, test' + testId + '.two');
37+
// Expected: nested objects by table name
38+
assert.deepEqual(res, [
39+
{one: {a: 1}, two: {a: 10}},
40+
{one: {a: 1}, two: {a: 20}},
41+
{one: {a: 2}, two: {a: 10}},
42+
{one: {a: 2}, two: {a: 20}},
43+
]);
44+
});
45+
46+
it('4. UNDERSCORE JOINSTAR with qualified names', () => {
47+
alasql.options.joinstar = 'underscore';
48+
alasql.databases.alasql.dbversion++; // Reset database cache (for current database context)
49+
var res = alasql('SELECT * FROM test' + testId + '.one, test' + testId + '.two');
50+
// Expected: columns prefixed with table names
51+
assert.deepEqual(res, [
52+
{one_a: 1, two_a: 10},
53+
{one_a: 1, two_a: 20},
54+
{one_a: 2, two_a: 10},
55+
{one_a: 2, two_a: 20},
56+
]);
57+
});
58+
59+
it('5. JSON JOINSTAR with USE database', () => {
60+
alasql('USE test' + testId);
61+
alasql.options.joinstar = 'json';
62+
alasql.databases['test' + testId].dbversion++; // Reset database cache
63+
var res = alasql('SELECT * FROM one, two');
64+
// Expected: nested objects by table name (should work)
65+
assert.deepEqual(res, [
66+
{one: {a: 1}, two: {a: 10}},
67+
{one: {a: 1}, two: {a: 20}},
68+
{one: {a: 2}, two: {a: 10}},
69+
{one: {a: 2}, two: {a: 20}},
70+
]);
71+
});
72+
73+
it('6. UNDERSCORE JOINSTAR with USE database', () => {
74+
alasql('USE test' + testId);
75+
alasql.options.joinstar = 'underscore';
76+
alasql.databases['test' + testId].dbversion++; // Reset database cache
77+
var res = alasql('SELECT * FROM one, two');
78+
// Expected: columns prefixed with table names (should work)
79+
assert.deepEqual(res, [
80+
{one_a: 1, two_a: 10},
81+
{one_a: 1, two_a: 20},
82+
{one_a: 2, two_a: 10},
83+
{one_a: 2, two_a: 20},
84+
]);
85+
});
86+
});

test/test421.js

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,18 @@ describe('Test 421 Test for JOINSTAR', function () {
1717
alasql('DROP DATABASE test' + test);
1818
});
1919

20-
it('1. Create tables', function (done) {
20+
it('1. Create tables', () => {
2121
alasql('CREATE TABLE one (a INT); INSERT INTO one VALUES (1),(2)');
2222
alasql('CREATE TABLE two (a INT); INSERT INTO two VALUES (10),(20)');
23-
done();
2423
});
2524

26-
it('2. OVERWRITE JOINSTAR', function (done) {
25+
it('2. OVERWRITE JOINSTAR', () => {
2726
alasql.options.joinstar = 'overwrite';
2827
var res = alasql('SELECT * FROM one,two');
2928
assert.deepEqual(res, [{a: 10}, {a: 20}, {a: 10}, {a: 20}]);
30-
done();
3129
});
3230

33-
it('3. JSON JOINSTAR', function (done) {
31+
it('3. JSON JOINSTAR', () => {
3432
alasql.options.joinstar = 'json';
3533
alasql.databases.test421.dbversion++; // Reset database cache
3634
var res = alasql('SELECT * FROM one,two');
@@ -41,10 +39,9 @@ describe('Test 421 Test for JOINSTAR', function () {
4139
{one: {a: 2}, two: {a: 10}},
4240
{one: {a: 2}, two: {a: 20}},
4341
]);
44-
done();
4542
});
4643

47-
it('4. UNDESCORE JOINSTAR', function (done) {
44+
it('4. UNDESCORE JOINSTAR', () => {
4845
alasql.options.joinstar = 'underscore';
4946
alasql.databases.test421.dbversion++; // Reset database cache
5047
var res = alasql('SELECT * FROM one,two');
@@ -55,6 +52,31 @@ describe('Test 421 Test for JOINSTAR', function () {
5552
{one_a: 2, two_a: 10},
5653
{one_a: 2, two_a: 20},
5754
]);
58-
done();
55+
});
56+
57+
it('5. JSON JOINSTAR with qualified names', () => {
58+
alasql.options.joinstar = 'json';
59+
alasql.databases.test421.dbversion++; // Reset database cache
60+
var res = alasql('SELECT * FROM test' + test + '.one, test' + test + '.two');
61+
//console.log(res);
62+
assert.deepEqual(res, [
63+
{one: {a: 1}, two: {a: 10}},
64+
{one: {a: 1}, two: {a: 20}},
65+
{one: {a: 2}, two: {a: 10}},
66+
{one: {a: 2}, two: {a: 20}},
67+
]);
68+
});
69+
70+
it('6. UNDERSCORE JOINSTAR with qualified names', () => {
71+
alasql.options.joinstar = 'underscore';
72+
alasql.databases.test421.dbversion++; // Reset database cache
73+
var res = alasql('SELECT * FROM test' + test + '.one, test' + test + '.two');
74+
//console.log(res);
75+
assert.deepEqual(res, [
76+
{one_a: 1, two_a: 10},
77+
{one_a: 1, two_a: 20},
78+
{one_a: 2, two_a: 10},
79+
{one_a: 2, two_a: 20},
80+
]);
5981
});
6082
});

0 commit comments

Comments
 (0)