mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-21 01:25:42 -05:00
Check database case sensitivity for peek definition token matching (#227)
* Check database case sensitivity before peek definition token matching * Add sr gen * add tests for ignore case * remove sr.Designer
This commit is contained in:
@@ -29,24 +29,24 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.LanguageServices
|
||||
private const string OwnerUri = "testFile1";
|
||||
private const string ReturnTableFunctionName = "pd_returnTable";
|
||||
private const string ReturnTableTableFunctionQuery = @"
|
||||
CREATE FUNCTION [dbo].[" + ReturnTableFunctionName + @"] ()
|
||||
RETURNS TABLE
|
||||
AS
|
||||
RETURN
|
||||
(
|
||||
select * from master.dbo.spt_monitor
|
||||
);
|
||||
CREATE FUNCTION [dbo].[" + ReturnTableFunctionName + @"] ()
|
||||
RETURNS TABLE
|
||||
AS
|
||||
RETURN
|
||||
(
|
||||
select * from master.dbo.spt_monitor
|
||||
);
|
||||
|
||||
GO";
|
||||
|
||||
private const string AddTwoFunctionName = "pd_addTwo";
|
||||
private const string AddTwoFunctionQuery = @"
|
||||
CREATE FUNCTION[dbo].[" + AddTwoFunctionName + @"](@number int)
|
||||
CREATE FUNCTION[dbo].[" + AddTwoFunctionName + @"](@number int)
|
||||
RETURNS int
|
||||
AS
|
||||
AS
|
||||
BEGIN
|
||||
RETURN @number + 2;
|
||||
END;
|
||||
END;
|
||||
|
||||
GO";
|
||||
|
||||
@@ -147,11 +147,14 @@ GO";
|
||||
/// Test GetDefinition with an unsupported type(schema - dbo). Expect a error result.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void GetUnsupportedDefinitionErrorTest()
|
||||
public async Task GetUnsupportedDefinitionErrorTest()
|
||||
{
|
||||
TestConnectionResult connectionResult = TestObjects.InitLiveConnectionInfo();
|
||||
connectionResult.ScriptFile.Contents = "select * from dbo.func ()";
|
||||
string ownerUri = connectionResult.ScriptFile.ClientFilePath;
|
||||
TextDocumentPosition textDocument = new TextDocumentPosition
|
||||
{
|
||||
TextDocument = new TextDocumentIdentifier { Uri = OwnerUri },
|
||||
TextDocument = new TextDocumentIdentifier { Uri = ownerUri },
|
||||
Position = new Position
|
||||
{
|
||||
Line = 0,
|
||||
@@ -159,17 +162,16 @@ GO";
|
||||
Character = 15
|
||||
}
|
||||
};
|
||||
|
||||
TestConnectionResult connectionResult = TestObjects.InitLiveConnectionInfo();
|
||||
connectionResult.ScriptFile.Contents = "select * from dbo.func ()";
|
||||
var languageService = new LanguageService();
|
||||
ScriptParseInfo scriptInfo = new ScriptParseInfo { IsConnected = true };
|
||||
languageService.ScriptParseInfoMap.Add(OwnerUri, scriptInfo);
|
||||
connectionResult.TextDocumentPosition = textDocument;
|
||||
var languageService = LanguageService.Instance;
|
||||
await languageService.UpdateLanguageServiceOnConnection(connectionResult.ConnectionInfo);
|
||||
ScriptParseInfo parseInfo = languageService.GetScriptParseInfo(connectionResult.ScriptFile.ClientFilePath);
|
||||
Assert.NotNull(parseInfo);
|
||||
|
||||
// When I call the language service
|
||||
var result = languageService.GetDefinition(textDocument, connectionResult.ScriptFile, connectionResult.ConnectionInfo);
|
||||
|
||||
// Then I expect null locations and an error to be reported
|
||||
// Then I expect non null result with error flag set
|
||||
Assert.NotNull(result);
|
||||
Assert.True(result.IsErrorResult);
|
||||
}
|
||||
@@ -642,7 +644,7 @@ GO";
|
||||
|
||||
/// <summary>
|
||||
/// Test get definition using quickInfo text for a view object with active connection
|
||||
/// Expect a non-null result with location
|
||||
/// Expect a non-null result with location
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void GetDefinitionUsingQuickInfoTextWithNonexistentObjectTest()
|
||||
|
||||
@@ -233,7 +233,23 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.LanguageServices
|
||||
PeekDefinition peekDefinition = new PeekDefinition(null, null);
|
||||
string objectName = "testTable";
|
||||
string quickInfoText = "table master.dbo.testTable";
|
||||
string result = peekDefinition.GetFullObjectNameFromQuickInfo(quickInfoText, objectName);
|
||||
string result = peekDefinition.GetFullObjectNameFromQuickInfo(quickInfoText, objectName, StringComparison.Ordinal);
|
||||
string expected = "master.dbo.testTable";
|
||||
Assert.Equal(expected, result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test extracting the full object name from quickInfoText with case insensitive comparison.
|
||||
/// Given a valid object name string and a vaild quickInfo string containing the object name
|
||||
/// Expect the full object name (database.schema.objectName)
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void GetFullObjectNameFromQuickInfoWithValidStringsandIgnoreCaseTest()
|
||||
{
|
||||
PeekDefinition peekDefinition = new PeekDefinition(null, null);
|
||||
string objectName = "testtable";
|
||||
string quickInfoText = "table master.dbo.testTable";
|
||||
string result = peekDefinition.GetFullObjectNameFromQuickInfo(quickInfoText, objectName, StringComparison.OrdinalIgnoreCase);
|
||||
string expected = "master.dbo.testTable";
|
||||
Assert.Equal(expected, result);
|
||||
}
|
||||
@@ -251,17 +267,17 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.LanguageServices
|
||||
|
||||
string objectName = null;
|
||||
string quickInfoText = "table master.dbo.testTable";
|
||||
string result = peekDefinition.GetFullObjectNameFromQuickInfo(quickInfoText, objectName);
|
||||
string result = peekDefinition.GetFullObjectNameFromQuickInfo(quickInfoText, objectName, StringComparison.Ordinal);
|
||||
Assert.Equal(expected, result);
|
||||
|
||||
quickInfoText = null;
|
||||
objectName = "tableName";
|
||||
result = peekDefinition.GetFullObjectNameFromQuickInfo(quickInfoText, objectName);
|
||||
result = peekDefinition.GetFullObjectNameFromQuickInfo(quickInfoText, objectName, StringComparison.Ordinal);
|
||||
Assert.Equal(expected, result);
|
||||
|
||||
quickInfoText = null;
|
||||
objectName = null;
|
||||
result = peekDefinition.GetFullObjectNameFromQuickInfo(quickInfoText, objectName);
|
||||
result = peekDefinition.GetFullObjectNameFromQuickInfo(quickInfoText, objectName, StringComparison.Ordinal);
|
||||
Assert.Equal(expected, result);
|
||||
}
|
||||
|
||||
@@ -276,7 +292,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.LanguageServices
|
||||
PeekDefinition peekDefinition = new PeekDefinition(null, null);
|
||||
string objectName = "test";
|
||||
string quickInfoText = "table master.dbo.tableName";
|
||||
string result = peekDefinition.GetFullObjectNameFromQuickInfo(quickInfoText, objectName);
|
||||
string result = peekDefinition.GetFullObjectNameFromQuickInfo(quickInfoText, objectName, StringComparison.Ordinal);
|
||||
string expected = null;
|
||||
Assert.Equal(expected, result);
|
||||
}
|
||||
@@ -292,7 +308,24 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.LanguageServices
|
||||
PeekDefinition peekDefinition = new PeekDefinition(null, null);
|
||||
string objectName = "tableName";
|
||||
string quickInfoText = "table master.dbo.tableName";
|
||||
string result = peekDefinition.GetTokenTypeFromQuickInfo(quickInfoText, objectName);
|
||||
string result = peekDefinition.GetTokenTypeFromQuickInfo(quickInfoText, objectName, StringComparison.Ordinal);
|
||||
string expected = "table";
|
||||
Assert.Equal(expected, result);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Test extracting the object type from quickInfoText with case insensitive comparison.
|
||||
/// Given a valid object name string and a vaild quickInfo string containing the object name
|
||||
/// Expect correct object type
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void GetTokenTypeFromQuickInfoWithValidStringsandIgnoreCaseTest()
|
||||
{
|
||||
PeekDefinition peekDefinition = new PeekDefinition(null, null);
|
||||
string objectName = "tablename";
|
||||
string quickInfoText = "table master.dbo.tableName";
|
||||
string result = peekDefinition.GetTokenTypeFromQuickInfo(quickInfoText, objectName, StringComparison.OrdinalIgnoreCase);
|
||||
string expected = "table";
|
||||
Assert.Equal(expected, result);
|
||||
}
|
||||
@@ -310,17 +343,17 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.LanguageServices
|
||||
|
||||
string objectName = null;
|
||||
string quickInfoText = "table master.dbo.testTable";
|
||||
string result = peekDefinition.GetTokenTypeFromQuickInfo(quickInfoText, objectName);
|
||||
string result = peekDefinition.GetTokenTypeFromQuickInfo(quickInfoText, objectName, StringComparison.Ordinal);
|
||||
Assert.Equal(expected, result);
|
||||
|
||||
quickInfoText = null;
|
||||
objectName = "tableName";
|
||||
result = peekDefinition.GetTokenTypeFromQuickInfo(quickInfoText, objectName);
|
||||
result = peekDefinition.GetTokenTypeFromQuickInfo(quickInfoText, objectName, StringComparison.Ordinal);
|
||||
Assert.Equal(expected, result);
|
||||
|
||||
quickInfoText = null;
|
||||
objectName = null;
|
||||
result = peekDefinition.GetTokenTypeFromQuickInfo(quickInfoText, objectName);
|
||||
result = peekDefinition.GetTokenTypeFromQuickInfo(quickInfoText, objectName, StringComparison.Ordinal);
|
||||
Assert.Equal(expected, result);
|
||||
}
|
||||
|
||||
@@ -335,7 +368,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.LanguageServices
|
||||
PeekDefinition peekDefinition = new PeekDefinition(null, null);
|
||||
string objectName = "test";
|
||||
string quickInfoText = "table master.dbo.tableName";
|
||||
string result = peekDefinition.GetTokenTypeFromQuickInfo(quickInfoText, objectName);
|
||||
string result = peekDefinition.GetTokenTypeFromQuickInfo(quickInfoText, objectName, StringComparison.Ordinal);
|
||||
string expected = null;
|
||||
Assert.Equal(expected, result);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user