|
1 | 1 | import * as assert from 'assert';
|
2 |
| -import * as path from 'path'; |
3 | 2 | import * as vscode from 'vscode';
|
4 | 3 | import { Range, TextDocument } from 'vscode';
|
5 | 4 | import { adjustedRangeWithMinimumIndentation, contentOfLinesWithAdjustedIndentation, endOfLineCharacter, linesForIndexes, minimumIndentationForLineIndexes } from '../../../lib/documentHelpers';
|
6 | 5 |
|
7 |
| - |
8 |
| -const fixturesPath = '/../../../../src/test/fixtures/'; |
9 |
| -const uri = vscode.Uri.file( |
10 |
| - path.join(__dirname + fixturesPath + 'javascript-example.js') |
11 |
| -); |
| 6 | +const fixtureUri = (fileName: string) => { |
| 7 | + const workspaceFolder = vscode.workspace.workspaceFolders![0]; |
| 8 | + return vscode.Uri.joinPath(workspaceFolder.uri, fileName); |
| 9 | +}; |
12 | 10 |
|
13 | 11 | describe('Document Helpers', function () {
|
14 | 12 | let document: TextDocument;
|
15 | 13 |
|
16 | 14 | before(async () => {
|
| 15 | + const uri = fixtureUri('javascript-example.js'); |
17 | 16 | document = await vscode.workspace.openTextDocument(uri);
|
18 | 17 | });
|
19 | 18 |
|
20 | 19 | context('linesForIndexes', () => {
|
21 | 20 | it('returns the correct lines', () => {
|
22 | 21 | const lines = linesForIndexes(document, [0, 1]);
|
23 |
| - assert.equal(lines.length, 2); |
24 |
| - assert.equal(lines[0].lineNumber, 0); |
25 |
| - assert.equal(lines[0].text, 'class MyThing {'); |
26 |
| - assert.equal(lines[1].lineNumber, 1); |
27 |
| - assert.equal(lines[1].text, ' doSomething(aValue) {'); |
| 22 | + assert.strictEqual(lines.length, 2); |
| 23 | + assert.strictEqual(lines[0].lineNumber, 0); |
| 24 | + assert.strictEqual(lines[0].text, 'class MyThing {'); |
| 25 | + assert.strictEqual(lines[1].lineNumber, 1); |
| 26 | + assert.strictEqual(lines[1].text, ' doSomething(aValue) {'); |
28 | 27 | });
|
29 | 28 | });
|
30 | 29 |
|
31 | 30 | context('minimumIndentationLevelForLineIndexes', () => {
|
32 | 31 | it('calculates the correct minimum indentation level for a single line', () => {
|
33 |
| - assert.equal(minimumIndentationForLineIndexes(document, [3]), 6); |
| 32 | + assert.strictEqual(minimumIndentationForLineIndexes(document, [3]), 6); |
34 | 33 | });
|
35 | 34 |
|
36 | 35 | it('calculates the correct minimum indentation level for multiple lines', () => {
|
37 |
| - assert.equal(minimumIndentationForLineIndexes(document, [1, 2, 3]), 2); |
| 36 | + assert.strictEqual(minimumIndentationForLineIndexes(document, [1, 2, 3]), 2); |
38 | 37 | });
|
39 | 38 |
|
40 | 39 | it('calculates the correct minimum indentation level when lines contain an empty line', () => {
|
41 |
| - assert.equal(minimumIndentationForLineIndexes(document, [11, 12, 13, 14]), 4); |
| 40 | + assert.strictEqual(minimumIndentationForLineIndexes(document, [11, 12, 13, 14]), 4); |
42 | 41 | });
|
43 | 42 | });
|
44 | 43 |
|
45 | 44 | context('contentOfLinesWithAdjustedIndentation', () => {
|
46 | 45 | it('returns multiline text with the indentation adjusted correctly', () => {
|
47 |
| - assert.equal(contentOfLinesWithAdjustedIndentation(document, [2, 3, 4], 4), 'if (aValue) {\n console.log(`Doing something with ${aValue}!`);\n}'); |
| 46 | + assert.strictEqual(contentOfLinesWithAdjustedIndentation(document, [2, 3, 4], 4), 'if (aValue) {\n console.log(`Doing something with ${aValue}!`);\n}'); |
48 | 47 | });
|
49 | 48 |
|
50 | 49 | it('returns single line text with the indentation adjusted correctly', () => {
|
51 |
| - assert.equal(contentOfLinesWithAdjustedIndentation(document, [3], 6), 'console.log(`Doing something with ${aValue}!`);'); |
| 50 | + assert.strictEqual(contentOfLinesWithAdjustedIndentation(document, [3], 6), 'console.log(`Doing something with ${aValue}!`);'); |
52 | 51 | });
|
53 | 52 |
|
54 | 53 | it('returns text with CRLF characters if file is using them', async () => {
|
55 |
| - const uri = vscode.Uri.file( |
56 |
| - path.join(__dirname + fixturesPath + 'crlf-ruby-example.rb') |
57 |
| - ); |
58 |
| - const crlfDocument = await vscode.workspace.openTextDocument(uri); |
| 54 | + const crlfDocument = await vscode.workspace.openTextDocument(fixtureUri('crlf-ruby-example.rb')); |
59 | 55 |
|
60 |
| - assert.equal(contentOfLinesWithAdjustedIndentation(crlfDocument, [1, 2, 3], 2), 'def polish\r\n puts "Polishing"\r\nend'); |
| 56 | + assert.strictEqual(contentOfLinesWithAdjustedIndentation(crlfDocument, [1, 2, 3], 2), 'def polish\r\n puts "Polishing"\r\nend'); |
61 | 57 | });
|
62 | 58 | });
|
63 | 59 |
|
64 | 60 | context('adjustedRangeWithMinimumIndentation', () => {
|
65 | 61 | it('adjusts the range', () => {
|
66 | 62 | const adjustedRange = adjustedRangeWithMinimumIndentation(new Range(2, 0, 2, 17), 4);
|
67 |
| - assert.equal(adjustedRange.start.line, 2); |
68 |
| - assert.equal(adjustedRange.start.character, 4); |
69 |
| - assert.equal(adjustedRange.end.line, 2); |
70 |
| - assert.equal(adjustedRange.end.character, 17); |
| 63 | + assert.strictEqual(adjustedRange.start.line, 2); |
| 64 | + assert.strictEqual(adjustedRange.start.character, 4); |
| 65 | + assert.strictEqual(adjustedRange.end.line, 2); |
| 66 | + assert.strictEqual(adjustedRange.end.character, 17); |
71 | 67 | });
|
72 | 68 | });
|
73 | 69 |
|
74 | 70 | context('endOfLineCharacter', () => {
|
75 | 71 | it('correctly returns LF', () => {
|
76 |
| - assert.equal(endOfLineCharacter(document), '\n'); |
| 72 | + assert.strictEqual(endOfLineCharacter(document), '\n'); |
77 | 73 | });
|
78 | 74 |
|
79 | 75 | it('correctly returns CRLF', async () => {
|
80 |
| - const uri = vscode.Uri.file( |
81 |
| - path.join(__dirname + fixturesPath + 'crlf-ruby-example.rb') |
82 |
| - ); |
83 |
| - assert.equal(endOfLineCharacter(await vscode.workspace.openTextDocument(uri)), '\r\n'); |
| 76 | + assert.strictEqual(endOfLineCharacter(await vscode.workspace.openTextDocument(fixtureUri('crlf-ruby-example.rb'))), '\r\n'); |
84 | 77 | });
|
85 | 78 | });
|
86 | 79 | });
|
0 commit comments