mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-14 09:59:48 -05:00
- TSqlFormatterService with support for formatting document and text range inside document - Settings support for all formatting options. - Extensibility support so that the service can be initialized using MEF extensibility, and can find all necessary TSqlFormatters using the same process Fix Initialize request error on startup - Messages were being read from the input channel before all request handlers were registered - In particular, the Initialize request which is key for any server to talk to the client was getting lost because the message reader thread begins consuming, and we take an extra few hundred milliseconds due to MEF startup before we register the handler - The solution is to initialize the message handler so request handlers can register, but not actually start processing incoming messages until all handers are ready. This is a safer way to go and should improve reliability overall Improvements from internal prototype: - Normalizing baselines to handle the line ending differences on Mac & Linux vs. Windows - Significantly shortened most lines by implementing base class methods to wrap common objects from Visitor.Context and removing unnecessary "this." syntax - Refactored the SqlCommonTableExpressionFormatter and related classes to reduce code count significantly. This provides a pattern to follow when refactoring other classes for similar clarity. It's likely a lot of common logic could be found and reused across these. - Reduced overall code size by adding utility methods
83 lines
2.9 KiB
C#
83 lines
2.9 KiB
C#
//
|
|
// 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.Formatter;
|
|
using Xunit;
|
|
|
|
namespace Microsoft.SqlTools.ServiceLayer.Test.Formatter
|
|
{
|
|
|
|
public class InsertFormatterTests : FormatterUnitTestsBase
|
|
{
|
|
[Fact]
|
|
public void Insert_DefaultValues()
|
|
{
|
|
LoadAndFormatAndCompare("Insert_DefaultValues", GetInputFile("Insert_DefaultValues.sql"),
|
|
GetBaselineFile("Insert_DefaultValues.sql"), new FormatOptions(), true);
|
|
}
|
|
|
|
[Fact]
|
|
public void Insert_OpenQuery()
|
|
{
|
|
LoadAndFormatAndCompare("Insert_OpenQuery", GetInputFile("Insert_OpenQuery.sql"),
|
|
GetBaselineFile("Insert_OpenQuery.sql"), new FormatOptions(), true);
|
|
}
|
|
|
|
[Fact]
|
|
public void Insert_OutputInto()
|
|
{
|
|
LoadAndFormatAndCompare("Insert_OutputInto", GetInputFile("Insert_OutputInto.sql"),
|
|
GetBaselineFile("Insert_OutputInto.sql"), new FormatOptions(), true);
|
|
}
|
|
|
|
[Fact]
|
|
public void Insert_OutputStatement()
|
|
{
|
|
LoadAndFormatAndCompare("Insert_OutputStatement", GetInputFile("Insert_OutputStatement.sql"),
|
|
GetBaselineFile("Insert_OutputStatement.sql"), new FormatOptions(), true);
|
|
}
|
|
|
|
[Fact]
|
|
public void Insert_Select()
|
|
{
|
|
FormatOptions options = new FormatOptions();
|
|
options.PlaceEachReferenceOnNewLineInQueryStatements = true;
|
|
LoadAndFormatAndCompare("Insert_Select", GetInputFile("Insert_Select.sql"),
|
|
GetBaselineFile("Insert_Select.sql"), options, true);
|
|
}
|
|
|
|
[Fact]
|
|
public void Insert_SelectSource()
|
|
{
|
|
FormatOptions options = new FormatOptions();
|
|
options.PlaceEachReferenceOnNewLineInQueryStatements = true;
|
|
LoadAndFormatAndCompare("Insert_SelectSource", GetInputFile("Insert_SelectSource.sql"),
|
|
GetBaselineFile("Insert_SelectSource.sql"), options, true);
|
|
}
|
|
|
|
[Fact]
|
|
public void Insert_TopSpecification()
|
|
{
|
|
LoadAndFormatAndCompare("Insert_TopSpecification", GetInputFile("Insert_TopSpecification.sql"),
|
|
GetBaselineFile("Insert_TopSpecification.sql"), new FormatOptions(), true);
|
|
}
|
|
|
|
[Fact]
|
|
public void Insert_TopWithComments()
|
|
{
|
|
LoadAndFormatAndCompare("Insert_TopWithComments", GetInputFile("Insert_TopWithComments.sql"),
|
|
GetBaselineFile("Insert_TopWithComments.sql"), new FormatOptions(), true);
|
|
}
|
|
|
|
[Fact]
|
|
public void Insert_Full()
|
|
{
|
|
LoadAndFormatAndCompare("Insert_Full", GetInputFile("Insert_Full.sql"),
|
|
GetBaselineFile("Insert_Full.sql"), new FormatOptions(), true);
|
|
}
|
|
}
|
|
}
|