@@ -98,4 +98,119 @@ describe('Formatter Engine (Vitest)', () => {
9898 const out = formatTsql ( t , { options : { } as any , config : cfg ( { newlineBeforeSemicolon : true , linesBetweenQueries : 2 } ) , profile : { } } ) ;
9999 expect ( out . includes ( '\n;\n' ) ) . toBe ( true ) ;
100100 } ) ;
101+
102+ it ( 'dense operators' , ( ) => {
103+ const t = 'WHERE a = 10 AND b > 5' ;
104+ const out = formatTsql ( t , { options : { } as any , config : cfg ( { denseOperators : true } ) , profile : { } } ) ;
105+ expect ( out ) . toBe ( 'WHERE a=10AND\nb>5' ) ;
106+ } ) ;
107+
108+ it ( 'parenthesis spacing outside' , ( ) => {
109+ const t = 'COUNT(*)' ;
110+ const out = formatTsql ( t , { options : { } as any , config : cfg ( { parenthesisSpacing : 'outside' } ) , profile : { } } ) ;
111+ expect ( out ) . toBe ( 'COUNT( * ) ' ) ;
112+ } ) ;
113+
114+ it ( 'join alignment left' , ( ) => {
115+ const t = 'SELECT a FROM t INNER JOIN x ON t.id=x.id' ;
116+ const out = formatTsql ( t , { options : { } as any , config : cfg ( { newlineAfterFrom : true , joinAlignment : 'left' } ) , profile : { } } ) ;
117+ expect ( / \n I N N E R J O I N / . test ( out ) ) . toBe ( true ) ;
118+ } ) ;
119+
120+ it ( 'logical operator newline before' , ( ) => {
121+ const t = 'WHERE a = 1 AND b = 2' ;
122+ const out = formatTsql ( t , { options : { } as any , config : cfg ( { logicalOperatorNewline : 'before' } ) , profile : { } } ) ;
123+ expect ( / \n A N D / . test ( out ) ) . toBe ( true ) ;
124+ } ) ;
125+
126+ it ( 'alias keyword enable for table aliases' , ( ) => {
127+ const t = 'SELECT a FROM dbo.Table t' ;
128+ const out = formatTsql ( t , { options : { } as any , config : cfg ( { aliasKeyword : 'enable' } ) , profile : { } } ) ;
129+ expect ( out ) . toBe ( 'SELECT\n a\nFROM dbo.TABLE AS t' ) ;
130+ } ) ;
131+
132+ it ( 'columns comma placement ignore' , ( ) => {
133+ const t = 'SELECT a, b, c FROM t' ;
134+ const out = formatTsql ( t , { options : { } as any , config : cfg ( { newlineAfterSelect : true , columnsCommaPlacement : 'ignore' } ) , profile : { } } ) ;
135+ expect ( / S E L E C T \n \s + a \n \s + b \n \s + c \n F R O M / . test ( out ) ) . toBe ( true ) ;
136+ } ) ;
137+
138+ it ( 'expression width wrapping' , ( ) => {
139+ const t = 'SELECT verylongcolumnname, anotherverylongcolumnname FROM t' ;
140+ const out = formatTsql ( t , { options : { } as any , config : cfg ( { newlineAfterSelect : true , expressionWidth : 20 , safeWrapDelimiters : [ 'comma' ] } ) , profile : { } } ) ;
141+ expect ( out . includes ( '\n' ) ) . toBe ( true ) ;
142+ } ) ;
143+
144+ it ( 'cte style inline' , ( ) => {
145+ const t = 'WITH c AS (SELECT * FROM t) SELECT * FROM c' ;
146+ const out = formatTsql ( t , { options : { } as any , config : cfg ( { cteStyle : 'inline' } ) , profile : { } } ) ;
147+ expect ( out ) . toBe ( 'WITH c AS(SELECT\n *\nFROM t) SELECT\n *\nFROM c' ) ;
148+ } ) ;
149+
150+ it ( 'window function compact style' , ( ) => {
151+ const t = 'SELECT ROW_NUMBER() OVER(PARTITION BY a ORDER BY b) FROM t' ;
152+ const out = formatTsql ( t , { options : { } as any , config : cfg ( { windowFunctionStyle : 'compact' } ) , profile : { } } ) ;
153+ expect ( / O V E R \( P A R T I T I O N B Y a O R D E R B Y b \) / . test ( out ) ) . toBe ( true ) ;
154+ } ) ;
155+
156+ it ( 'align column definitions false' , ( ) => {
157+ const t = 'CREATE TABLE t (id INT, name VARCHAR(50))' ;
158+ const out = formatTsql ( t , { options : { } as any , config : cfg ( { alignColumnDefinitions : false } ) , profile : { } } ) ;
159+ expect ( out ) . toBe ( 'CREATE TABLE t(id INT, name VARCHAR(50))' ) ;
160+ } ) ;
161+
162+ it ( 'bracket identifiers ignore' , ( ) => {
163+ const t = 'SELECT a FROM [dbo].[Table]' ;
164+ const out = formatTsql ( t , { options : { } as any , config : cfg ( { bracketIdentifiers : 'ignore' } ) , profile : { } } ) ;
165+ expect ( out ) . toBe ( 'SELECT\n a\nFROM [dbo].[TABLE]' ) ;
166+ } ) ;
167+
168+ it ( 'tabulate alias' , ( ) => {
169+ const t = 'SELECT a AS alias, verylongcolumn AS longer FROM t' ;
170+ const out = formatTsql ( t , { options : { } as any , config : cfg ( { newlineAfterSelect : true , tabulateAlias : true } ) , profile : { } } ) ;
171+ expect ( out ) . toBe ( 'SELECT\n a AS alias, verylongcolumn AS longer\nFROM t' ) ;
172+ } ) ;
173+
174+ it ( 'expression width wrapping without delimiters' , ( ) => {
175+ const t = 'SELECT verylongcolumnnamethatexceeds FROM t' ;
176+ const out = formatTsql ( t , { options : { } as any , config : cfg ( { newlineAfterSelect : true , expressionWidth : 20 } ) , profile : { } } ) ;
177+ expect ( out . includes ( '\n' ) ) . toBe ( true ) ;
178+ } ) ;
179+
180+ it ( 'alias keyword remove for table aliases' , ( ) => {
181+ const t = 'SELECT a FROM dbo.Table AS t' ;
182+ const out = formatTsql ( t , { options : { } as any , config : cfg ( { aliasKeyword : 'remove' } ) , profile : { } } ) ;
183+ expect ( out ) . toBe ( 'SELECT\n a\nFROM dbo.TABLE t' ) ;
184+ } ) ;
185+
186+ it ( 'central indent alignment' , ( ) => {
187+ const t = 'SELECT a FROM t\nWHERE b = 1' ;
188+ const out = formatTsql ( t , { options : { } as any , config : cfg ( { indentStyle : 'central' , indentStyleMode : 'enable' , indentAlignColumn : 20 , indentCentralClauses : [ 'WHERE' ] } ) , profile : { } } ) ;
189+ expect ( out . includes ( ' WHERE' ) ) . toBe ( true ) ;
190+ } ) ;
191+
192+ it ( 'central indent alignment select' , ( ) => {
193+ const t = 'SELECT a, b FROM t' ;
194+ const out = formatTsql ( t , { options : { } as any , config : cfg ( { newlineAfterSelect : true , indentStyle : 'central' , indentStyleMode : 'enable' , indentAlignColumn : 10 , indentCentralClauses : [ 'SELECT' ] } ) , profile : { } } ) ;
195+ // Verify SELECT items are split and aligned consistently.
196+ expect ( / S E L E C T \s * \n \s + a , \n \s + b \s + F R O M / . test ( out ) ) . toBe ( true ) ;
197+ } ) ;
198+
199+ it ( 'window function multiline style' , ( ) => {
200+ const t = 'SELECT ROW_NUMBER() OVER(PARTITION BY a ORDER BY b) FROM t' ;
201+ const out = formatTsql ( t , { options : { } as any , config : cfg ( { windowFunctionStyle : 'multiline' } ) , profile : { } } ) ;
202+ expect ( / O V E R \s * \( \s * \n \s * P A R T I T I O N B Y / . test ( out ) ) . toBe ( true ) ;
203+ } ) ;
204+
205+ it ( 'align column definitions true' , ( ) => {
206+ const t = 'CREATE TABLE t (id INT, name VARCHAR(50))' ;
207+ const out = formatTsql ( t , { options : { } as any , config : cfg ( { alignColumnDefinitions : true } ) , profile : { } } ) ;
208+ expect ( out ) . toBe ( 'CREATE TABLE t (\n id INT,\n name VARCHAR(50)\n))' ) ;
209+ } ) ;
210+
211+ it ( 'bracket identifiers remove' , ( ) => {
212+ const t = 'SELECT [a] FROM [t]' ;
213+ const out = formatTsql ( t , { options : { } as any , config : cfg ( { bracketIdentifiers : 'remove' } ) , profile : { } } ) ;
214+ expect ( out ) . toBe ( 'SELECT\n a\nFROM t' ) ;
215+ } ) ;
101216} ) ;
0 commit comments