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
|
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
|
|
|
|
2013-06-04 23:12:14 +04:00
|
|
|
describe '.hasSurrogatePair(string)', ->
|
|
|
|
it 'returns true when the string contains a surrogate pair', ->
|
|
|
|
expect(textUtils.hasSurrogatePair('abc')).toBe false
|
|
|
|
expect(textUtils.hasSurrogatePair('a\uD835\uDF97b\uD835\uDF97c')).toBe true
|
|
|
|
expect(textUtils.hasSurrogatePair('\uD835\uDF97')).toBe true
|
2013-06-04 23:16:45 +04:00
|
|
|
expect(textUtils.hasSurrogatePair('\uD835')).toBe false
|
|
|
|
expect(textUtils.hasSurrogatePair('\uDF97')).toBe false
|
2013-06-04 23:12:14 +04:00
|
|
|
|
2013-06-04 06:16:44 +04:00
|
|
|
describe '.isSurrogatePair(string, index)', ->
|
|
|
|
it 'returns true when the index is the start of a high/low surrogate pair', ->
|
|
|
|
expect(textUtils.isSurrogatePair('a\uD835\uDF97b\uD835\uDF97c', 0)).toBe false
|
|
|
|
expect(textUtils.isSurrogatePair('a\uD835\uDF97b\uD835\uDF97c', 1)).toBe true
|
|
|
|
expect(textUtils.isSurrogatePair('a\uD835\uDF97b\uD835\uDF97c', 2)).toBe false
|
|
|
|
expect(textUtils.isSurrogatePair('a\uD835\uDF97b\uD835\uDF97c', 3)).toBe false
|
|
|
|
expect(textUtils.isSurrogatePair('a\uD835\uDF97b\uD835\uDF97c', 4)).toBe true
|
|
|
|
expect(textUtils.isSurrogatePair('a\uD835\uDF97b\uD835\uDF97c', 5)).toBe false
|
|
|
|
expect(textUtils.isSurrogatePair('a\uD835\uDF97b\uD835\uDF97c', 6)).toBe false
|
2013-06-04 23:16:45 +04:00
|
|
|
expect(textUtils.isSurrogatePair('\uD835')).toBe false
|
|
|
|
expect(textUtils.isSurrogatePair('\uDF97')).toBe false
|