Skip to content

Commit 8d81244

Browse files
committed
Add tests for dataTypeCase and functionCase
1 parent 66d596e commit 8d81244

26 files changed

+218
-11
lines changed

src/languages/db2/db2.keywords.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,12 +404,16 @@ export const keywords: string[] = [
404404
export const dataTypes: string[] = [
405405
// https://www.ibm.com/docs/en/db2-for-zos/12?topic=columns-data-types
406406
'ARRAY',
407+
'BIGINT',
407408
'CCSID',
408409
'CHAR',
409410
'CHARACTER',
410411
'DATE',
411412
'DOUBLE',
413+
'INT',
414+
'INTEGER',
412415
'LONG',
416+
'SMALLINT',
413417
'TIME',
414418
'TIMESTAMP',
415419
];

src/languages/db2i/db2i.keywords.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,7 @@ export const dataTypes: string[] = [
517517
'DOUBLE',
518518
'FLOAT',
519519
'GRAPHIC',
520+
'INT',
520521
'INTEGER',
521522
'LONG',
522523
'NUMERIC',

src/languages/mysql/mysql.keywords.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,12 @@ export const dataTypes: string[] = [
235235
'BIGINT', // (R)
236236
'BINARY', // (R)
237237
'BLOB', // (R)
238+
'BOOL', // (R)
239+
'BOOLEAN', // (R)
238240
'CHAR', // (R)
239241
'CHARACTER', // (R)
242+
'DATE', // (R)
243+
'DATETIME', // (R)
240244
'DEC', // (R)
241245
'DECIMAL', // (R)
242246
'DOUBLE', // (R)
@@ -260,6 +264,7 @@ export const dataTypes: string[] = [
260264
'PRECISION', // (R)
261265
'REAL', // (R)
262266
'SMALLINT', // (R)
267+
'TIMESTAMP', // (R)
263268
'TINYBLOB', // (R)
264269
'TINYINT', // (R)
265270
'TINYTEXT', // (R)

src/languages/redshift/redshift.keywords.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,13 @@ export const keywords: string[] = [
201201
export const dataTypes: string[] = [
202202
// https://docs.aws.amazon.com/redshift/latest/dg/r_Character_types.html#r_Character_types-text-and-bpchar-types
203203
'ARRAY',
204+
'BIGINT',
204205
'BPCHAR',
206+
'INT',
207+
'INT2',
208+
'INT4',
209+
'INT8',
210+
'INTEGER',
211+
'SMALLINT',
205212
'TEXT',
206213
];

src/lexer/disambiguateTokens.ts

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,39 @@ const funcNameToKeyword = (token: Token, i: number, tokens: Token[]): Token => {
3535
if (token.type === TokenType.RESERVED_FUNCTION_NAME) {
3636
const nextToken = nextNonCommentToken(tokens, i);
3737
if (!nextToken || !isOpenParen(nextToken)) {
38-
return { ...token, type: TokenType.RESERVED_KEYWORD };
38+
return {
39+
...token,
40+
type:
41+
// Function names which are also data types
42+
[
43+
'BIGINT',
44+
'BINARY',
45+
'BIT',
46+
'BLOB',
47+
'BOOLEAN',
48+
'CHAR',
49+
'DATE',
50+
'DECIMAL',
51+
'DOUBLE',
52+
'FLOAT',
53+
'INT',
54+
'INTEGER',
55+
'JSON',
56+
'NCHAR',
57+
'NUMBER',
58+
'NVARCHAR',
59+
'REAL',
60+
'SMALLINT',
61+
'TEXT',
62+
'TIME',
63+
'TIMESTAMP',
64+
'TINYINT',
65+
'VARCHAR',
66+
'XML',
67+
].includes(token.text)
68+
? TokenType.RESERVED_DATA_TYPE
69+
: TokenType.RESERVED_KEYWORD,
70+
};
3971
}
4072
}
4173
return token;

test/behavesLikeMariaDbFormatter.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,10 @@ export default function behavesLikeMariaDbFormatter(format: FormatFn) {
163163
`create table account (id int comment 'the most important column');
164164
select * from mysql.user;
165165
insert into user (id, name) values (1, 'Blah');`,
166-
{ keywordCase: 'upper' }
166+
{
167+
keywordCase: 'upper',
168+
dataTypeCase: 'upper',
169+
}
167170
)
168171
).toBe(dedent`
169172
CREATE TABLE

test/behavesLikeSqlFormatter.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import supportsNewlineBeforeSemicolon from './options/newlineBeforeSemicolon.js'
1616
import supportsLogicalOperatorNewline from './options/logicalOperatorNewline.js';
1717
import supportsParamTypes from './options/paramTypes.js';
1818
import supportsWindowFunctions from './features/windowFunctions.js';
19+
import supportsFunctionCase from './options/functionCase.js';
1920

2021
/**
2122
* Core tests for all SQL formatters
@@ -29,6 +30,7 @@ export default function behavesLikeSqlFormatter(format: FormatFn) {
2930
supportsUseTabs(format);
3031
supportsKeywordCase(format);
3132
supportsIdentifierCase(format);
33+
supportsFunctionCase(format);
3234
supportsIndentStyle(format);
3335
supportsLinesBetweenQueries(format);
3436
supportsExpressionWidth(format);

test/bigquery.test.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import supportsMergeInto from './features/mergeInto.js';
2424
import supportsCreateView from './features/createView.js';
2525
import supportsAlterTable from './features/alterTable.js';
2626
import supportsIsDistinctFrom from './features/isDistinctFrom.js';
27+
import supportsDataTypeCase from './options/dataTypeCase.js';
2728

2829
describe('BigQueryFormatter', () => {
2930
const language = 'bigquery';
@@ -32,7 +33,11 @@ describe('BigQueryFormatter', () => {
3233
behavesLikeSqlFormatter(format);
3334
supportsComments(format, { hashComments: true });
3435
supportsCreateView(format, { orReplace: true, materialized: true, ifNotExists: true });
35-
supportsCreateTable(format, { orReplace: true, ifNotExists: true });
36+
supportsCreateTable(format, {
37+
orReplace: true,
38+
ifNotExists: true,
39+
dialectDoesntHaveVarchar: true,
40+
});
3641
supportsDropTable(format, { ifExists: true });
3742
supportsAlterTable(format, {
3843
addColumn: true,
@@ -60,6 +65,7 @@ describe('BigQueryFormatter', () => {
6065
supportsParams(format, { positional: true, named: ['@'], quoted: ['@``'] });
6166
supportsWindow(format);
6267
supportsLimiting(format, { limit: true, offset: true });
68+
supportsDataTypeCase(format);
6369

6470
// Note: BigQuery supports single dashes inside identifiers, so my-ident would be
6571
// detected as identifier, while other SQL dialects would detect it as

test/db2.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import supportsStrings from './features/strings.js';
1111
import supportsComments from './features/comments.js';
1212
import supportsOperators from './features/operators.js';
1313
import supportsLimiting from './features/limiting.js';
14+
import supportsDataTypeCase from './options/dataTypeCase.js';
1415

1516
describe('Db2Formatter', () => {
1617
const language = 'db2';
@@ -49,6 +50,7 @@ describe('Db2Formatter', () => {
4950
]);
5051
// Additional U& string type in addition to others shared by all DB2 implementations
5152
supportsStrings(format, ["U&''"]);
53+
supportsDataTypeCase(format);
5254

5355
it('supports non-standard FOR clause', () => {
5456
expect(format('SELECT * FROM tbl FOR UPDATE OF other_tbl FOR RS USE AND KEEP EXCLUSIVE LOCKS'))

test/db2i.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import supportsDropTable from './features/dropTable.js';
88
import supportsJoin from './features/join.js';
99
import supportsOperators from './features/operators.js';
1010
import supportsLimiting from './features/limiting.js';
11+
import supportsDataTypeCase from './options/dataTypeCase.js';
1112

1213
describe('Db2iFormatter', () => {
1314
const language = 'db2i';
@@ -28,4 +29,5 @@ describe('Db2iFormatter', () => {
2829
additionally: ['EXCEPTION JOIN', 'LEFT EXCEPTION JOIN', 'RIGHT EXCEPTION JOIN'],
2930
});
3031
supportsOperators(format, ['**', '¬=', '¬>', '¬<', '!>', '!<', '||', '=>']);
32+
supportsDataTypeCase(format);
3133
});

0 commit comments

Comments
 (0)