PlaceCommasBeforeNextStatement should handle correctly formatted text (#247)

- Fixed handling of PlaceCommasBeforeNextStatement so that it doesn't add whitespace unnecessarily. This ensures that repeated formats of the same text shouldn't keep adding whitespace
- Added tests covering a number of scenarios related to this
This commit is contained in:
Kevin Cunnane
2017-02-22 11:08:57 -08:00
committed by Raymond Martin
parent 7f20f84add
commit 0c0bd3125b
8 changed files with 168 additions and 59 deletions

View File

@@ -0,0 +1,10 @@
CREATE PROCEDURE [dbo].[sp1]
AS
SELECT
c1
,c2
,c3
FROM
[dbo].[T1]
RETURN 0

View File

@@ -0,0 +1,6 @@
CREATE PROCEDURE [dbo].[sp1]
AS
SELECT c1 ,c2 ,c3
FROM [dbo].[T1]
RETURN 0

View File

@@ -0,0 +1,3 @@
CREATE PROCEDURE [dbo].[sp1] AS SELECT c1, c2, c3 from [dbo].[T1] RETURN 0

View File

@@ -0,0 +1,9 @@
CREATE PROCEDURE [dbo].[sp1]
AS
SELECT
c1
,c2, c3
FROM
[dbo].[T1]
RETURN 0

View File

@@ -66,6 +66,59 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.Formatter
GetBaselineFile("CreateProcedure_Select.sql"), new FormatOptions(), true);
}
[Fact]
public void CreateProcedure_CommaBeforeNextColumn()
{
// Verifies that commas are placed before the next column instead of after the current one,
// when PlaceCommasBeforeNextStatement = true
LoadAndFormatAndCompare("CreateProcedure_CommaBeforeNextColumn",
GetInputFile("CreateProcedure_CommaHandling1.sql"),
GetBaselineFile("CreateProcedure_CommaBeforeNext.sql"),
new FormatOptions()
{
DatatypeCasing = CasingOptions.Lowercase,
KeywordCasing = CasingOptions.Uppercase,
PlaceCommasBeforeNextStatement = true,
PlaceEachReferenceOnNewLineInQueryStatements = true
}, true);
}
[Fact]
public void CreateProcedure_CommaBeforeNextColumnRepeated()
{
// Verifies that formatting isn't changed for text that's already been formatted
// as having the comma placed before the next column instead of after the prevous one
LoadAndFormatAndCompare("CreateProcedure_CommaBeforeNextColumnRepeated",
GetInputFile("CreateProcedure_CommaHandling2.sql"),
GetBaselineFile("CreateProcedure_CommaBeforeNext.sql"),
new FormatOptions()
{
DatatypeCasing = CasingOptions.Lowercase,
KeywordCasing = CasingOptions.Uppercase,
PlaceCommasBeforeNextStatement = true,
PlaceEachReferenceOnNewLineInQueryStatements = true
},
true);
}
[Fact]
public void CreateProcedure_CommaBeforeNextColumnNoNewline()
{
// Verifies that commas are placed before the next column instead of after the current one,
// when PlaceCommasBeforeNextStatement = true
// And that whitespace is used instead of newline if PlaceEachReferenceOnNewLineInQueryStatements = false
LoadAndFormatAndCompare("CreateProcedure_CommaBeforeNextColumnNoNewline",
GetInputFile("CreateProcedure_CommaHandling1.sql"),
GetBaselineFile("CreateProcedure_CommaSpaced.sql"),
new FormatOptions()
{
DatatypeCasing = CasingOptions.Lowercase,
KeywordCasing = CasingOptions.Uppercase,
PlaceCommasBeforeNextStatement = true,
PlaceEachReferenceOnNewLineInQueryStatements = false
}, true);
}
[Fact]
public void CreateProcedure_TwoPartName()
{