Skip to content

Commit

Permalink
Fix failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Joe Reynolds committed Aug 15, 2024
1 parent e1bb304 commit cfe7405
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions test/unit/reader/reader.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,32 @@ import {
import { Query } from "../../../src/reader/query";
import { Line } from "../../../src/reader/line";

beforeEach(() => {
this.query = new Query();
this.query.lines = [
function getTestQuery(): Query {
const query = new Query();
query.lines = [
new Line("DELETE", 1),
new Line(" FROM ", 2),
new Line(" person WHERE ", 4),
new Line(" age > 5;", 5),
];

this.queryWithComments = new Query();
this.queryWithComments.lines = [
return query;
}

function getTestQueryWithComments(): Query {
const queryWithComments = new Query();
queryWithComments.lines = [
new Line("DELETE", 1),
new Line(" FROM ", 2),
new Line(" person WHERE ", 4),
new Line(" age > 5;", 6),
];
});

return queryWithComments;
}

test("We correctly read a file", () => {
const expected: any = [this.query];
const expected: any = [getTestQuery()];
const input = "DELETE\n FROM \n\n person WHERE \n age > 5;";
const actual = putContentIntoLines(input);
expect(actual).toEqual(expected);
Expand All @@ -41,17 +47,19 @@ test.each([
["DELETE\n FROM \n\n person WHERE \n/* Remove old people*/\n age > 5;"],
])("We ignore comments in files", (input) => {
const actual = putContentIntoLines(input);
expect(actual).toEqual([this.queryWithComments]);
expect(actual).toEqual([getTestQueryWithComments()]);
});

test("We correctly reconstruct our query from lines", () => {
const query = getTestQuery()
const expected: string = "DELETE FROM person WHERE age > 5;";
const actual = this.query.getContent();
const actual = query.getContent();
expect(actual).toEqual(expected);
});

test("We correctly construct lines in a query from a string", () => {
const expected: any = [this.query];
const query = getTestQuery()
const expected: any = [query];

const input = "DELETE\n FROM \n\n person WHERE \n age > 5;";
const actual = getQueryFromLine(input);
Expand All @@ -62,5 +70,6 @@ test("We should ignore multiline comments", () => {
const input =
"/*\n * catpants\n*/DELETE\n FROM \n\n person /*comment */WHERE \n/*\n\n this is useless*/ age > 5;";

expect(getQueryFromLine(input)).toEqual([this.query]);
const query = getTestQuery()
expect(getQueryFromLine(input)).toEqual([query]);
});

0 comments on commit cfe7405

Please sign in to comment.