forked from filamentgroup/glyphhanger
-
Notifications
You must be signed in to change notification settings - Fork 20
/
GlyphHangerWhitelistTest.js
92 lines (77 loc) · 2.96 KB
/
GlyphHangerWhitelistTest.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
const assert = require( "assert" );
const GlyphHangerWhitelist = require( "../src/GlyphHangerWhitelist" );
const CharacterSet = require( "characterset" );
describe( "GlyphHangerWhitelist", function() {
describe( "constructor", function() {
it( "made a simple whitelist from string", function() {
let wl = new GlyphHangerWhitelist("abc");
assert.equal( wl.getWhitelist(), "abc" );
assert.equal( wl.isEmpty(), false );
assert.equal( wl.getCharacterSet() instanceof CharacterSet, true );
});
it( "made a simple whitelist from empty string", function() {
let wl = new GlyphHangerWhitelist("");
assert.equal( wl.getWhitelist(), "" );
assert.equal( wl.isEmpty(), true );
});
it( "made a simple whitelist from unicode range", function() {
let wl = new GlyphHangerWhitelist("U+61-63");
assert.equal( wl.getWhitelist(), "abc" );
assert.equal( wl.isEmpty(), false );
});
it( "made a simple whitelist from string with US_ASCII", function() {
let wl = new GlyphHangerWhitelist("abc", {
US_ASCII: true
});
assert.equal( wl.getWhitelistAsUnicodes(), "U+20-7E" );
assert.equal( wl.isEmpty(), false );
});
it( "made a simple whitelist from empty string with US_ASCII", function() {
let wl = new GlyphHangerWhitelist("", {
US_ASCII: true
});
assert.equal( wl.getWhitelistAsUnicodes(), "U+20-7E" );
assert.equal( wl.isEmpty(), false );
});
it( "made a simple whitelist from unicode range with US_ASCII", function() {
let wl = new GlyphHangerWhitelist("U+61-63", {
US_ASCII: true
});
assert.equal( wl.getWhitelistAsUnicodes(), "U+20-7E" );
assert.equal( wl.isEmpty(), false );
});
it( "doesn’t barf when you don’t pass in a whitelist", function() {
let wl = new GlyphHangerWhitelist("");
assert.equal( wl.getWhitelistAsUnicodes(), "" );
assert.equal( wl.isEmpty(), true );
});
it( "doesn’t barf when you pass in true (whitelist enabled but empty)", function() {
let wl = new GlyphHangerWhitelist(true);
assert.equal( wl.getWhitelistAsUnicodes(), "" );
assert.equal( wl.isEmpty(), true );
});
it( "using LATIN", function() {
let wl = new GlyphHangerWhitelist("", {
LATIN: true
});
assert.equal( wl.isEmpty(), false );
});
});
describe( "unicodeCodePointsRegex", function() {
it( "Matched a single code point", function() {
assert.ok( "U+20".match( GlyphHangerWhitelist.unicodeCodePointsRegex ) );
});
it( "Matched a range", function() {
assert.ok( "U+20-32".match( GlyphHangerWhitelist.unicodeCodePointsRegex ) );
});
it( "Mixed range", function() {
assert.ok( "U+20-7E,U+A0-FF,U+131".match( GlyphHangerWhitelist.unicodeCodePointsRegex ) );
});
it( "Mixed range with spaces", function() {
assert.ok( "U+20-7E, U+A0-FF, U+131".match( GlyphHangerWhitelist.unicodeCodePointsRegex ) );
});
it( "Lower case mixed range with spaces", function() {
assert.ok( "u+20-7e, u+a0-ff, u+131".match( GlyphHangerWhitelist.unicodeCodePointsRegex ) );
});
});
});