Skip to content

Commit 714ef04

Browse files
authored
Sync repos: Merged PR 1067391: Add token info for CursorOption (microsoft#37) (microsoft#45)
* Merged PR 1067391: Add token info for CursorOption (microsoft#37) Add token info for CursorOption (microsoft#37) * Add token info for CursorOption Fixes microsoft#26 * Add additional asserts in test case for CursorOption * merging back another commit ---------
1 parent 9f71e00 commit 714ef04

10 files changed

Lines changed: 43 additions & 0 deletions

File tree

SqlScriptDom/Parser/TSql/TSql100.g

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11984,6 +11984,7 @@ cursorOption returns [CursorOption vResult = FragmentFactory.CreateFragment<Curs
1198411984
: tOption:Identifier
1198511985
{
1198611986
vResult.OptionKind=CursorOptionsHelper.Instance.ParseOption(tOption);
11987+
UpdateTokenInfo(vResult, tOption);
1198711988
}
1198811989
;
1198911990

SqlScriptDom/Parser/TSql/TSql110.g

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13994,6 +13994,7 @@ cursorOption returns [CursorOption vResult = FragmentFactory.CreateFragment<Curs
1399413994
: tOption:Identifier
1399513995
{
1399613996
vResult.OptionKind=CursorOptionsHelper.Instance.ParseOption(tOption);
13997+
UpdateTokenInfo(vResult, tOption);
1399713998
}
1399813999
;
1399914000

SqlScriptDom/Parser/TSql/TSql120.g

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14396,6 +14396,7 @@ cursorOption returns [CursorOption vResult = FragmentFactory.CreateFragment<Curs
1439614396
: tOption:Identifier
1439714397
{
1439814398
vResult.OptionKind=CursorOptionsHelper.Instance.ParseOption(tOption);
14399+
UpdateTokenInfo(vResult, tOption);
1439914400
}
1440014401
;
1440114402

SqlScriptDom/Parser/TSql/TSql130.g

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15640,6 +15640,7 @@ cursorOption returns [CursorOption vResult = FragmentFactory.CreateFragment<Curs
1564015640
: tOption:Identifier
1564115641
{
1564215642
vResult.OptionKind=CursorOptionsHelper.Instance.ParseOption(tOption);
15643+
UpdateTokenInfo(vResult, tOption);
1564315644
}
1564415645
;
1564515646

SqlScriptDom/Parser/TSql/TSql140.g

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16025,6 +16025,7 @@ cursorOption returns [CursorOption vResult = FragmentFactory.CreateFragment<Curs
1602516025
: tOption:Identifier
1602616026
{
1602716027
vResult.OptionKind=CursorOptionsHelper.Instance.ParseOption(tOption);
16028+
UpdateTokenInfo(vResult, tOption);
1602816029
}
1602916030
;
1603016031

SqlScriptDom/Parser/TSql/TSql150.g

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16695,6 +16695,7 @@ cursorOption returns [CursorOption vResult = FragmentFactory.CreateFragment<Curs
1669516695
: tOption:Identifier
1669616696
{
1669716697
vResult.OptionKind=CursorOptionsHelper.Instance.ParseOption(tOption);
16698+
UpdateTokenInfo(vResult, tOption);
1669816699
}
1669916700
;
1670016701

SqlScriptDom/Parser/TSql/TSql160.g

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16741,6 +16741,7 @@ cursorOption returns [CursorOption vResult = FragmentFactory.CreateFragment<Curs
1674116741
: tOption:Identifier
1674216742
{
1674316743
vResult.OptionKind=CursorOptionsHelper.Instance.ParseOption(tOption);
16744+
UpdateTokenInfo(vResult, tOption);
1674416745
}
1674516746
;
1674616747

SqlScriptDom/Parser/TSql/TSql80.g

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3898,6 +3898,7 @@ cursorOption returns [CursorOption vResult = FragmentFactory.CreateFragment<Curs
38983898
: tOption:Identifier
38993899
{
39003900
vResult.OptionKind=CursorOptionsHelper.Instance.ParseOption(tOption);
3901+
UpdateTokenInfo(vResult, tOption);
39013902
}
39023903
;
39033904

SqlScriptDom/Parser/TSql/TSql90.g

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9640,6 +9640,7 @@ cursorOption returns [CursorOption vResult = FragmentFactory.CreateFragment<Curs
96409640
: tOption:Identifier
96419641
{
96429642
vResult.OptionKind=CursorOptionsHelper.Instance.ParseOption(tOption);
9643+
UpdateTokenInfo(vResult, tOption);
96439644
}
96449645
;
96459646

Test/SqlDom/RegressionTests.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,40 @@ INSERT INTO [dbo].[UrlTable] (Col1, Url) VALUES ('1', '2')
157157
Parse(scriptReader);
158158
}
159159

160+
/// <summary>
161+
/// Regression test to verify token info (start line, start column, etc.) are correctly populated for CursorOption
162+
/// See https://github.com/microsoft/SqlScriptDOM/issues/26 for details on the issue.
163+
/// </summary>
164+
[TestMethod]
165+
[Priority(0)]
166+
[SqlStudioTestCategory(Category.UnitTest)]
167+
public void CursorOptionTokenInfoTest()
168+
{
169+
ParserTestUtils.ExecuteTestForAllParsers(delegate (TSqlParser parser)
170+
{
171+
string script = @"-- Single line comment
172+
DECLARE MyCursor scroll CURSOR FOR
173+
SELECT * FROM ANYTHING";
174+
175+
using (var scriptReader = new StringReader(script))
176+
{
177+
var fragment = parser.Parse(scriptReader, out IList<ParseError> errors) as TSqlScript;
178+
Assert.AreEqual(0, errors.Count);
179+
180+
Assert.IsTrue(fragment is TSqlScript);
181+
Assert.IsTrue(fragment.Batches[0].Statements[0] is DeclareCursorStatement);
182+
183+
var declCursorStmt = fragment.Batches[0].Statements[0] as DeclareCursorStatement;
184+
185+
Assert.AreEqual(3, declCursorStmt.CursorDefinition.Select.StartLine);
186+
Assert.AreEqual(9, declCursorStmt.CursorDefinition.Select.StartColumn);
187+
188+
Assert.AreEqual(2, declCursorStmt.CursorDefinition.Options[0].StartLine);
189+
Assert.AreEqual(26, declCursorStmt.CursorDefinition.Options[0].StartColumn);
190+
}
191+
}, true);
192+
}
193+
160194
#region Private Methods
161195

162196
private static string GenerateScript(TSqlFragment fragment)

0 commit comments

Comments
 (0)