@@ -4,10 +4,14 @@ import { FormatFn } from '../../src/sqlFormatter.js';
4
4
5
5
export default function supportsIdentifierCase ( format : FormatFn ) {
6
6
it ( 'preserves identifier case by default' , ( ) => {
7
- const result = format ( 'select Abc from tBl1 left join Tbl2 where colA > 1 and colB = 3' ) ;
7
+ const result = format (
8
+ dedent `
9
+ select Abc, 'mytext' as MyText from tBl1 left join Tbl2 where colA > 1 and colB = 3`
10
+ ) ;
8
11
expect ( result ) . toBe ( dedent `
9
12
select
10
- Abc
13
+ Abc,
14
+ 'mytext' as MyText
11
15
from
12
16
tBl1
13
17
left join Tbl2
@@ -18,12 +22,15 @@ export default function supportsIdentifierCase(format: FormatFn) {
18
22
} ) ;
19
23
20
24
it ( 'converts identifiers to uppercase' , ( ) => {
21
- const result = format ( 'select Abc from tBl1 left join Tbl2 where colA > 1 and colB = 3' , {
22
- identifierCase : 'upper' ,
23
- } ) ;
25
+ const result = format (
26
+ dedent `
27
+ select Abc, 'mytext' as MyText from tBl1 left join Tbl2 where colA > 1 and colB = 3` ,
28
+ { identifierCase : 'upper' }
29
+ ) ;
24
30
expect ( result ) . toBe ( dedent `
25
31
select
26
- ABC
32
+ ABC,
33
+ 'mytext' as MYTEXT
27
34
from
28
35
TBL1
29
36
left join TBL2
@@ -34,12 +41,15 @@ export default function supportsIdentifierCase(format: FormatFn) {
34
41
} ) ;
35
42
36
43
it ( 'converts identifiers to lowercase' , ( ) => {
37
- const result = format ( 'select Abc from tBl1 left join Tbl2 where colA > 1 and colB = 3' , {
38
- identifierCase : 'lower' ,
39
- } ) ;
44
+ const result = format (
45
+ dedent `
46
+ select Abc, 'mytext' as MyText from tBl1 left join Tbl2 where colA > 1 and colB = 3` ,
47
+ { identifierCase : 'lower' }
48
+ ) ;
40
49
expect ( result ) . toBe ( dedent `
41
50
select
42
- abc
51
+ abc,
52
+ 'mytext' as mytext
43
53
from
44
54
tbl1
45
55
left join tbl2
@@ -49,23 +59,23 @@ export default function supportsIdentifierCase(format: FormatFn) {
49
59
` ) ;
50
60
} ) ;
51
61
52
- it ( 'does not uppercase identifiers inside strings ' , ( ) => {
53
- const result = format ( `select ' abc' as foo` , {
62
+ it ( 'does not uppercase quoted identifiers ' , ( ) => {
63
+ const result = format ( `select " abc" as foo` , {
54
64
identifierCase : 'upper' ,
55
65
} ) ;
56
66
expect ( result ) . toBe ( dedent `
57
67
select
58
- ' abc' as FOO
68
+ " abc" as FOO
59
69
` ) ;
60
70
} ) ;
61
71
62
- it ( 'does not uppercase identifiers inside quotes' , ( ) => {
63
- const result = format ( `select "abc" as foo` , {
64
- identifierCase : 'upper' ,
65
- } ) ;
72
+ it ( 'converts multi-part identifiers to uppercase' , ( ) => {
73
+ const result = format ( 'select Abc from Part1.Part2.Part3' , { identifierCase : 'upper' } ) ;
66
74
expect ( result ) . toBe ( dedent `
67
75
select
68
- "abc" as FOO
76
+ ABC
77
+ from
78
+ PART1.PART2.PART3
69
79
` ) ;
70
80
} ) ;
71
81
}
0 commit comments