2013-09-18 05:58:41 +04:00
|
|
|
textUtils = require '../src/text-utils'
|
2013-06-04 06:16:44 +04:00
|
|
|
|
|
|
|
describe 'text utilities', ->
|
|
|
|
describe '.getCharacterCount(string)', ->
|
|
|
|
it 'returns the number of full characters in the string', ->
|
|
|
|
expect(textUtils.getCharacterCount('abc')).toBe 3
|
|
|
|
expect(textUtils.getCharacterCount('a\uD835\uDF97b\uD835\uDF97c')).toBe 5
|
|
|
|
expect(textUtils.getCharacterCount('\uD835\uDF97')).toBe 1
|
2014-09-17 20:26:52 +04:00
|
|
|
expect(textUtils.getCharacterCount('\u2714\uFE0E')).toBe 1
|
2013-06-04 23:16:45 +04:00
|
|
|
expect(textUtils.getCharacterCount('\uD835')).toBe 1
|
|
|
|
expect(textUtils.getCharacterCount('\uDF97')).toBe 1
|
2013-06-04 06:16:44 +04:00
|
|
|
|
2014-09-17 20:26:52 +04:00
|
|
|
describe '.hasPairedCharacter(string)', ->
|
2014-09-17 20:28:24 +04:00
|
|
|
it 'returns true when the string contains a surrogate pair or variation sequence', ->
|
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
|
|
|
|
expect(textUtils.hasPairedCharacter('\uD835')).toBe false
|
|
|
|
expect(textUtils.hasPairedCharacter('\uDF97')).toBe false
|
|
|
|
expect(textUtils.hasPairedCharacter('\uFE0E')).toBe false
|
2013-06-04 23:12:14 +04:00
|
|
|
|
2014-09-17 20:26:52 +04:00
|
|
|
describe '.isPairedCharacter(string, index)', ->
|
2014-09-17 20:28:24 +04:00
|
|
|
it 'returns true when the index is the start of a high/low surrogate pair or variation sequence', ->
|
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
|
|
|
|
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
|
|
|
|
expect(textUtils.isPairedCharacter('\uD835')).toBe false
|
|
|
|
expect(textUtils.isPairedCharacter('\uDF97')).toBe false
|