Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/copilot/src/util/common/test/notebooks.spec.ts
13579 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import { Uri, NotebookCellData, NotebookCellKind, NotebookData } from '../../../vscodeTypes';
7
import { assert, describe, it } from 'vitest';
8
import { ExtHostNotebookDocumentData } from './shims/notebookDocument';
9
import { URI } from '../../vs/base/common/uri';
10
import { findCell, findNotebook, getNotebookAndCellFromUri, getNotebookCellOutput } from '../notebooks';
11
12
13
describe('Notebook Common', () => {
14
it('Does not find notebook', async () => {
15
const notebooks = createSampleNotebooks();
16
17
assert.isUndefined(findNotebook(Uri.file('foo.ipynb'), notebooks));
18
});
19
20
it('Finds a notebook', async () => {
21
const notebooks = createSampleNotebooks();
22
23
assert.isObject(findNotebook(Uri.file('one.ipynb'), notebooks));
24
});
25
26
it('Finds a notebook', async () => {
27
const notebooks = createSampleNotebooks();
28
for (const notebook of notebooks) {
29
for (const cell of notebook.getCells()) {
30
const info = getNotebookAndCellFromUri(cell.document.uri, notebooks);
31
assert.equal(info[0], notebook);
32
assert.equal(info[1], cell);
33
34
assert.equal(findCell(cell.document.uri, notebook), cell);
35
36
assert.equal(findNotebook(cell.document.uri, notebooks), notebook);
37
38
assert.isUndefined(getNotebookCellOutput(cell.document.uri, notebooks));
39
}
40
}
41
});
42
43
function createSampleNotebooks() {
44
return [
45
ExtHostNotebookDocumentData.fromNotebookData(URI.file('one.ipynb'), new NotebookData(createCells([['markdown', '# Hello'], ['markdown', '# Foo Bar'], ['code', 'print(1234)']])), 'jupyter-notebook').document,
46
ExtHostNotebookDocumentData.fromNotebookData(URI.file('two.ipynb'), new NotebookData(createCells([['markdown', '# Title'], ['code', 'import sys'], ['code', 'sys.executable']])), 'jupyter-notebook').document,
47
ExtHostNotebookDocumentData.fromNotebookData(URI.file('three.ipynb').with({ scheme: 'ssh' }), new NotebookData(createCells([['markdown', '# Title'], ['code', 'import sys'], ['code', 'sys.executable']])), 'jupyter-notebook').document,
48
];
49
}
50
function createCells(cells: [kind: 'code' | 'markdown', code: string][]) {
51
return cells.map(([kind, code]) => {
52
return new NotebookCellData(kind === 'markdown' ? NotebookCellKind.Markup : NotebookCellKind.Code, code, kind === 'markdown' ? 'markdown' : 'python');
53
});
54
}
55
});
56
57