|
| 1 | +// // Copyright 2024 The MathWorks, Inc. |
1 | 2 | // import assert from 'assert'
|
2 | 3 | // import sinon from 'sinon'
|
3 |
| - |
| 4 | +// |
4 | 5 | // import FormatSupportProvider from '../../../src/providers/formatting/FormatSupportProvider'
|
5 | 6 | // import MatlabLifecycleManager from '../../../src/lifecycle/MatlabLifecycleManager'
|
6 | 7 | // import ClientConnection from '../../../src/ClientConnection'
|
7 |
| - |
| 8 | +// |
8 | 9 | // import { TextDocument } from 'vscode-languageserver-textdocument'
|
9 | 10 | // import { _Connection, DocumentFormattingParams, Position, Range, TextDocuments, TextEdit } from 'vscode-languageserver'
|
10 | 11 | // import getMockConnection from '../../mocks/Connection.mock'
|
11 |
| - |
| 12 | +// |
12 | 13 | // describe('FormatSupportProvider', () => {
|
13 | 14 | // let formatSupportProvider: FormatSupportProvider
|
14 | 15 | // let matlabLifecycleManager: MatlabLifecycleManager
|
15 | 16 | // let documentManager: TextDocuments<TextDocument>
|
16 | 17 | // let mockMatlabConnection: any
|
17 | 18 | // let mockTextDocument: TextDocument
|
18 |
| - |
| 19 | +// |
19 | 20 | // before(() => {
|
20 | 21 | // ClientConnection._setConnection(getMockConnection())
|
21 | 22 | // })
|
22 |
| - |
| 23 | +// |
23 | 24 | // after(() => {
|
24 | 25 | // ClientConnection._clearConnection()
|
25 | 26 | // })
|
26 |
| - |
| 27 | +// |
27 | 28 | // describe('#handleDocumentFormatRequest', () => {
|
28 | 29 | // // Because the actual formatting logic occurs in MATLAB, the actual value of these
|
29 | 30 | // // params are not tested in this file. So, define static params for each test.
|
30 | 31 | // const mockParams = {
|
31 | 32 | // textDocument: { uri: 'file:///test.m' },
|
32 | 33 | // options: { insertSpaces: true, tabSize: 4 }
|
33 | 34 | // } as DocumentFormattingParams
|
34 |
| - |
| 35 | +// |
35 | 36 | // beforeEach(() => {
|
36 | 37 | // matlabLifecycleManager = new MatlabLifecycleManager()
|
37 | 38 | // formatSupportProvider = new FormatSupportProvider(matlabLifecycleManager)
|
|
43 | 44 | // publish: sinon.stub()
|
44 | 45 | // }
|
45 | 46 | // mockTextDocument = TextDocument.create('file:///test.m', 'matlab', 1, 'function y = test(x)\ny = x + 1;\nend')
|
46 |
| - |
| 47 | +// |
47 | 48 | // sinon.stub(matlabLifecycleManager, 'getMatlabConnection').returns(mockMatlabConnection)
|
48 | 49 | // sinon.stub(documentManager, 'get').returns(mockTextDocument)
|
49 | 50 | // })
|
50 |
| - |
| 51 | +// |
51 | 52 | // afterEach(() => {
|
52 | 53 | // sinon.restore()
|
53 | 54 | // })
|
54 |
| - |
| 55 | + // |
55 | 56 | // it('should return null if no document to format', async () => {
|
56 | 57 | // // Return undefined text document
|
57 | 58 | // (documentManager.get as sinon.SinonStub).returns(undefined)
|
58 |
| - |
| 59 | +// |
59 | 60 | // const res = await formatSupportProvider.handleDocumentFormatRequest(mockParams, documentManager)
|
60 |
| - |
| 61 | +// |
61 | 62 | // assert.equal(res, null, 'Result should be null when there is no document')
|
62 | 63 | // })
|
63 |
| - |
| 64 | +// |
64 | 65 | // it('should return empty array if no MATLAB connection', async () => {
|
65 | 66 | // // Return null MATLAB connection
|
66 | 67 | // (matlabLifecycleManager.getMatlabConnection as sinon.SinonStub).resolves(null)
|
67 |
| - |
| 68 | +// |
68 | 69 | // const res = await formatSupportProvider.handleDocumentFormatRequest(mockParams, documentManager)
|
69 |
| - |
| 70 | +// |
70 | 71 | // assert.deepEqual(res, [], 'Result should be [] when there is no connection')
|
71 | 72 | // })
|
72 |
| - |
| 73 | +// |
73 | 74 | // it('should handle successful formatting', async () => {
|
74 | 75 | // const formattedCode = 'function y = test(x)\n y = x + 1;\nend'
|
75 | 76 | // const expectedEdit = TextEdit.replace(
|
76 | 77 | // Range.create(Position.create(0, 0), Position.create(2, 3)),
|
77 | 78 | // formattedCode
|
78 | 79 | // )
|
79 |
| - |
| 80 | +// |
80 | 81 | // mockMatlabConnection.subscribe.callsFake((channel: string, callback: any) => {
|
81 | 82 | // setTimeout(() => {
|
82 | 83 | // callback({ data: formattedCode })
|
83 | 84 | // }, 0)
|
84 | 85 | // return 'subscription-id'
|
85 | 86 | // })
|
86 |
| - |
| 87 | +// |
87 | 88 | // const result = await formatSupportProvider.handleDocumentFormatRequest(mockParams, documentManager)
|
88 |
| - |
| 89 | +// |
89 | 90 | // assert.deepStrictEqual(result, [expectedEdit])
|
90 | 91 | // sinon.assert.calledOnce(mockMatlabConnection.publish)
|
91 | 92 | // sinon.assert.calledWith(mockMatlabConnection.publish, formatSupportProvider.REQUEST_CHANNEL, {
|
|
0 commit comments