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:
Charles Gagnon
2020-12-14 15:16:07 -08:00
committed by GitHub
parent a47fa8bf87
commit 5c7211e82a
3 changed files with 120 additions and 6 deletions

View File

@@ -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);
}
}
}