mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-14 01:25:40 -05:00
Include singleline comments outside batch for nb convert (#1139)
* Include singleline comments outside batch for nb convert * Remove extra space
This commit is contained in:
@@ -0,0 +1,105 @@
|
||||
//
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
using NUnit.Framework;
|
||||
using Microsoft.SqlTools.ServiceLayer.NotebookConvert;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.NotebookConvert
|
||||
{
|
||||
|
||||
[TestFixture]
|
||||
public class NotebookConvertServiceTests
|
||||
{
|
||||
[Test]
|
||||
public void ConvertSqlToNotebook()
|
||||
{
|
||||
var sql = @"
|
||||
/*
|
||||
* Initial multiline comment
|
||||
*/
|
||||
|
||||
-- Comment before batch
|
||||
SELECT * FROM sys.databases
|
||||
|
||||
-- Compare Row Counts in Tables From Two Different Databases With the Same Schema
|
||||
|
||||
SELECT * -- inline single line comment
|
||||
/* inline multiline
|
||||
* comment
|
||||
*/
|
||||
FROM sys.databases
|
||||
|
||||
-- ending single line comment
|
||||
/**
|
||||
* Ending multiline
|
||||
* comment
|
||||
*/
|
||||
";
|
||||
|
||||
var expectedNotebook = @"{
|
||||
""metadata"": {
|
||||
""kernelspec"": {
|
||||
""name"": ""SQL"",
|
||||
""display_name"": ""SQL"",
|
||||
""language"": ""sql""
|
||||
},
|
||||
""language_info"": {
|
||||
""name"": ""sql"",
|
||||
""version"": """"
|
||||
}
|
||||
},
|
||||
""nbformat_minor"": 2,
|
||||
""nbformat"": 4,
|
||||
""cells"": [
|
||||
{
|
||||
""cell_type"": ""markdown"",
|
||||
""source"": [
|
||||
""* Initial multiline comment""
|
||||
]
|
||||
},
|
||||
{
|
||||
""cell_type"": ""markdown"",
|
||||
""source"": [
|
||||
""Comment before batch""
|
||||
]
|
||||
},
|
||||
{
|
||||
""cell_type"": ""code"",
|
||||
""source"": [
|
||||
""SELECT * FROM sys.databases\n"",
|
||||
""\n"",
|
||||
""-- Compare Row Counts in Tables From Two Different Databases With the Same Schema\n"",
|
||||
""\n"",
|
||||
""SELECT * -- inline single line comment\n"",
|
||||
""/* inline multiline\n"",
|
||||
"" * comment\n"",
|
||||
"" */\n"",
|
||||
""FROM sys.databases""
|
||||
]
|
||||
},
|
||||
{
|
||||
""cell_type"": ""markdown"",
|
||||
""source"": [
|
||||
""ending single line comment""
|
||||
]
|
||||
},
|
||||
{
|
||||
""cell_type"": ""markdown"",
|
||||
""source"": [
|
||||
""* Ending multiline \n"",
|
||||
"" * comment""
|
||||
]
|
||||
}
|
||||
]
|
||||
}";
|
||||
|
||||
var notebook = NotebookConvertService.ConvertSqlToNotebook(sql);
|
||||
var notebookString = JsonConvert.SerializeObject(notebook, Formatting.Indented);
|
||||
Assert.AreEqual(expectedNotebook, notebookString);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user