added support for QUOTED_IDENTIFIER in auto complete list (#190)

*  added support for QUOTED_IDENTIFIER in auto complete list
This commit is contained in:
Leila Lali
2017-01-04 14:03:10 -08:00
committed by GitHub
parent 3ad7cc1a8b
commit 379decf4e9
5 changed files with 174 additions and 39 deletions

View File

@@ -3,8 +3,8 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
using System;
using Microsoft.SqlServer.Management.SqlParser.Intellisense;
using Microsoft.SqlTools.ServiceLayer.LanguageServices;
using Microsoft.SqlTools.ServiceLayer.LanguageServices.Completion;
using Microsoft.SqlTools.ServiceLayer.LanguageServices.Contracts;
using Xunit;
@@ -325,6 +325,22 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.LanguageServer
Assert.True(completionItem.InsertText.StartsWith("[") && completionItem.InsertText.EndsWith("]"));
}
[Fact]
public void ConstructorShouldThrowExceptionGivenEmptyDeclarionType()
{
string declarationTitle = "";
DeclarationType declarationType = DeclarationType.Table;
string tokenText = "";
Assert.Throws<ArgumentException>(() => new SqlCompletionItem(declarationTitle, declarationType, tokenText));
}
[Fact]
public void ConstructorShouldThrowExceptionGivenNullDeclarion()
{
string tokenText = "";
Assert.Throws<ArgumentException>(() => new SqlCompletionItem(null, tokenText));
}
[Fact]
public void InsertTextShouldIncludeBracketGivenNameWithSpecialCharacter()
{
@@ -431,23 +447,83 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.LanguageServer
}
[Fact]
public void LabelShouldIncBracketGivenReservedName()
public void LabelShouldIncludeQuotedIdentifiersGivenTokenWithQuotedIdentifier()
{
string declarationTitle = "name";
string expected = "\"" + declarationTitle + "\"";
DeclarationType declarationType = DeclarationType.Table;
string tokenText = "\"";
SqlCompletionItem item = new SqlCompletionItem(declarationTitle, declarationType, tokenText);
CompletionItem completionItem = item.CreateCompletionItem(0, 1, 2);
Assert.Equal(completionItem.Label, expected);
Assert.Equal(completionItem.InsertText, expected);
Assert.Equal(completionItem.Detail, expected);
}
[Fact]
public void LabelShouldIncludeQuotedIdentifiersGivenTokenWithQuotedIdentifiers()
{
string declarationTitle = "name";
string expected = "\"" + declarationTitle + "\"";
DeclarationType declarationType = DeclarationType.Table;
string tokenText = "\"\"";
SqlCompletionItem item = new SqlCompletionItem(declarationTitle, declarationType, tokenText);
CompletionItem completionItem = item.CreateCompletionItem(0, 1, 2);
Assert.Equal(completionItem.Label, expected);
Assert.Equal(completionItem.InsertText, expected);
Assert.Equal(completionItem.Detail, expected);
}
[Fact]
public void InsertTextShouldIncludeBracketGivenReservedName()
{
foreach (string word in ReservedWords)
{
string declarationTitle = word;
string expected = "[" + declarationTitle + "]";
DeclarationType declarationType = DeclarationType.Table;
string tokenText = "[]";
string tokenText = "";
SqlCompletionItem item = new SqlCompletionItem(declarationTitle, declarationType, tokenText);
CompletionItem completionItem = item.CreateCompletionItem(0, 1, 2);
Assert.Equal(completionItem.Label, expected);
Assert.Equal(completionItem.Label, word);
Assert.Equal(completionItem.InsertText, expected);
Assert.Equal(completionItem.Detail, expected);
Assert.Equal(completionItem.Detail, word);
}
}
[Fact]
public void LabelShouldNotIncludeBracketIfTokenIncludesQuotedIdentifiersGivenReservedName()
{
string declarationTitle = "User";
string expected = "\"" + declarationTitle + "\"";
DeclarationType declarationType = DeclarationType.Table;
string tokenText = "\"";
SqlCompletionItem item = new SqlCompletionItem(declarationTitle, declarationType, tokenText);
CompletionItem completionItem = item.CreateCompletionItem(0, 1, 2);
Assert.Equal(completionItem.Label, expected);
Assert.Equal(completionItem.InsertText, expected);
Assert.Equal(completionItem.Detail, expected);
}
[Fact]
public void LabelShouldNotIncludeDoubleBracketIfTokenIncludesBracketsGivenReservedName()
{
string declarationTitle = "User";
string expected = "[" + declarationTitle + "]";
DeclarationType declarationType = DeclarationType.Table;
string tokenText = "[";
SqlCompletionItem item = new SqlCompletionItem(declarationTitle, declarationType, tokenText);
CompletionItem completionItem = item.CreateCompletionItem(0, 1, 2);
Assert.Equal(completionItem.Label, expected);
Assert.Equal(completionItem.InsertText, expected);
Assert.Equal(completionItem.Detail, expected);
}
[Fact]
public void KindShouldBeModuleGivenSchemaDeclarationType()
{