-
-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathtest.js
49 lines (41 loc) · 1.78 KB
/
test.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
import test from 'ava';
import {htmlEscape, htmlUnescape} from './index.js';
test('htmlEscape', t => {
t.is(htmlEscape('&<>"\''), '&<>"'');
t.is(htmlEscape('🦄 & 🐐'), '🦄 & 🐐');
t.is(htmlEscape('Hello <em>World</em>'), 'Hello <em>World</em>');
});
test('htmlUnescape', t => {
t.is(htmlUnescape('&<>"''), '&<>"\'');
t.is(htmlUnescape('🦄 & 🐐'), '🦄 & 🐐');
t.is(htmlUnescape('Hello <em>World</em>'), 'Hello <em>World</em>');
});
test('htmlEscape & htmlUnescape', t => {
t.is(htmlUnescape(htmlEscape('&<>"\'')), '&<>"\'');
t.is(htmlUnescape(htmlEscape('"')), '"');
});
test('htmlEscape as template tag', t => {
t.is(htmlEscape`foobarz${'&<>"\''}`, 'foobarz&<>"'');
t.is(htmlEscape`🦄 ${'&'} 🐐`, '🦄 & 🐐');
t.is(htmlEscape`Hello <em><>${'<>'}</em>`, 'Hello <em><><></em>');
});
test('htmlEscape as template tag with non-strings', t => {
t.is(htmlEscape`foobarz${undefined}`, 'foobarzundefined');
t.is(htmlEscape`🦄 ${true}`, '🦄 true');
t.is(htmlEscape`Hello <em><>${1}</em>`, 'Hello <em><>1</em>');
});
test('htmlUnescape as template tag', t => {
t.is(htmlUnescape`foobarz${'&<>"''}`, 'foobarz&<>"\'');
t.is(htmlUnescape`🦄 ${'&'} 🐐`, '🦄 & 🐐');
t.is(htmlUnescape`Hello <em><>${'<>'}</em>`, 'Hello <em><><></em>');
});
test('htmlUnescape as template tag on non-strings', t => {
t.is(htmlUnescape`foobarz${undefined}`, 'foobarzundefined');
t.is(htmlUnescape`🦄 ${true}`, '🦄 true');
t.is(htmlUnescape`Hello <em><>${1}</em>`, 'Hello <em><>1</em>');
});
test('htmlEscape & htmlUnescape as template tags', t => {
const input = '&<>"\'';
const actual = htmlUnescape`${htmlEscape`${input}`}`;
t.is(actual, input);
});