-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure text changes are applied in order (#42)
* ensure correct text change order * Actually impl test * fix formatting * formatting
- Loading branch information
Showing
2 changed files
with
62 additions
and
1 deletion.
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
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,34 @@ | ||
import { getTextChangeDict } from "../../src/index"; | ||
import { CodeFixAction } from "typescript"; | ||
|
||
const codefixes: CodeFixAction[] = [ | ||
{ | ||
fixName: 'fixOverrideModifier', | ||
description: 'Add \'override\' modifier', | ||
changes: [{ fileName: 'foo.ts', textChanges: [{ span: { start: 2, length: 0 }, newText: 'override ' }, { span: { start: 3, length: 0 }, newText: 'override ' }] }], | ||
commands: undefined, | ||
fixId: 'fixAddOverrideModifier' | ||
}, | ||
{ | ||
fixName: 'fixOverrideModifier', | ||
description: 'Add \'override\' modifier', | ||
changes: [{ fileName: 'foo.ts', textChanges: [{ span: { start: 1, length: 0 }, newText: 'override ' }] }], | ||
commands: undefined, | ||
fixId: 'fixAddOverrideModifier' | ||
}, | ||
{ | ||
fixName: 'addConvertToUnknownForNonOverlappingTypes', | ||
description: 'Add \'unknown\' conversion for non-overlapping types', | ||
changes: [{ fileName: 'foo.ts', textChanges: [{ span: { start: 8, length: 9 }, newText: '<unknown>["words"]' }] }], | ||
commands: undefined, | ||
fixId: 'addConvertToUnknownForNonOverlappingTypes' | ||
}, | ||
] | ||
|
||
test("should merge text changes in order", () => { | ||
const result = getTextChangeDict(codefixes); | ||
const changes = result.get('foo.ts'); | ||
const spanStarts = changes?.map(c => c.span.start); | ||
expect(spanStarts).toEqual([1, 2, 3, 8]); | ||
}) | ||
|