Skip to content

Commit

Permalink
chore: Streamline apply file update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dividedmind committed Oct 29, 2024
1 parent 62ab2fa commit 7c705fa
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 36 deletions.
47 changes: 16 additions & 31 deletions packages/cli/tests/unit/rpc/file/applyFileUpdate.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,34 +24,22 @@ describe(applyFileUpdate, () => {
process.chdir(startCwd);
});

const example =
(name: string, expectedAssertions = 1) =>
async (): Promise<string> => {
expect.assertions(expectedAssertions);
const example = (name: string) => async () => {
expect.assertions(1);

const fixtureDir = join(__dirname, 'applyFileUpdate', name);
await cp(fixtureDir, process.cwd(), { recursive: true });
const applyStr = await readFile('apply.yml', 'utf8');
const change = load(applyStr) as Change;
const { file, original, modified } = change;
const fixtureDir = join(__dirname, 'applyFileUpdate', name);
await cp(fixtureDir, process.cwd(), { recursive: true });
const applyStr = await readFile('apply.yml', 'utf8');
const change = load(applyStr) as Change;
const { file, original, modified } = change;

await applyFileUpdate(file, original, modified);
await applyFileUpdate(file, original, modified);

const updatedStr = await readFile('original.txt', 'utf8');
const updated = updatedStr
.split('\n')
.map((line) => line.trim())
.join('\n');
const expectedStr = await readFile('expected.txt', 'utf8');
const expected = expectedStr
.split('\n')
.map((line) => line.trim())
.join('\n');
const updatedStr = await readFile('original.txt', 'utf8');
const expectedStr = await readFile('expected.txt', 'utf8');

expect(updated).toEqual(expected);

return updatedStr;
};
expect(updatedStr).toEqual(expectedStr);
};

it('correctly applies an update even with broken whitespace', example('whitespace-mismatch'));
it('correctly applies an update even with trailing newlines', example('trailing-newlines'));
Expand All @@ -61,11 +49,8 @@ describe(applyFileUpdate, () => {
example('mismatched-similar')
);
it('compensates for missing indentation in the first line', example('missing-firstline-indent'));
it('compensates for missing indentation in the first line', async () => {
const updated = await example('missing-firstline-indent-must-match', 4)();
const updatedLines = updated.split('\n');
expect(updatedLines[0]).toEqual(' # hello');
expect(updatedLines[1]).toEqual(' def _bind_to_schema(self, field_name, schema):');
expect(updatedLines[2]).toEqual(' super()._bind_to_schema(field_name, schema)');
});
it(
'compensates for missing indentation in the first line (even when there is a mismatch)',
example('missing-firstline-indent-must-match')
);
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,24 @@
# A buffer for all table expressions in join conditions
from_expression_elements = []
column_reference_segments = []

from_clause_segment = segment.get_child("from_clause")

if not from_clause_segment:
return None

# Check if the FROM clause contains any JOINs
join_clauses = from_clause_segment.recursive_crawl('join_clause')
if not join_clauses:
return None

from_expression = from_clause_segment.get_child("from_expression")
from_expression_element = None
if from_expression:
from_expression_element = from_expression.get_child(
"from_expression_element"
)

if not from_expression_element:
return None
from_expression_element = from_expression_element.get_child(
Expand Down

0 comments on commit 7c705fa

Please sign in to comment.