-
Notifications
You must be signed in to change notification settings - Fork 766
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix issue with mark offsets when using
lineBreakChar
- Loading branch information
Showing
6 changed files
with
102 additions
and
35 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
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
12 changes: 12 additions & 0 deletions
12
packages/diff/src/internal/utils/unused-char-generator.spec.ts
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,12 @@ | ||
import { unusedCharGenerator } from './unused-char-generator'; | ||
|
||
describe('unusedCharGenerator', () => { | ||
it('should generate unique chars that are not skipped', () => { | ||
const generator = unusedCharGenerator({ | ||
skipChars: 'DO NOT USE ANY OF THESE CHARS', | ||
}); | ||
|
||
const chars = Array.from({ length: 10 }, () => generator.next().value); | ||
expect(chars).toEqual(['B', 'G', 'I', 'J', 'K', 'L', 'M', 'P', 'Q', 'V']); | ||
}); | ||
}); |
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,15 @@ | ||
export interface UnusedCharGeneratorOptions { | ||
skipChars?: string; | ||
} | ||
|
||
export function* unusedCharGenerator({ | ||
skipChars = '', | ||
}: UnusedCharGeneratorOptions = {}): Generator<string> { | ||
const skipSet = new Set(skipChars); | ||
|
||
for (let code = 'A'.codePointAt(0)!; ; code++) { | ||
const c = String.fromCodePoint(code); | ||
if (skipSet.has(c)) continue; | ||
yield c; | ||
} | ||
} |