@@ -5,26 +5,32 @@ import {
55import { Query } from "../../../src/reader/query" ;
66import { Line } from "../../../src/reader/line" ;
77
8- beforeEach ( ( ) => {
9- this . query = new Query ( ) ;
10- this . query . lines = [
8+ function getTestQuery ( ) : Query {
9+ const query = new Query ( ) ;
10+ query . lines = [
1111 new Line ( "DELETE" , 1 ) ,
1212 new Line ( " FROM " , 2 ) ,
1313 new Line ( " person WHERE " , 4 ) ,
1414 new Line ( " age > 5;" , 5 ) ,
1515 ] ;
1616
17- this . queryWithComments = new Query ( ) ;
18- this . queryWithComments . lines = [
17+ return query ;
18+ }
19+
20+ function getTestQueryWithComments ( ) : Query {
21+ const queryWithComments = new Query ( ) ;
22+ queryWithComments . lines = [
1923 new Line ( "DELETE" , 1 ) ,
2024 new Line ( " FROM " , 2 ) ,
2125 new Line ( " person WHERE " , 4 ) ,
2226 new Line ( " age > 5;" , 6 ) ,
2327 ] ;
24- } ) ;
28+
29+ return queryWithComments ;
30+ }
2531
2632test ( "We correctly read a file" , ( ) => {
27- const expected : any = [ this . query ] ;
33+ const expected : any = [ getTestQuery ( ) ] ;
2834 const input = "DELETE\n FROM \n\n person WHERE \n age > 5;" ;
2935 const actual = putContentIntoLines ( input ) ;
3036 expect ( actual ) . toEqual ( expected ) ;
@@ -41,17 +47,19 @@ test.each([
4147 [ "DELETE\n FROM \n\n person WHERE \n/* Remove old people*/\n age > 5;" ] ,
4248] ) ( "We ignore comments in files" , ( input ) => {
4349 const actual = putContentIntoLines ( input ) ;
44- expect ( actual ) . toEqual ( [ this . queryWithComments ] ) ;
50+ expect ( actual ) . toEqual ( [ getTestQueryWithComments ( ) ] ) ;
4551} ) ;
4652
4753test ( "We correctly reconstruct our query from lines" , ( ) => {
54+ const query = getTestQuery ( )
4855 const expected : string = "DELETE FROM person WHERE age > 5;" ;
49- const actual = this . query . getContent ( ) ;
56+ const actual = query . getContent ( ) ;
5057 expect ( actual ) . toEqual ( expected ) ;
5158} ) ;
5259
5360test ( "We correctly construct lines in a query from a string" , ( ) => {
54- const expected : any = [ this . query ] ;
61+ const query = getTestQuery ( )
62+ const expected : any = [ query ] ;
5563
5664 const input = "DELETE\n FROM \n\n person WHERE \n age > 5;" ;
5765 const actual = getQueryFromLine ( input ) ;
@@ -62,5 +70,6 @@ test("We should ignore multiline comments", () => {
6270 const input =
6371 "/*\n * catpants\n*/DELETE\n FROM \n\n person /*comment */WHERE \n/*\n\n this is useless*/ age > 5;" ;
6472
65- expect ( getQueryFromLine ( input ) ) . toEqual ( [ this . query ] ) ;
73+ const query = getTestQuery ( )
74+ expect ( getQueryFromLine ( input ) ) . toEqual ( [ query ] ) ;
6675} ) ;
0 commit comments