UNPKG

1.51 kBJavaScriptView Raw
1var assert = require('assert'),
2 cleaner = require('./index.js');
3
4// test that text is unchanged
5assert.equal(cleaner.clean('Foo Bar'), 'Foo Bar');
6
7// test that extra whitespace is removed
8assert.equal(cleaner.clean('Foo Bar'), 'Foo Bar');
9assert.equal(cleaner.clean('Foo\nBar'), 'Foo Bar');
10
11// test that uppercase tags and attributes are lowercased
12assert.equal(cleaner.clean('<FOO BAR="QUX">Bam</FOO>'), '<foo bar="qux">Bam</foo>');
13
14// test that deprecated tags are removed
15assert.equal(cleaner.clean('foo <font="arial">bar</font>'), 'foo bar');
16
17// test that trailing slash is removed from empty element tag
18assert.equal(cleaner.clean('<br />'), '<br>');
19assert.equal(cleaner.clean('<hr/>'), '<hr>');
20
21// test that legacy attributes are removed
22assert.equal(cleaner.clean('<foo color="red">'), '<foo>');
23
24// test that comments are removed
25assert.equal(cleaner.clean('foo<!-- bar -->', {'remove-comments': true}), 'foo');
26
27// test that line breaks are added before and after block element tags
28assert.equal(cleaner.clean('foo<div></div>foo', {'pretty': true}), 'foo\n<div>\n</div>\nfoo');
29
30// test that line break is added after br element tag
31assert.equal(cleaner.clean('foo<br>foo', {'pretty': true}), 'foo<br>\nfoo');
32
33// test that nested tags are indented after block element tags
34assert.equal(cleaner.clean('<div>\nbar</div>', {'pretty': true}), '<div>\n bar\n</div>');
35
36// test that output is trimmed
37assert.equal(cleaner.clean(' Foo\n'), 'Foo');
38
39process.stdout.write('all tests passed\n');