Skip to content

Commit 9afd2c9

Browse files
authored
Fix joining of source when source is an array of strings (#186)
* Fix joining of source when source is an array of strings * Add test
1 parent e52fb63 commit 9afd2c9

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

javascript/src/ycell.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ export const createCell = (
113113
}
114114
if (cell.source != null) {
115115
ycell.setSource(
116-
typeof cell.source === 'string' ? cell.source : cell.source.join('\n')
116+
typeof cell.source === 'string' ? cell.source : cell.source.join('')
117117
);
118118
}
119119
return ycell;

javascript/test/ycell.spec.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Copyright (c) Jupyter Development Team.
33
// Distributed under the terms of the Modified BSD License.
44

5-
import { IMapChange, YCodeCell, YNotebook } from '../src';
5+
import { createStandaloneCell, IMapChange, YCodeCell, YNotebook } from '../src';
66

77
describe('@jupyter/ydoc', () => {
88
// Fix awareness timeout open handle
@@ -13,6 +13,17 @@ describe('@jupyter/ydoc', () => {
1313
jest.clearAllTimers();
1414
});
1515

16+
describe('createStandaloneCell', () => {
17+
test('should convert a source set as a list of string to a single string', () => {
18+
const cell = createStandaloneCell({
19+
cell_type: 'code',
20+
source: ['import this\n', 'import math']
21+
});
22+
23+
expect(cell.source).toEqual('import this\nimport math');
24+
});
25+
});
26+
1627
describe('YCell standalone', () => {
1728
test('should set source', () => {
1829
const codeCell = YCodeCell.create();

0 commit comments

Comments
 (0)