-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
491 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { Range } from 'vscode'; | ||
import { ExpandTest } from './types'; | ||
|
||
export const expandTests: ExpandTest[] = [ | ||
{ | ||
file: 'expand.ts.fixture', | ||
ranges: [new Range(3, 9, 3, 9)], | ||
targetRanges: [new Range(3, 0, 16, 20)], | ||
}, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { join } from 'path'; | ||
|
||
export const fixtureDir = join(__dirname, '../../../test/fixtures'); | ||
export * from './expand'; | ||
export * from './sort'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { join } from 'path'; | ||
import { Range } from 'vscode'; | ||
import { ExpandTest, SortTest } from './types'; | ||
|
||
export const sortTests: SortTest[] = [ | ||
{ | ||
file: 'block.ts.fixture', | ||
compareFile: 'block.ts.expect', | ||
ranges: [new Range(3, 0, 11, 22), new Range(17, 0, 31, 8), new Range(37, 0, 45, 8)], | ||
}, | ||
{ | ||
file: 'toplevel.ts.fixture', | ||
compareFile: 'toplevel.ts.expect', | ||
ranges: [new Range(0, 0, 59, 0)], | ||
}, | ||
{ | ||
file: 'comments.ts.fixture', | ||
compareFile: 'comments.ts.expect', | ||
ranges: [new Range(1, 0, 27, 3)], | ||
}, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { Range } from 'vscode'; | ||
|
||
interface BaseTest { | ||
file: string; | ||
ranges: Range[]; | ||
} | ||
|
||
export interface SortTest extends BaseTest { | ||
compareFile: string; | ||
} | ||
|
||
export interface ExpandTest extends BaseTest { | ||
targetRanges: Range[]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import * as assert from 'assert'; | ||
import { join } from 'path'; | ||
import { Range, TextDocument, window, workspace, Selection } from 'vscode'; | ||
import BlockSortProvider from '../../providers/BlockSortProvider'; | ||
import { expandTests, fixtureDir, sortTests } from '../fixtures'; | ||
|
||
suite('Unit Suite for BlockSortProvider', async () => { | ||
let document: TextDocument; | ||
let compareDocument: TextDocument; | ||
let blockSortProvider: BlockSortProvider; | ||
|
||
window.showInformationMessage('Start tests for BlockSortProvider.'); | ||
|
||
expandTests.map(({ file, ranges, targetRanges }) => { | ||
ranges | ||
.map((range, i) => ({ position: range, target: targetRanges[i] })) | ||
.forEach(({ position, target }) => { | ||
test('Expands selection', async () => { | ||
document = await workspace.openTextDocument(join(fixtureDir, file)); | ||
blockSortProvider = new BlockSortProvider(document); | ||
const selection = new Selection(position.start, position.end); | ||
const expanded = blockSortProvider.expandSelection(selection); | ||
|
||
assert(expanded.isEqual(target), 'range did not expand correctly'); | ||
}); | ||
}); | ||
}); | ||
|
||
sortTests.map(({ file, compareFile, ranges }) => { | ||
ranges.forEach((range, i) => { | ||
const descriptor = file.match(/^(.*)\.(.*)\.fixture/); | ||
const [_, type, lang] = descriptor || ['generic', 'generic']; | ||
test(`Sort Blocks (${type}, lang ${lang}) #${i}`, async () => { | ||
compareDocument = await workspace.openTextDocument(join(fixtureDir, compareFile)); | ||
document = await workspace.openTextDocument(join(fixtureDir, file)); | ||
blockSortProvider = new BlockSortProvider(document); | ||
|
||
const blocks = blockSortProvider.getBlocks(range); | ||
const sorted = blockSortProvider.sortBlocks(blocks).join('\n'); | ||
const compareSorted = compareDocument.getText(range); | ||
|
||
assert.strictEqual(sorted, compareSorted, 'sorted ranges are not equal'); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
class Test { | ||
testSwitch(input: string) { | ||
switch (input) { | ||
case 'a': | ||
return 'first'; | ||
case 'b': | ||
const result = 'second'; | ||
return result; | ||
case 'c': | ||
return 'third'; | ||
default: | ||
return 'last'; | ||
} | ||
} | ||
|
||
testObject() { | ||
return { | ||
a: { | ||
2: 2, | ||
0: 0, | ||
1: 1 | ||
}, | ||
b: { | ||
2: 2, | ||
0: 0, | ||
1: 1 | ||
}, | ||
c: { | ||
2: 2, | ||
0: 0, | ||
1: 1 | ||
} | ||
}; | ||
} | ||
|
||
testReverse() { | ||
return { | ||
a: { | ||
0: 0 | ||
}, | ||
b: { | ||
0: 0 | ||
}, | ||
c: { | ||
0: 0 | ||
} | ||
}; | ||
} | ||
|
||
testNatural() { | ||
return { | ||
3: { | ||
0: 0 | ||
}, | ||
5: { | ||
0: 0 | ||
}, | ||
16: { | ||
0: 0 | ||
}, | ||
300: { | ||
0: 0 | ||
} | ||
}; | ||
} | ||
|
||
testNaturalExtra() { | ||
return { | ||
0o3: { | ||
0: 0 | ||
}, | ||
0b101: { | ||
0: 0 | ||
}, | ||
0xF: { | ||
0: 0 | ||
}, | ||
300: { | ||
0: 0 | ||
} | ||
}; | ||
} | ||
} |
Oops, something went wrong.