Return as soon as first paired character is found

Previously the character count of the entire string was taken even
though it was only checking for the presence of a paired character.

Now hasPairedCharacter returns as early as possible and the now
unused getCharacterCount has been removed.
This commit is contained in:
Kevin Sawicki
2014-09-17 10:35:33 -07:00
parent e343b0e0fc
commit f1fd13b0b2
2 changed files with 6 additions and 28 deletions

View File

@@ -1,17 +1,6 @@
textUtils = require '../src/text-utils'
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
expect(textUtils.getCharacterCount('\u2714\uFE0E')).toBe 1
expect(textUtils.getCharacterCount('\uD835')).toBe 1
expect(textUtils.getCharacterCount('\uDF97')).toBe 1
expect(textUtils.getCharacterCount('\uFE0E')).toBe 1
expect(textUtils.getCharacterCount('\uFE0E\uFE0E')).toBe 2
describe '.hasPairedCharacter(string)', ->
it 'returns true when the string contains a surrogate pair or variation sequence', ->
expect(textUtils.hasPairedCharacter('abc')).toBe false