source: trip-planner-front/node_modules/ent/test/codes.js@ 6a80231

Last change on this file since 6a80231 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 2.3 KB
Line 
1var test = require('tape');
2var punycode = require('punycode');
3var ent = require('../');
4
5test('amp', function (t) {
6 var a = 'a & b & c';
7 var b = 'a &#38; b &#38; c';
8 t.equal(ent.encode(a), b);
9 t.equal(ent.decode(b), a);
10 t.end();
11});
12
13test('html', function (t) {
14 var a = '<html> © π " \'';
15 var b = '&#60;html&#62; &#169; &#960; &#34; &#39;';
16 t.equal(ent.encode(a), b);
17 t.equal(ent.decode(b), a);
18 t.end();
19});
20
21test('html named', function (t) {
22 var a = '<html> © π " \' ∴ Β β';
23 var b = '&lt;html&gt; &copy; &pi; &quot; &apos; &therefore; &Beta; &beta;';
24 t.equal(ent.encode(a, { named: true }), b);
25 t.equal(ent.decode(b), a);
26 t.end();
27});
28
29test('ambiguous ampersands', function (t) {
30 var a = '• &bullet';
31 var b = '&bullet; &bullet';
32 var c = '&bullet; &amp;bullet';
33 t.equal(ent.encode(a, { named: true }), c);
34 t.equal(ent.decode(b), a);
35 t.equal(ent.decode(c), a);
36 t.end();
37});
38
39test('entities', function (t) {
40 var a = '\u2124';
41 var b = '&#8484;';
42 t.equal(ent.encode(a), b);
43 t.equal(ent.decode(b), a);
44 t.end();
45});
46
47test('entities named', function (t) {
48 var a = '\u2124';
49 var b = '&Zopf;';
50 t.equal(ent.encode(a, { named: true }), b);
51 t.equal(ent.decode(b), a);
52 t.end();
53});
54
55test('num', function (t) {
56 var a = String.fromCharCode(1337);
57 var b = '&#1337;';
58 t.equal(ent.encode(a), b);
59 t.equal(ent.decode(b), a);
60
61 t.equal(ent.encode(a + a), b + b);
62 t.equal(ent.decode(b + b), a + a);
63 t.end();
64});
65
66test('astral num', function (t) {
67 var a = punycode.ucs2.encode([0x1d306]);
68 var b = '&#119558;';
69 t.equal(ent.encode(a), b);
70 t.equal(ent.decode(b), a);
71
72 t.equal(ent.encode(a + a), b + b);
73 t.equal(ent.decode(b + b), a + a);
74 t.end();
75});
76
77test('nested escapes', function (t) {
78 var a = '&amp;';
79 var b = '&#38;amp;';
80 t.equal(ent.encode(a), b);
81 t.equal(ent.decode(b), a);
82
83 t.equal(ent.encode(a + a), b + b);
84 t.equal(ent.decode(b + b), a + a);
85 t.end();
86});
87
88test('encode `special` option', function (t) {
89 var a = '<>\'"&';
90 var b = '&lt;&gt;\'"&amp;';
91 t.equal(ent.encode(a, {
92 named: true,
93 special: {
94 '<': true,
95 '>': true,
96 '&': true
97 }
98 }), b);
99
100 t.end();
101});
Note: See TracBrowser for help on using the repository browser.