2013-09-18 05:58:41 +04:00
|
|
|
textUtils = require '../src/text-utils'
|
2013-06-04 06:16:44 +04:00
|
|
|
|
|
|
|
describe 'text utilities', ->
|
2014-09-17 20:26:52 +04:00
|
|
|
describe '.hasPairedCharacter(string)', ->
|
2014-10-24 20:44:45 +04:00
|
|
|
it 'returns true when the string contains a surrogate pair, variation sequence, or combined character', ->
|
2014-09-17 20:26:52 +04:00
|
|
|
expect(textUtils.hasPairedCharacter('abc')).toBe false
|
|
|
|
expect(textUtils.hasPairedCharacter('a\uD835\uDF97b\uD835\uDF97c')).toBe true
|
|
|
|
expect(textUtils.hasPairedCharacter('\uD835\uDF97')).toBe true
|
|
|
|
expect(textUtils.hasPairedCharacter('\u2714\uFE0E')).toBe true
|
2014-10-24 20:43:39 +04:00
|
|
|
expect(textUtils.hasPairedCharacter('e\u0301')).toBe true
|
|
|
|
|
2014-09-17 20:26:52 +04:00
|
|
|
expect(textUtils.hasPairedCharacter('\uD835')).toBe false
|
|
|
|
expect(textUtils.hasPairedCharacter('\uDF97')).toBe false
|
|
|
|
expect(textUtils.hasPairedCharacter('\uFE0E')).toBe false
|
2014-10-24 20:43:39 +04:00
|
|
|
expect(textUtils.hasPairedCharacter('\u0301')).toBe false
|
|
|
|
|
2014-09-17 20:40:49 +04:00
|
|
|
expect(textUtils.hasPairedCharacter('\uFE0E\uFE0E')).toBe false
|
2014-10-24 20:43:39 +04:00
|
|
|
expect(textUtils.hasPairedCharacter('\u0301\u0301')).toBe false
|
2013-06-04 23:12:14 +04:00
|
|
|
|
2014-09-17 20:26:52 +04:00
|
|
|
describe '.isPairedCharacter(string, index)', ->
|
2014-10-24 20:44:45 +04:00
|
|
|
it 'returns true when the index is the start of a high/low surrogate pair, variation sequence, or combined character', ->
|
2014-09-17 20:26:52 +04:00
|
|
|
expect(textUtils.isPairedCharacter('a\uD835\uDF97b\uD835\uDF97c', 0)).toBe false
|
|
|
|
expect(textUtils.isPairedCharacter('a\uD835\uDF97b\uD835\uDF97c', 1)).toBe true
|
|
|
|
expect(textUtils.isPairedCharacter('a\uD835\uDF97b\uD835\uDF97c', 2)).toBe false
|
|
|
|
expect(textUtils.isPairedCharacter('a\uD835\uDF97b\uD835\uDF97c', 3)).toBe false
|
|
|
|
expect(textUtils.isPairedCharacter('a\uD835\uDF97b\uD835\uDF97c', 4)).toBe true
|
|
|
|
expect(textUtils.isPairedCharacter('a\uD835\uDF97b\uD835\uDF97c', 5)).toBe false
|
|
|
|
expect(textUtils.isPairedCharacter('a\uD835\uDF97b\uD835\uDF97c', 6)).toBe false
|
2014-10-24 20:43:39 +04:00
|
|
|
|
2014-09-17 20:26:52 +04:00
|
|
|
expect(textUtils.isPairedCharacter('a\u2714\uFE0E', 0)).toBe false
|
|
|
|
expect(textUtils.isPairedCharacter('a\u2714\uFE0E', 1)).toBe true
|
|
|
|
expect(textUtils.isPairedCharacter('a\u2714\uFE0E', 2)).toBe false
|
|
|
|
expect(textUtils.isPairedCharacter('a\u2714\uFE0E', 3)).toBe false
|
2014-10-24 20:43:39 +04:00
|
|
|
|
2014-09-17 20:26:52 +04:00
|
|
|
expect(textUtils.isPairedCharacter('\uD835')).toBe false
|
|
|
|
expect(textUtils.isPairedCharacter('\uDF97')).toBe false
|
2014-09-17 20:40:49 +04:00
|
|
|
expect(textUtils.isPairedCharacter('\uFE0E')).toBe false
|
|
|
|
expect(textUtils.isPairedCharacter('\uFE0E')).toBe false
|
2014-10-24 20:43:39 +04:00
|
|
|
|
2014-09-17 20:40:49 +04:00
|
|
|
expect(textUtils.isPairedCharacter('\uFE0E\uFE0E')).toBe false
|
2014-10-24 20:43:39 +04:00
|
|
|
|
|
|
|
expect(textUtils.isPairedCharacter('ae\u0301c', 0)).toBe false
|
|
|
|
expect(textUtils.isPairedCharacter('ae\u0301c', 1)).toBe true
|
|
|
|
expect(textUtils.isPairedCharacter('ae\u0301c', 2)).toBe false
|
|
|
|
expect(textUtils.isPairedCharacter('ae\u0301c', 3)).toBe false
|
|
|
|
expect(textUtils.isPairedCharacter('ae\u0301c', 4)).toBe false
|