Last change
on this file was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
965 bytes
|
Line | |
---|
1 | var test = require('tape');
|
---|
2 | var punycode = require('punycode');
|
---|
3 | var ent = require('../');
|
---|
4 |
|
---|
5 | test('hex', function (t) {
|
---|
6 | for (var i = 0; i < 32; i++) {
|
---|
7 | var a = String.fromCharCode(i);
|
---|
8 | if (a.match(/\s/)) {
|
---|
9 | t.equal(ent.decode(a), a);
|
---|
10 | }
|
---|
11 | else {
|
---|
12 | var b = '&#x' + i.toString(16) + ';';
|
---|
13 | t.equal(ent.decode(b), a);
|
---|
14 | t.equal(ent.encode(a), '&#' + i + ';');
|
---|
15 | }
|
---|
16 | }
|
---|
17 |
|
---|
18 | for (var i = 127; i < 2000; i++) {
|
---|
19 | var a = String.fromCharCode(i);
|
---|
20 | var b = '&#x' + i.toString(16) + ';';
|
---|
21 | var c = '&#X' + i.toString(16) + ';';
|
---|
22 |
|
---|
23 | t.equal(ent.decode(b), a);
|
---|
24 | t.equal(ent.decode(c), a);
|
---|
25 |
|
---|
26 | var encoded = ent.encode(a);
|
---|
27 | var encoded2 = ent.encode(a + a);
|
---|
28 | if (!encoded.match(/^&\w+;/)) {
|
---|
29 | t.equal(encoded, '&#' + i + ';');
|
---|
30 | t.equal(encoded2, '&#' + i + ';&#' + i + ';');
|
---|
31 | }
|
---|
32 | }
|
---|
33 | t.end();
|
---|
34 | });
|
---|
35 |
|
---|
Note:
See
TracBrowser
for help on using the repository browser.