From 7272117d5e7409e2d3e5e0bfa4f6944338b4f9b6 Mon Sep 17 00:00:00 2001 From: Zi Chen <13544267+zijchen@users.noreply.github.com> Date: Fri, 6 Jun 2025 15:18:22 -0700 Subject: [PATCH 1/2] Update TestUtilities.cs Signed-off-by: Zi Chen <13544267+zijchen@users.noreply.github.com> --- Test/SqlDom/TestUtilities.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Test/SqlDom/TestUtilities.cs b/Test/SqlDom/TestUtilities.cs index abc8d76..fa5dc1f 100644 --- a/Test/SqlDom/TestUtilities.cs +++ b/Test/SqlDom/TestUtilities.cs @@ -394,7 +394,13 @@ public static TSqlFragment ParseStringNoErrors(TSqlParser parser, string source) } public static TSqlFragment ParseString(TSqlParser parser, string source, out IList errors) - { + { +#if NET + // Convert line endings from \n to \r\n + if (System.Environment.NewLine == "\n") + source = source.ReplaceLineEndings("\r\n"); +#endif + TSqlFragment fragment; using (StringReader sr = new StringReader(source)) { From 531f178167759c15f9bf3e7f7b86f6b2a9103fc5 Mon Sep 17 00:00:00 2001 From: Zi Chen Date: Fri, 6 Jun 2025 15:41:40 -0700 Subject: [PATCH 2/2] Use IndexOf instead of hardcoded values --- Test/SqlDom/ParserErrorsTests.cs | 8 ++++---- Test/SqlDom/TestUtilities.cs | 8 +------- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/Test/SqlDom/ParserErrorsTests.cs b/Test/SqlDom/ParserErrorsTests.cs index dd9a9a4..7474efd 100644 --- a/Test/SqlDom/ParserErrorsTests.cs +++ b/Test/SqlDom/ParserErrorsTests.cs @@ -6824,7 +6824,7 @@ RETURNS VARCHAR(20) RETURN '$' + CAST(@amount AS VARCHAR) END; "; - ParserTestUtils.ErrorTestFabricDW(scalarFunctionSyntax, new ParserErrorInfo(330, "SQL46026", "ENCRYPTION")); + ParserTestUtils.ErrorTestFabricDW(scalarFunctionSyntax, new ParserErrorInfo(scalarFunctionSyntax.IndexOf("ENCRYPTION"), "SQL46026", "ENCRYPTION")); string scalarFunctionSyntax2 = @"CREATE OR ALTER FUNCTION dbo.ConcatNames ( @@ -6837,7 +6837,7 @@ RETURNS NVARCHAR(101) BEGIN RETURN @first + ' ' + @last END;"; - ParserTestUtils.ErrorTestFabricDW(scalarFunctionSyntax2, new ParserErrorInfo(425, "SQL46010", "INLINE")); + ParserTestUtils.ErrorTestFabricDW(scalarFunctionSyntax2, new ParserErrorInfo(scalarFunctionSyntax2.IndexOf("INLINE"), "SQL46010", "INLINE")); string scalarFunctionSyntax3 = @"CREATE OR ALTER FUNCTION dbo.CountProducts ( @@ -6849,7 +6849,7 @@ WITH SCHEMABINDING BEGIN RETURN (SELECT COUNT(*) FROM @ProductTable) END;"; - ParserTestUtils.ErrorTestFabricDW(scalarFunctionSyntax3, new ParserErrorInfo(172, "SQL46026", "READONLY")); + ParserTestUtils.ErrorTestFabricDW(scalarFunctionSyntax3, new ParserErrorInfo(scalarFunctionSyntax3.IndexOf("READONLY"), "SQL46026", "READONLY")); string scalarFunctionSyntax4 = @"CREATE OR ALTER FUNCTION sales.TotalSalesForRegion ( @@ -6866,7 +6866,7 @@ FROM @SalesData WHERE RegionId = @RegionId ) END;"; - ParserTestUtils.ErrorTestFabricDW(scalarFunctionSyntax4, new ParserErrorInfo(171, "SQL46010", "NULL")); + ParserTestUtils.ErrorTestFabricDW(scalarFunctionSyntax4, new ParserErrorInfo(scalarFunctionSyntax4.IndexOf("NULL"), "SQL46010", "NULL")); } } } diff --git a/Test/SqlDom/TestUtilities.cs b/Test/SqlDom/TestUtilities.cs index fa5dc1f..abc8d76 100644 --- a/Test/SqlDom/TestUtilities.cs +++ b/Test/SqlDom/TestUtilities.cs @@ -394,13 +394,7 @@ public static TSqlFragment ParseStringNoErrors(TSqlParser parser, string source) } public static TSqlFragment ParseString(TSqlParser parser, string source, out IList errors) - { -#if NET - // Convert line endings from \n to \r\n - if (System.Environment.NewLine == "\n") - source = source.ReplaceLineEndings("\r\n"); -#endif - + { TSqlFragment fragment; using (StringReader sr = new StringReader(source)) {