From cfe740595ff7287641bab44d5dfc4fb5cd7a82e6 Mon Sep 17 00:00:00 2001 From: Joe Reynolds Date: Thu, 15 Aug 2024 14:26:03 +0100 Subject: [PATCH] Fix failing tests --- test/unit/reader/reader.test.ts | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/test/unit/reader/reader.test.ts b/test/unit/reader/reader.test.ts index f24aef52..a90903e6 100644 --- a/test/unit/reader/reader.test.ts +++ b/test/unit/reader/reader.test.ts @@ -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); @@ -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); @@ -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]); });