precis-js
Version:
A JavaScript implementation of RFC 7564 (The PRECIS Framework).
43 lines (30 loc) • 1.58 kB
text/coffeescript
fs = require 'fs'
UnicodeTrie = require 'unicode-trie'
{ucs2} = require 'punycode'
CodepointPropertyReader = require '../../../src/unicode/CodepointPropertyReader'
EmptyStringError = require '../../../src/error/EmptyStringError'
OpaqueStringProfile = require '../../../src/profile/OpaqueStringProfile'
precis = require '../../../src/constants'
describe 'OpaqueStringProfile', ->
before ->
data = fs.readFileSync __dirname + '/../../../data/properties.trie'
= new UnicodeTrie data
beforeEach ->
= new OpaqueStringProfile()
= propertyReader: new CodepointPropertyReader
it 'has the correct properties', ->
assert.strictEqual .stringClass, precis.STRING_CLASS.FREEFORM
assert.strictEqual .widthMapping, precis.WIDTH_MAPPING.NONE
assert.strictEqual .caseMapping, precis.CASE_MAPPING.NONE
assert.strictEqual .normalization, precis.NORMALIZATION.C
assert.strictEqual .directionality, precis.DIRECTIONALITY.NONE
describe 'map()', ->
it 'maps non-ASCII spaces to ASCII spaces', ->
codepoints = ucs2.decode '\u3000ab\u3000cd\u3000ef\u3000'
.map codepoints,
assert.strictEqual ucs2.encode(codepoints), ' ab cd ef '
describe 'validate()', ->
it 'allows non-empty strings', ->
assert.doesNotThrow => .validate [0]
it 'rejects empty strings', ->
assert.throws (=> .validate []), EmptyStringError