mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-18 09:35:38 -05:00
Merge branch 'dev' into feature/componentizeServiceHost
This commit is contained in:
124
test/ServiceHost.Test/LanguageServer/LanguageServiceTests.cs
Normal file
124
test/ServiceHost.Test/LanguageServer/LanguageServiceTests.cs
Normal file
@@ -0,0 +1,124 @@
|
||||
//
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
using Microsoft.SqlTools.ServiceLayer.LanguageServices;
|
||||
using Microsoft.SqlTools.ServiceLayer.WorkspaceServices.Contracts;
|
||||
using Microsoft.SqlTools.Test.Utility;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.Test.LanguageServer
|
||||
{
|
||||
/// <summary>
|
||||
/// Tests for the ServiceHost Language Service tests
|
||||
/// </summary>
|
||||
public class LanguageServiceTests
|
||||
{
|
||||
#region "Diagnostics tests"
|
||||
|
||||
/// <summary>
|
||||
/// Verify that the SQL parser correctly detects errors in text
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void ParseSelectStatementWithoutErrors()
|
||||
{
|
||||
// sql statement with no errors
|
||||
const string sqlWithErrors = "SELECT * FROM sys.objects";
|
||||
|
||||
// get the test service
|
||||
LanguageService service = TestObjects.GetTestLanguageService();
|
||||
|
||||
// parse the sql statement
|
||||
var scriptFile = new ScriptFile();
|
||||
scriptFile.SetFileContents(sqlWithErrors);
|
||||
ScriptFileMarker[] fileMarkers = service.GetSemanticMarkers(scriptFile);
|
||||
|
||||
// verify there are no errors
|
||||
Assert.Equal(0, fileMarkers.Length);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verify that the SQL parser correctly detects errors in text
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void ParseSelectStatementWithError()
|
||||
{
|
||||
// sql statement with errors
|
||||
const string sqlWithErrors = "SELECT *** FROM sys.objects";
|
||||
|
||||
// get test service
|
||||
LanguageService service = TestObjects.GetTestLanguageService();
|
||||
|
||||
// parse sql statement
|
||||
var scriptFile = new ScriptFile();
|
||||
scriptFile.SetFileContents(sqlWithErrors);
|
||||
ScriptFileMarker[] fileMarkers = service.GetSemanticMarkers(scriptFile);
|
||||
|
||||
// verify there is one error
|
||||
Assert.Equal(1, fileMarkers.Length);
|
||||
|
||||
// verify the position of the error
|
||||
Assert.Equal(9, fileMarkers[0].ScriptRegion.StartColumnNumber);
|
||||
Assert.Equal(1, fileMarkers[0].ScriptRegion.StartLineNumber);
|
||||
Assert.Equal(10, fileMarkers[0].ScriptRegion.EndColumnNumber);
|
||||
Assert.Equal(1, fileMarkers[0].ScriptRegion.EndLineNumber);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verify that the SQL parser correctly detects errors in text
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void ParseMultilineSqlWithErrors()
|
||||
{
|
||||
// multiline sql with errors
|
||||
const string sqlWithErrors =
|
||||
"SELECT *** FROM sys.objects;\n" +
|
||||
"GO\n" +
|
||||
"SELECT *** FROM sys.objects;\n";
|
||||
|
||||
// get test service
|
||||
LanguageService service = TestObjects.GetTestLanguageService();
|
||||
|
||||
// parse sql
|
||||
var scriptFile = new ScriptFile();
|
||||
scriptFile.SetFileContents(sqlWithErrors);
|
||||
ScriptFileMarker[] fileMarkers = service.GetSemanticMarkers(scriptFile);
|
||||
|
||||
// verify there are two errors
|
||||
Assert.Equal(2, fileMarkers.Length);
|
||||
|
||||
// check position of first error
|
||||
Assert.Equal(9, fileMarkers[0].ScriptRegion.StartColumnNumber);
|
||||
Assert.Equal(1, fileMarkers[0].ScriptRegion.StartLineNumber);
|
||||
Assert.Equal(10, fileMarkers[0].ScriptRegion.EndColumnNumber);
|
||||
Assert.Equal(1, fileMarkers[0].ScriptRegion.EndLineNumber);
|
||||
|
||||
// check position of second error
|
||||
Assert.Equal(9, fileMarkers[1].ScriptRegion.StartColumnNumber);
|
||||
Assert.Equal(3, fileMarkers[1].ScriptRegion.StartLineNumber);
|
||||
Assert.Equal(10, fileMarkers[1].ScriptRegion.EndColumnNumber);
|
||||
Assert.Equal(3, fileMarkers[1].ScriptRegion.EndLineNumber);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region "Autocomplete Tests"
|
||||
|
||||
/// <summary>
|
||||
/// Verify that the SQL parser correctly detects errors in text
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void AutocompleteTest()
|
||||
{
|
||||
var autocompleteService = TestObjects.GetAutoCompleteService();
|
||||
var connectionService = TestObjects.GetTestConnectionService();
|
||||
var connectionResult = connectionService.Connect(TestObjects.GetTestConnectionDetails());
|
||||
var sqlConnection = connectionService.ActiveConnections[connectionResult.ConnectionId];
|
||||
autocompleteService.UpdateAutoCompleteCache(sqlConnection);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user