Skip to content

Add generated.json with fixture contents from passing tests #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions create-legacy-zip.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
const fs = require('fs');
const path = require('path');

const generatedJsonPath = './generated.json';
const fixturesDir = './__fixtures__';
const outputDir = './legacy-13';

function createDirectoryStructure(filePath) {
const dir = path.dirname(filePath);
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir, { recursive: true });
}
}

function main() {
console.log('Reading generated.json to get fixture paths...');
const generatedData = JSON.parse(fs.readFileSync(generatedJsonPath, 'utf8'));
const fixturePaths = Object.keys(generatedData);

console.log(`Found ${fixturePaths.length} fixture files to copy`);

if (fs.existsSync(outputDir)) {
console.log('Removing existing legacy-13 directory...');
fs.rmSync(outputDir, { recursive: true, force: true });
}

fs.mkdirSync(outputDir, { recursive: true });

let copiedCount = 0;
let errorCount = 0;

for (const fixturePath of fixturePaths) {
const sourcePath = path.join(fixturesDir, fixturePath);
const destPath = path.join(outputDir, fixturePath);

try {
createDirectoryStructure(destPath);

if (fs.existsSync(sourcePath)) {
fs.copyFileSync(sourcePath, destPath);
copiedCount++;
console.log(`Copied: ${fixturePath}`);
} else {
console.error(`Source file not found: ${sourcePath}`);
errorCount++;
}
} catch (error) {
console.error(`Error copying ${fixturePath}:`, error.message);
errorCount++;
}
}

console.log(`\nSummary:`);
console.log(`- Successfully copied: ${copiedCount} files`);
console.log(`- Errors: ${errorCount} files`);
console.log(`- Output directory: ${outputDir}`);

console.log('\nDirectory structure created:');
function listDirectory(dir, prefix = '') {
const items = fs.readdirSync(dir, { withFileTypes: true });
items.forEach((item, index) => {
const isLast = index === items.length - 1;
const currentPrefix = prefix + (isLast ? '└── ' : '├── ');
console.log(currentPrefix + item.name);

if (item.isDirectory()) {
const nextPrefix = prefix + (isLast ? ' ' : '│ ');
listDirectory(path.join(dir, item.name), nextPrefix);
}
});
}

if (fs.existsSync(outputDir)) {
listDirectory(outputDir);
}
}

if (require.main === module) {
main();
}
96 changes: 96 additions & 0 deletions generate-fixtures.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
const fs = require('fs');
const path = require('path');

const testFilePath = './packages/deparser/__tests__/kitchen-sink.test.ts';
const fixturesDir = './__fixtures__';
const outputFile = './generated.json';

function parseTestFile() {
const content = fs.readFileSync(testFilePath, 'utf8');
const lines = content.split('\n');

const fixtureFiles = [];

for (let i = 0; i < lines.length; i++) {
const line = lines[i].trim();

if (line.startsWith('//') || line.startsWith('/*')) {
continue;
}

if (line.includes('xit(')) {
continue;
}

if (line.includes('it(') && line.includes('check(')) {
const checkMatch = line.match(/check\(['"`]([^'"`]+)['"`]\)/);
if (checkMatch) {
fixtureFiles.push(checkMatch[1]);
}
}

if (line.includes('it(') && i + 1 < lines.length) {
const nextLine = lines[i + 1].trim();
if (nextLine.includes('check(') && !nextLine.includes('xit(')) {
const checkMatch = nextLine.match(/check\(['"`]([^'"`]+)['"`]\)/);
if (checkMatch) {
fixtureFiles.push(checkMatch[1]);
}
}
}
}

return [...new Set(fixtureFiles)]; // Remove duplicates
}

function readFixtureFiles(fixtureFiles) {
const result = {};
const missingFiles = [];

for (const fixturePath of fixtureFiles) {
const fullPath = path.join(fixturesDir, fixturePath);

try {
if (fs.existsSync(fullPath)) {
const content = fs.readFileSync(fullPath, 'utf8');
result[fixturePath] = content;
} else {
missingFiles.push(fixturePath);
}
} catch (error) {
console.error(`Error reading ${fullPath}:`, error.message);
missingFiles.push(fixturePath);
}
}

if (missingFiles.length > 0) {
console.warn('Missing fixture files:', missingFiles);
}

return result;
}

function main() {
console.log('Parsing test file...');
const fixtureFiles = parseTestFile();
console.log(`Found ${fixtureFiles.length} fixture files from passing tests`);

console.log('Reading fixture file contents...');
const fixtureContents = readFixtureFiles(fixtureFiles);
console.log(`Successfully read ${Object.keys(fixtureContents).length} fixture files`);

console.log('Writing generated.json...');
fs.writeFileSync(outputFile, JSON.stringify(fixtureContents, null, 2));
console.log(`Generated ${outputFile} with ${Object.keys(fixtureContents).length} entries`);

console.log('\nSample entries:');
const entries = Object.entries(fixtureContents);
for (let i = 0; i < Math.min(5, entries.length); i++) {
const [path, content] = entries[i];
console.log(`${path}: ${content.length} characters`);
}
}

if (require.main === module) {
main();
}
112 changes: 112 additions & 0 deletions generated.json

Large diffs are not rendered by default.

Binary file added legacy-13.zip
Binary file not shown.
172 changes: 172 additions & 0 deletions legacy-13/a_expr.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
CREATE VIEW superschema.app_authorized_grants AS
SELECT
coalesce(nullif(s[1], ''), 'PUBLIC') as grantee,
relname as table_name,
nspname as table_schema,
string_agg(s[2], ', ') as privileges,
relkind as table_type
FROM
pg_class c
join pg_namespace n on n.oid = relnamespace
join pg_roles r on r.oid = relowner,
unnest(coalesce(relacl::text[], format('{%%s=arwdDxt/%%s}', rolname, rolname)::text[])) acl,
regexp_split_to_array(acl, '=|/') s
WHERE (s[1] = 'authenticated' or s[1] is null) and nspname not in ('pg_catalog', 'information_schema', 'pg_toast')
GROUP BY grantee, table_name, table_schema, relkind
ORDER BY relkind != 'r', relkind != 'v', relkind != 'm', relkind != 'i', relkind, nspname, relname;

-- AEXPR_OP
select a = b;

-- AEXPR_OP_ANY
SELECT foo = ANY(x) FROM vtable;

-- AEXPR_OP_ALL
SELECT foo = ALL(x) FROM vtable;

-- AEXPR_DISTINCT
-- AEXPR_NOT_DISTINCT

SELECT foo,bar FROM vtable WHERE foo IS DISTINCT FROM bar;
SELECT foo,bar FROM vtable WHERE foo IS NOT DISTINCT FROM bar;

SELECT t1.foo,t1.bar,t1.baz
FROM t1
LEFT OUTER JOIN t2 ON (
t1.foo IS NOT DISTINCT FROM t2.foo
AND t1.bar IS NOT DISTINCT FROM t2.bar
AND t1.baz IS NOT DISTINCT FROM t2.baz
)
WHERE ( t2.foo IS NULL );



-- AEXPR_NULLIF

select nullif(null, '');

-- AEXPR_OF

SELECT x, x IS OF (text) AS is_text FROM q;
SELECT x, x IS NOT OF (text) AS is_text FROM q;
SELECT COALESCE(4::domainint4, 7::domainint4) IS OF ( domainint4 ) AS t;

-- AEXPR_IN

SELECT
value IN (SELECT column_name FROM table_name);

SELECT
value NOT IN (SELECT column_name FROM table_name);

SELECT customer_id,
rental_id,
return_date
FROM
rental
WHERE
customer_id IN (1, 2)
ORDER BY
return_date DESC;


SELECT
customer_id,
rental_id,
return_date
FROM
rental
WHERE
customer_id NOT IN (1, 2);

SELECT
customer_id,
rental_id,
return_date
FROM
rental
WHERE
customer_id <> 1
AND customer_id <> 2;

SELECT *
FROM Employees
WHERE name IN ('James John', 'Mercy Bush', 'Kate Joel');

SELECT *
FROM Employees
WHERE name NOT IN ('James John', 'Mercy Bush', 'Kate Joel');

SELECT customer_id
FROM rental
WHERE CAST (return_date AS DATE) = '2005-05-27'
ORDER BY customer_id;

SELECT
customer_id,
first_name,
last_name
FROM
customer
WHERE
customer_id IN (
SELECT customer_id
FROM rental
WHERE CAST (return_date AS DATE) = '2005-05-27'
)
ORDER BY customer_id;

-- AEXPR_LIKE

SELECT * FROM student WHERE name LIKE 'a%';
SELECT * FROM student WHERE name NOT LIKE 'a%';
SELECT
'foo' LIKE 'foo',
'foo' LIKE 'f%',
'foo' LIKE '_o_',
'bar' LIKE 'b_';

-- AEXPR_ILIKE

SELECT * FROM student WHERE name ILIKE 'a%';
SELECT * FROM student WHERE name NOT ILIKE 'a%';


-- AEXPR_SIMILAR

select 'xyz' SIMILAR TO 'xyz';
select 'xyz' SIMILAR TO 'x';
select 'xyz' SIMILAR TO '%(y|a)%';
select 'xyz' SIMILAR TO '(y|z)%';

select 'xyz' SIMILAR TO 'xyz' ESCAPE 'x';
select 'xyz' SIMILAR TO 'x' ESCAPE 'x';
select 'xyz' SIMILAR TO '%(y|a)%' ESCAPE 'x';
select 'xyz' SIMILAR TO '(y|z)%' ESCAPE 'x';

select 'xyz' NOT SIMILAR TO 'xyz';
select 'xyz' NOT SIMILAR TO 'x';
select 'xyz' NOT SIMILAR TO '%(y|a)%';
select 'xyz' NOT SIMILAR TO '(y|z)%';

select 'xyz' NOT SIMILAR TO 'xyz' ESCAPE 'x';
select 'xyz' NOT SIMILAR TO 'x' ESCAPE 'x';
select 'xyz' NOT SIMILAR TO '%(y|a)%' ESCAPE 'x';
select 'xyz' NOT SIMILAR TO '(y|z)%' ESCAPE 'x';

-- AEXPR_BETWEEN
-- AEXPR_NOT_BETWEEN
-- AEXPR_BETWEEN_SYM
-- AEXPR_NOT_BETWEEN_SYM

select * from generate_series(1,10) as numbers(a)
where numbers.a between symmetric 6 and 3;

select * from generate_series(1,10) as numbers(a)
where numbers.a between 6 and 3;

select * from generate_series(1,10) as numbers(a)
where numbers.a not between symmetric 6 and 3;

select * from generate_series(1,10) as numbers(a)
where numbers.a not between 6 and 3;
8 changes: 8 additions & 0 deletions legacy-13/alter/alter-table-column.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
ALTER TABLE public.table1 ALTER COLUMN id ADD GENERATED ALWAYS AS IDENTITY (
SEQUENCE NAME public.table1
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1
)
Loading