-
-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathhtml.test.js
66 lines (64 loc) · 2.89 KB
/
html.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
process.mixin(GLOBAL, require('./test').dsl);
process.mixin(GLOBAL, require('./html'));
testcase('tests for linebreaks()')
test('should break lines into <p> and <br /> tags', function () {
var input = 'This is a \'nice\'\n'
+ 'way to spend the summer!\n'
+ '\n'
+ 'The days are just packed!\n';
var expected = '<p>This is a \'nice\'<br />'
+ 'way to spend the summer!</p>\n'
+ '\n'
+ '<p>The days are just packed!<br /></p>';
var expected_escaped = '<p>This is a 'nice'<br />'
+ 'way to spend the summer!</p>\n'
+ '\n'
+ '<p>The days are just packed!<br /></p>';
assertEquals(expected, linebreaks(input));
assertEquals(expected_escaped, linebreaks(input, { escape: true }));
})
testcase('truncate_html_words');
test('should truncate strings without tags', function () {
assertEquals('Joel is ...', truncate_html_words('Joel is a slug', 2));
});
test('should close tags on truncate', function () {
assertEquals('<p>Joel is ...</p>', truncate_html_words('<p>Joel is a slug</p>', 2));
});
testcase('urlize')
test('should urlize urls in text', function () {
assertEquals(
'Check out <a href="http://www.djangoproject.com">www.djangoproject.com</a>',
urlize('Check out www.djangoproject.com')
);
assertEquals(
'Check out (<a href="http://www.djangoproject.com">www.djangoproject.com</a>)',
urlize('Check out (www.djangoproject.com)')
);
assertEquals(
'Skriv til <a href="mailto:[email protected]">[email protected]</a>',
urlize('Skriv til [email protected]')
);
assertEquals(
'Check out (<a href="http://www.djangoproject.com">www.djangoproject.com</a>)\n' +
'Skriv til <a href="mailto:[email protected]">[email protected]</a>',
urlize('Check out (www.djangoproject.com)\nSkriv til [email protected]')
);
assertEquals(
'Check out <a href="http://www.djangoproject.com">www.djangopr...</a>',
urlize('Check out www.djangoproject.com', {limit: 15})
);
assertEquals(
'Se her: (<a href="http://www.dr.dk">www.dr.dk</a> & ' +
'<a href="http://www.djangoproject.com">http://www.djangoproject.com</a>)',
urlize('Se her: (www.dr.dk & http://www.djangoproject.com)', { escape: true })
);
assertEquals(
'Se her: <a href="http://www.dr.dk?hest=4&test=tolv">www.dr.dk?hest=4&test=tolv</a>.',
urlize('Se her: www.dr.dk?hest=4&test=tolv.', { escape: true })
);
assertEquals(
'Check out (<a href="http://www.djangoproject.com" rel="nofollow">www.djangoproject.com</a>)',
urlize('Check out (www.djangoproject.com)', { nofollow: true })
);
});
run();