Save multiline source in notebooks (#6445)

* Save multiline source in notebooks

* Stop demultiline localContentManager unnecessarily
This commit is contained in:
Chris LaFreniere
2019-07-26 10:30:52 -07:00
committed by GitHub
parent 5cffa7fe52
commit d51bdbd094
8 changed files with 153 additions and 13 deletions

View File

@@ -130,6 +130,121 @@ suite('Cell Model', function (): void {
should(cell.language).equal('python');
});
test('Should allow source of type string[] with length 1', async function (): Promise<void> {
let cellData: nb.ICellContents = {
cell_type: CellTypes.Code,
source: ['print(1)'],
metadata: { language: 'sql' },
execution_count: 1
};
let notebookModel = new NotebookModelStub({
name: '',
version: '',
mimetype: ''
});
let cell = factory.createCell(cellData, { notebook: notebookModel, isTrusted: false });
should(Array.isArray(cell.source)).equal(true);
should(cell.source.length).equal(1);
should(cell.source[0]).equal('print(1)');
});
test('Should allow source of type string', async function (): Promise<void> {
let cellData: nb.ICellContents = {
cell_type: CellTypes.Code,
source: 'print(1)',
metadata: { language: 'sql' },
execution_count: 1
};
let notebookModel = new NotebookModelStub({
name: '',
version: '',
mimetype: ''
});
let cell = factory.createCell(cellData, { notebook: notebookModel, isTrusted: false });
should(Array.isArray(cell.source)).equal(false);
should(cell.source).equal('print(1)');
});
test('Should allow source of type string with newline and split it', async function (): Promise<void> {
let cellData: nb.ICellContents = {
cell_type: CellTypes.Code,
source: 'print(1)\nprint(2)',
metadata: { language: 'sql' },
execution_count: 1
};
let notebookModel = new NotebookModelStub({
name: '',
version: '',
mimetype: ''
});
let cell = factory.createCell(cellData, { notebook: notebookModel, isTrusted: false });
should(Array.isArray(cell.source)).equal(true);
should(cell.source.length).equal(2);
should(cell.source[0]).equal('print(1)\n');
should(cell.source[1]).equal('print(2)');
});
test('Should allow source of type string with Windows style newline and split it', async function (): Promise<void> {
let cellData: nb.ICellContents = {
cell_type: CellTypes.Code,
source: 'print(1)\r\nprint(2)',
metadata: { language: 'sql' },
execution_count: 1
};
let notebookModel = new NotebookModelStub({
name: '',
version: '',
mimetype: ''
});
let cell = factory.createCell(cellData, { notebook: notebookModel, isTrusted: false });
should(Array.isArray(cell.source)).equal(true);
should(cell.source.length).equal(2);
should(cell.source[0]).equal('print(1)\r\n');
should(cell.source[1]).equal('print(2)');
});
test('Should allow source of type string[] with length 2', async function (): Promise<void> {
let cellData: nb.ICellContents = {
cell_type: CellTypes.Code,
source: ['print(1)\n', 'print(2)'],
metadata: { language: 'sql' },
execution_count: 1
};
let notebookModel = new NotebookModelStub({
name: '',
version: '',
mimetype: ''
});
let cell = factory.createCell(cellData, { notebook: notebookModel, isTrusted: false });
should(Array.isArray(cell.source)).equal(true);
should(cell.source.length).equal(2);
should(cell.source[0]).equal('print(1)\n');
should(cell.source[1]).equal('print(2)');
});
test('Should allow empty string source', async function (): Promise<void> {
let cellData: nb.ICellContents = {
cell_type: CellTypes.Code,
source: '',
metadata: { language: 'sql' },
execution_count: 1
};
let notebookModel = new NotebookModelStub({
name: '',
version: '',
mimetype: ''
});
let cell = factory.createCell(cellData, { notebook: notebookModel, isTrusted: false });
should(Array.isArray(cell.source)).equal(false);
should(cell.source).equal('');
});
suite('Model Future handling', function (): void {
let future: TypeMoq.Mock<EmptyFuture>;
let cell: ICellModel;