Skip to content

Commit

Permalink
fix tests after changes
Browse files Browse the repository at this point in the history
  • Loading branch information
DerTimonius committed Dec 6, 2023
1 parent c33c509 commit a6cf455
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 65 deletions.
3 changes: 1 addition & 2 deletions test/behavesLikeMariaDbFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,7 @@ export default function behavesLikeMariaDbFormatter(format: FormatFn) {
{ keywordCase: 'upper' }
)
).toBe(dedent`
CREATE TABLE
account (id INT comment 'the most important column');
CREATE TABLE account (id INT comment 'the most important column');
SELECT
*
Expand Down
3 changes: 1 addition & 2 deletions test/bigquery.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -339,8 +339,7 @@ describe('BigQueryFormatter', () => {
uris = ['gs://bucket/path1.csv']
)`;
const expected = dedent`
CREATE EXTERNAL TABLE
dataset.CsvTable
CREATE EXTERNAL TABLE dataset.CsvTable
WITH PARTITION COLUMNS
(field_1 STRING, field_2 INT64) OPTIONS(format = 'CSV', uris = ['gs://bucket/path1.csv'])`;
expect(format(input)).toBe(expected);
Expand Down
9 changes: 4 additions & 5 deletions test/features/constraints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@ export default function supportsConstraints(format: FormatFn, actions: string[])
);
`)
).toBe(dedent`
CREATE TABLE
foo (
update_time datetime ON UPDATE ${action},
delete_time datetime ON DELETE ${action},
);
CREATE TABLE foo (
update_time datetime ON UPDATE ${action},
delete_time datetime ON DELETE ${action},
);
`);
});
});
Expand Down
34 changes: 14 additions & 20 deletions test/features/createTable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ export default function supportsCreateTable(
) {
it('formats short CREATE TABLE', () => {
expect(format('CREATE TABLE tbl (a INT PRIMARY KEY, b TEXT);')).toBe(dedent`
CREATE TABLE
tbl (a INT PRIMARY KEY, b TEXT);
CREATE TABLE tbl (a INT PRIMARY KEY, b TEXT);
`);
});

Expand All @@ -26,30 +25,27 @@ export default function supportsCreateTable(
expect(
format('CREATE TABLE tbl (a INT PRIMARY KEY, b TEXT, c INT NOT NULL, doggie INT NOT NULL);')
).toBe(dedent`
CREATE TABLE
tbl (
a INT PRIMARY KEY,
b TEXT,
c INT NOT NULL,
doggie INT NOT NULL
);
CREATE TABLE tbl (
a INT PRIMARY KEY,
b TEXT,
c INT NOT NULL,
doggie INT NOT NULL
);
`);
});

if (orReplace) {
it('formats short CREATE OR REPLACE TABLE', () => {
expect(format('CREATE OR REPLACE TABLE tbl (a INT PRIMARY KEY, b TEXT);')).toBe(dedent`
CREATE OR REPLACE TABLE
tbl (a INT PRIMARY KEY, b TEXT);
CREATE OR REPLACE TABLE tbl (a INT PRIMARY KEY, b TEXT);
`);
});
}

if (ifNotExists) {
it('formats short CREATE TABLE IF NOT EXISTS', () => {
expect(format('CREATE TABLE IF NOT EXISTS tbl (a INT PRIMARY KEY, b TEXT);')).toBe(dedent`
CREATE TABLE IF NOT EXISTS
tbl (a INT PRIMARY KEY, b TEXT);
CREATE TABLE IF NOT EXISTS tbl (a INT PRIMARY KEY, b TEXT);
`);
});
}
Expand All @@ -59,20 +55,18 @@ export default function supportsCreateTable(
expect(
format(`CREATE TABLE tbl (a INT COMMENT 'Hello world!', b TEXT COMMENT 'Here we are!');`)
).toBe(dedent`
CREATE TABLE
tbl (
a INT COMMENT 'Hello world!',
b TEXT COMMENT 'Here we are!'
);
CREATE TABLE tbl (
a INT COMMENT 'Hello world!',
b TEXT COMMENT 'Here we are!'
);
`);
});
}

if (tableComment) {
it('formats short CREATE TABLE with comment', () => {
expect(format(`CREATE TABLE tbl (a INT, b TEXT) COMMENT = 'Hello, world!';`)).toBe(dedent`
CREATE TABLE
tbl (a INT, b TEXT) COMMENT = 'Hello, world!';
CREATE TABLE tbl (a INT, b TEXT) COMMENT = 'Hello, world!';
`);
});
}
Expand Down
3 changes: 1 addition & 2 deletions test/features/createView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ export default function supportsCreateView(
if (ifNotExists) {
it('formats short CREATE TABLE IF NOT EXISTS', () => {
expect(format('CREATE TABLE IF NOT EXISTS tbl (a INT PRIMARY KEY, b TEXT);')).toBe(dedent`
CREATE TABLE IF NOT EXISTS
tbl (a INT PRIMARY KEY, b TEXT);
CREATE TABLE IF NOT EXISTS tbl (a INT PRIMARY KEY, b TEXT);
`);
});
}
Expand Down
13 changes: 6 additions & 7 deletions test/postgresql.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,13 +222,12 @@ describe('PostgreSqlFormatter', () => {
deleted_at TIME WITH TIME ZONE,
modified_at TIMESTAMP(0) WITH TIME ZONE);`)
).toBe(dedent`
CREATE TABLE
time_table (
id INT,
created_at TIMESTAMP WITH TIME ZONE,
deleted_at TIME WITH TIME ZONE,
modified_at TIMESTAMP(0) WITH TIME ZONE
);
CREATE TABLE time_table (
id INT,
created_at TIMESTAMP WITH TIME ZONE,
deleted_at TIME WITH TIME ZONE,
modified_at TIMESTAMP(0) WITH TIME ZONE
);
`);
});

Expand Down
39 changes: 18 additions & 21 deletions test/redshift.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,23 @@ import dedent from 'dedent-js';

import { format as originalFormat, FormatFn } from '../src/sqlFormatter.js';
import behavesLikeSqlFormatter from './behavesLikeSqlFormatter.js';

import supportsAlterTable from './features/alterTable.js';
import supportsCommentOn from './features/commentOn.js';
import supportsComments from './features/comments.js';
import supportsCreateTable from './features/createTable.js';
import supportsCreateView from './features/createView.js';
import supportsDeleteFrom from './features/deleteFrom.js';
import supportsDropTable from './features/dropTable.js';
import supportsIdentifiers from './features/identifiers.js';
import supportsInsertInto from './features/insertInto.js';
import supportsJoin from './features/join.js';
import supportsLimiting from './features/limiting.js';
import supportsOperators from './features/operators.js';
import supportsStrings from './features/strings.js';
import supportsDeleteFrom from './features/deleteFrom.js';
import supportsComments from './features/comments.js';
import supportsCommentOn from './features/commentOn.js';
import supportsIdentifiers from './features/identifiers.js';
import supportsParams from './options/param.js';
import supportsSetOperations from './features/setOperations.js';
import supportsLimiting from './features/limiting.js';
import supportsInsertInto from './features/insertInto.js';
import supportsUpdate from './features/update.js';
import supportsStrings from './features/strings.js';
import supportsTruncateTable from './features/truncateTable.js';
import supportsCreateView from './features/createView.js';
import supportsUpdate from './features/update.js';
import supportsParams from './options/param.js';

describe('RedshiftFormatter', () => {
const language = 'redshift';
Expand Down Expand Up @@ -89,8 +88,7 @@ describe('RedshiftFormatter', () => {
it('formats temp table name starting with #', () => {
expect(format(`CREATE TABLE #tablename AS tbl;`)).toBe(
dedent`
CREATE TABLE
#tablename AS tbl;
CREATE TABLE #tablename AS tbl;
`
);
});
Expand All @@ -101,14 +99,13 @@ describe('RedshiftFormatter', () => {
'CREATE TABLE items (a INT PRIMARY KEY, b TEXT, c INT NOT NULL, d INT NOT NULL, e INT NOT NULL) DISTKEY(created_at) SORTKEY(created_at);'
)
).toBe(dedent`
CREATE TABLE
items (
a INT PRIMARY KEY,
b TEXT,
c INT NOT NULL,
d INT NOT NULL,
e INT NOT NULL
) DISTKEY (created_at) SORTKEY (created_at);
CREATE TABLE items (
a INT PRIMARY KEY,
b TEXT,
c INT NOT NULL,
d INT NOT NULL,
e INT NOT NULL
) DISTKEY (created_at) SORTKEY (created_at);
`);
});

Expand Down
11 changes: 5 additions & 6 deletions test/snowflake.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,10 @@ describe('SnowflakeFormatter', () => {
}
)
).toBe(dedent`
CREATE TABLE
tbl (
first_column DOUBLE PRECISION,
second_column NUMBER (38, 0),
third STRING
);`);
CREATE TABLE tbl (
first_column DOUBLE PRECISION,
second_column NUMBER (38, 0),
third STRING
);`);
});
});

0 comments on commit a6cf455

Please sign in to comment.