Skip to content

Commit 6343e84

Browse files
Copilotmathiasrw
andauthored
Test coverage for CROSS JOIN to confirm #128 is closed (#2330)
Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: mathiasrw <[email protected]>
1 parent f8ed656 commit 6343e84

File tree

2 files changed

+107
-0
lines changed

2 files changed

+107
-0
lines changed

test/test000.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ describe('Test 000 - multiple statements', function () {
1515
alasql('drop database test' + test);
1616
});
1717

18+
// NOTE: Tests should use assert.deepEqual to verify the complete expected output
19+
// against the actual result object. This ensures comprehensive validation and
20+
// makes test failures more informative by showing the full diff.
21+
1822
it('A) From single lines', function () {
1923
var res = [];
2024
res.push(alasql('create table one (a int)'));

test/test128-B.js

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
if (typeof exports === 'object') {
2+
var assert = require('assert');
3+
var alasql = require('..');
4+
}
5+
6+
describe('Test 128-B CROSS JOIN with parentheses (sqllogictest)', function () {
7+
const test = '128B';
8+
9+
before(function () {
10+
alasql('create database test' + test);
11+
alasql('use test' + test);
12+
});
13+
14+
after(function () {
15+
alasql('drop database test' + test);
16+
});
17+
18+
it('A) Setup test tables', function () {
19+
alasql('CREATE TABLE tab1 (id INT, val VARCHAR(10))');
20+
alasql('CREATE TABLE tab2 (id INT, name VARCHAR(10))');
21+
alasql("INSERT INTO tab1 VALUES (1, 'A'), (2, 'B')");
22+
alasql("INSERT INTO tab2 VALUES (3, 'X'), (4, 'Y')");
23+
});
24+
25+
it('B) CROSS JOIN without parentheses (baseline)', function () {
26+
var res = alasql('SELECT -92 AS col1 FROM tab1 AS cor0 CROSS JOIN tab2 AS cor1');
27+
assert.deepEqual(res, [{col1: -92}, {col1: -92}, {col1: -92}, {col1: -92}]);
28+
});
29+
30+
it('C) CROSS JOIN with parentheses around FROM clause', function () {
31+
var res = alasql('SELECT -92 AS col1 FROM ( tab1 AS cor0 CROSS JOIN tab2 AS cor1 )');
32+
assert.deepEqual(res, [{col1: -92}, {col1: -92}, {col1: -92}, {col1: -92}]);
33+
});
34+
35+
it('D) Verify CROSS JOIN produces correct results', function () {
36+
var res = alasql(
37+
'SELECT cor0.id as id1, cor1.id as id2 FROM ( tab1 AS cor0 CROSS JOIN tab2 AS cor1 )'
38+
);
39+
assert.deepEqual(res, [
40+
{id1: 1, id2: 3},
41+
{id1: 1, id2: 4},
42+
{id1: 2, id2: 3},
43+
{id1: 2, id2: 4},
44+
]);
45+
});
46+
47+
it('E) CROSS JOIN with WHERE clause', function () {
48+
var res = alasql(
49+
'SELECT cor0.id FROM ( tab1 AS cor0 CROSS JOIN tab2 AS cor1 ) WHERE cor0.id = 1'
50+
);
51+
assert.deepEqual(res, [{id: 1}, {id: 1}]);
52+
});
53+
54+
it('F) CROSS JOIN with ORDER BY', function () {
55+
var res = alasql(
56+
'SELECT cor0.id as id1, cor1.id as id2 FROM ( tab1 AS cor0 CROSS JOIN tab2 AS cor1 ) ORDER BY cor0.id DESC, cor1.id ASC'
57+
);
58+
assert.deepEqual(res, [
59+
{id1: 2, id2: 3},
60+
{id1: 2, id2: 4},
61+
{id1: 1, id2: 3},
62+
{id1: 1, id2: 4},
63+
]);
64+
});
65+
66+
it('G) Multiple CROSS JOINs with parentheses', function () {
67+
alasql('CREATE TABLE tab3 (id INT)');
68+
alasql('INSERT INTO tab3 VALUES (5), (6)');
69+
var res = alasql(
70+
'SELECT -92 AS col1 FROM ( tab1 AS cor0 CROSS JOIN tab2 AS cor1 CROSS JOIN tab3 AS cor2 )'
71+
);
72+
assert.deepEqual(res, [
73+
{col1: -92},
74+
{col1: -92},
75+
{col1: -92},
76+
{col1: -92},
77+
{col1: -92},
78+
{col1: -92},
79+
{col1: -92},
80+
{col1: -92},
81+
]);
82+
alasql('DROP TABLE tab3');
83+
});
84+
85+
it('H) Nested subquery with CROSS JOIN in parentheses', function () {
86+
var res = alasql(
87+
'SELECT * FROM (SELECT cor0.id FROM ( tab1 AS cor0 CROSS JOIN tab2 AS cor1 )) AS sub'
88+
);
89+
assert.deepEqual(res, [{id: 1}, {id: 1}, {id: 2}, {id: 2}]);
90+
});
91+
92+
it('I) CROSS JOIN in parentheses with complex expression', function () {
93+
var res = alasql(
94+
'SELECT cor0.val, cor1.name, cor0.id * 10 + cor1.id AS computed FROM ( tab1 AS cor0 CROSS JOIN tab2 AS cor1 ) WHERE cor0.id > 0'
95+
);
96+
assert.deepEqual(res, [
97+
{val: 'A', name: 'X', computed: 13},
98+
{val: 'A', name: 'Y', computed: 14},
99+
{val: 'B', name: 'X', computed: 23},
100+
{val: 'B', name: 'Y', computed: 24},
101+
]);
102+
});
103+
});

0 commit comments

Comments
 (0)