Skip to content

Commit 95bbff8

Browse files
Copilotmathiasrw
andauthored
Improve text coverage of CONTENT keyword to close #2239 (#2384)
Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: mathiasrw <[email protected]>
1 parent 4816906 commit 95bbff8

File tree

1 file changed

+202
-0
lines changed

1 file changed

+202
-0
lines changed

test/test2239.js

Lines changed: 202 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
1+
if (typeof exports === 'object') {
2+
var assert = require('assert');
3+
var alasql = require('..');
4+
}
5+
6+
describe('Test 2239 - Limit the impact of using the keyword: CONTENT', function () {
7+
const test = '2239';
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+
// 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+
22+
it('A) CONTENT as table name - CREATE and SELECT', function () {
23+
var res = alasql('CREATE TABLE content (id INT, name STRING)');
24+
assert.equal(res, 1);
25+
26+
res = alasql('INSERT INTO content VALUES (1, "Alice"), (2, "Bob")');
27+
assert.equal(res, 2);
28+
29+
res = alasql('SELECT * FROM content ORDER BY id');
30+
assert.deepEqual(res, [
31+
{id: 1, name: 'Alice'},
32+
{id: 2, name: 'Bob'},
33+
]);
34+
35+
res = alasql('DROP TABLE content');
36+
assert.equal(res, 1);
37+
});
38+
39+
it('B) CONTENT as column name - CREATE and SELECT', function () {
40+
var res = alasql('CREATE TABLE test_table (id INT, content STRING)');
41+
assert.equal(res, 1);
42+
43+
res = alasql('INSERT INTO test_table VALUES (1, "Some content"), (2, "More content")');
44+
assert.equal(res, 2);
45+
46+
res = alasql('SELECT content FROM test_table ORDER BY id');
47+
assert.deepEqual(res, [{content: 'Some content'}, {content: 'More content'}]);
48+
49+
res = alasql('SELECT id, content FROM test_table WHERE content = "Some content"');
50+
assert.deepEqual(res, [{id: 1, content: 'Some content'}]);
51+
52+
res = alasql('DROP TABLE test_table');
53+
assert.equal(res, 1);
54+
});
55+
56+
it('C) CONTENT as both table and column name', function () {
57+
var res = alasql('CREATE TABLE content (id INT, content STRING)');
58+
assert.equal(res, 1);
59+
60+
res = alasql('INSERT INTO content VALUES (1, "Test"), (2, "Data")');
61+
assert.equal(res, 2);
62+
63+
res = alasql('SELECT content FROM content ORDER BY id');
64+
assert.deepEqual(res, [{content: 'Test'}, {content: 'Data'}]);
65+
66+
res = alasql('SELECT content.content FROM content WHERE id = 1');
67+
assert.deepEqual(res, [{content: 'Test'}]);
68+
69+
res = alasql('DROP TABLE content');
70+
assert.equal(res, 1);
71+
});
72+
73+
it('D) CONTENT keyword in CREATE VERTEX SET (existing functionality)', function () {
74+
// This should still work - CONTENT is a keyword in graph operations
75+
var res = alasql('CREATE CLASS Person');
76+
assert.equal(res, 1);
77+
78+
// Using SET (not CONTENT keyword, but for comparison)
79+
res = alasql('CREATE VERTEX Person SET name = "John", age = 30');
80+
assert.ok(res); // Returns a vertex reference
81+
82+
// Clean up
83+
res = alasql('DROP CLASS Person');
84+
assert.equal(res, 1);
85+
});
86+
87+
it('E) CONTENT keyword in CREATE VERTEX CONTENT (existing functionality)', function () {
88+
// This should still work - CONTENT is a keyword in graph operations
89+
var res = alasql('CREATE CLASS Person');
90+
assert.equal(res, 1);
91+
92+
// Using CONTENT keyword in its proper context
93+
res = alasql('CREATE VERTEX Person CONTENT {name:"Alice",age:25}');
94+
assert.ok(res); // Returns a vertex reference
95+
96+
// Clean up
97+
res = alasql('DROP CLASS Person');
98+
assert.equal(res, 1);
99+
});
100+
101+
it('F) CONTENT as alias in SELECT', function () {
102+
var res = alasql('CREATE TABLE data (id INT, text STRING)');
103+
assert.equal(res, 1);
104+
105+
res = alasql('INSERT INTO data VALUES (1, "Hello"), (2, "World")');
106+
assert.equal(res, 2);
107+
108+
res = alasql('SELECT text AS content FROM data ORDER BY id');
109+
assert.deepEqual(res, [{content: 'Hello'}, {content: 'World'}]);
110+
111+
res = alasql('DROP TABLE data');
112+
assert.equal(res, 1);
113+
});
114+
115+
it('G) CONTENT in JOIN operations', function () {
116+
var res = alasql('CREATE TABLE content (id INT, text STRING)');
117+
assert.equal(res, 1);
118+
119+
res = alasql('CREATE TABLE other (id INT, data STRING)');
120+
assert.equal(res, 1);
121+
122+
res = alasql('INSERT INTO content VALUES (1, "A"), (2, "B")');
123+
assert.equal(res, 2);
124+
125+
res = alasql('INSERT INTO other VALUES (1, "X"), (2, "Y")');
126+
assert.equal(res, 2);
127+
128+
res = alasql(
129+
'SELECT content.text, other.data FROM content JOIN other ON content.id = other.id ORDER BY content.id'
130+
);
131+
assert.deepEqual(res, [
132+
{text: 'A', data: 'X'},
133+
{text: 'B', data: 'Y'},
134+
]);
135+
136+
res = alasql('DROP TABLE content');
137+
assert.equal(res, 1);
138+
139+
res = alasql('DROP TABLE other');
140+
assert.equal(res, 1);
141+
});
142+
143+
it('H) CONTENT in GROUP BY and aggregate functions', function () {
144+
var res = alasql('CREATE TABLE content (id INT, content STRING, amount INT)');
145+
assert.equal(res, 1);
146+
147+
res = alasql(
148+
'INSERT INTO content VALUES (1, "Type A", 10), (2, "Type A", 20), (3, "Type B", 15)'
149+
);
150+
assert.equal(res, 3);
151+
152+
res = alasql(
153+
'SELECT content, SUM(amount) as sum_amount FROM content GROUP BY content ORDER BY content'
154+
);
155+
assert.deepEqual(res, [
156+
{content: 'Type A', sum_amount: 30},
157+
{content: 'Type B', sum_amount: 15},
158+
]);
159+
160+
res = alasql('DROP TABLE content');
161+
assert.equal(res, 1);
162+
});
163+
164+
it('I) CONTENT in UPDATE and DELETE operations', function () {
165+
var res = alasql('CREATE TABLE content (id INT, content STRING)');
166+
assert.equal(res, 1);
167+
168+
res = alasql('INSERT INTO content VALUES (1, "Old"), (2, "Data")');
169+
assert.equal(res, 2);
170+
171+
res = alasql('UPDATE content SET content = "New" WHERE id = 1');
172+
assert.equal(res, 1);
173+
174+
res = alasql('SELECT * FROM content WHERE id = 1');
175+
assert.deepEqual(res, [{id: 1, content: 'New'}]);
176+
177+
res = alasql('DELETE FROM content WHERE content = "Data"');
178+
assert.equal(res, 1);
179+
180+
res = alasql('SELECT COUNT(*) as cnt FROM content');
181+
assert.deepEqual(res, [{cnt: 1}]);
182+
183+
res = alasql('DROP TABLE content');
184+
assert.equal(res, 1);
185+
});
186+
187+
it('J) CONTENT with subqueries', function () {
188+
var res = alasql('CREATE TABLE content (id INT, amount INT)');
189+
assert.equal(res, 1);
190+
191+
res = alasql('INSERT INTO content VALUES (1, 100), (2, 200), (3, 150)');
192+
assert.equal(res, 3);
193+
194+
res = alasql(
195+
'SELECT * FROM content WHERE amount > (SELECT AVG(amount) FROM content) ORDER BY id'
196+
);
197+
assert.deepEqual(res, [{id: 2, amount: 200}]);
198+
199+
res = alasql('DROP TABLE content');
200+
assert.equal(res, 1);
201+
});
202+
});

0 commit comments

Comments
 (0)