|
1 | 1 | import * as assert from 'assert'; |
2 | | -import * as path from 'path'; |
3 | | -import * as vscode from 'vscode'; |
| 2 | +import { Selection } from 'vscode'; |
| 3 | +import { lineIndexesForSelection } from '../../../lib/selectionHelpers'; |
4 | 4 |
|
5 | | -import { calculateSelectionLineIndexes, calculateMinimumIndentationInSelection, adjustIndentationInSelection } from '../../../lib/selectionHelpers'; |
6 | | -// import * as myExtension from '../extension'; |
7 | | - |
8 | | -const fixturesPath = '/../../../../src/test/fixtures/'; |
9 | | -const uri = vscode.Uri.file( |
10 | | - path.join(__dirname + fixturesPath + 'javascript-example.js') |
11 | | -); |
12 | 5 |
|
13 | 6 | describe('Selection Helpers', function () { |
14 | 7 | context('calculateSelectionLineIndexes', () => { |
15 | 8 | it('calculates the correct line indexes from an empty selection', () => { |
16 | | - assert.deepEqual([0], calculateSelectionLineIndexes(new vscode.Selection(0, 0, 0, 0))); |
| 9 | + assert.deepEqual([0], lineIndexesForSelection(new Selection(0, 0, 0, 0))); |
17 | 10 | }); |
18 | 11 |
|
19 | 12 | it('calculates the correct line indexes from a single line selection', () => { |
20 | | - assert.deepEqual([1], calculateSelectionLineIndexes(new vscode.Selection(1, 2, 1, 15))); |
| 13 | + assert.deepEqual([1], lineIndexesForSelection(new Selection(1, 2, 1, 15))); |
21 | 14 | }); |
22 | 15 |
|
23 | 16 | it('calculates the correct line indexes from a multiline selection', () => { |
24 | | - assert.deepEqual([1, 2, 3], calculateSelectionLineIndexes(new vscode.Selection(1, 2, 3, 3))); |
| 17 | + assert.deepEqual([1, 2, 3], lineIndexesForSelection(new Selection(1, 2, 3, 3))); |
25 | 18 | }); |
26 | 19 |
|
27 | 20 | it('calculates the correct line indexes from an reversed selection ', () => { |
28 | | - assert.deepEqual([1, 2, 3], calculateSelectionLineIndexes(new vscode.Selection(3, 0, 1, 0))); |
29 | | - }); |
30 | | - }); |
31 | | - |
32 | | - context('calculateMinimumIndentationInSelection', async () => { |
33 | | - let document: vscode.TextDocument; |
34 | | - |
35 | | - before(async () => { |
36 | | - document = await vscode.workspace.openTextDocument(uri); |
37 | | - }); |
38 | | - |
39 | | - it('calculates the correct minimum indentation level for a single line', () => { |
40 | | - assert.equal(4, calculateMinimumIndentationInSelection(document, [2])); |
41 | | - }); |
42 | | - |
43 | | - it('calculates the correct minimum indentation level for multiple lines', () => { |
44 | | - assert.equal(2, calculateMinimumIndentationInSelection(document, [1, 2, 3])); |
45 | | - }); |
46 | | - }); |
47 | | - |
48 | | - context('adjustIndentationInSelection', async () => { |
49 | | - let document: vscode.TextDocument; |
50 | | - |
51 | | - before(async () => { |
52 | | - document = await vscode.workspace.openTextDocument(uri); |
53 | | - }); |
54 | | - |
55 | | - it('returns multiline text with the indentation adjusted correctly', () => { |
56 | | - assert.equal('if (aValue) {\n console.log(`Doing something with ${aValue}!`);\n}', adjustIndentationInSelection(document, [1, 2, 3], 2)); |
57 | | - }); |
58 | | - |
59 | | - it('returns single line text with the indentation adjusted correctly', () => { |
60 | | - assert.equal('console.log(`Doing something with ${aValue}!`);', adjustIndentationInSelection(document, [2], 4)); |
61 | | - }); |
62 | | - |
63 | | - it('returns text with CRLF characters if file is using them', async () => { |
64 | | - const uri = vscode.Uri.file( |
65 | | - path.join(__dirname + fixturesPath + 'crlf-ruby-example.rb') |
66 | | - ); |
67 | | - let crlfDocument = await vscode.workspace.openTextDocument(uri); |
68 | | - |
69 | | - assert.equal('def polish\r\n puts "Polishing"\r\nend', adjustIndentationInSelection(crlfDocument, [1, 2, 3], 2)); |
| 21 | + assert.deepEqual([1, 2, 3], lineIndexesForSelection(new Selection(3, 0, 1, 0))); |
70 | 22 | }); |
71 | 23 | }); |
72 | 24 | }); |
0 commit comments