This repository has been archived by the owner on Nov 8, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
test.js
76 lines (61 loc) · 2.1 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
const assert = require('assert');
const assign = require('object-assign');
const loader = require('./');
const webpackContext = {
cacheable: noop,
exec: noop
};
const highlight = loader.bind(webpackContext);
describe('highlight-loader', function () {
it('should highlight code', function () {
const code = '<code>run <script></code>';
const given = highlight(code);
const expected = '<code>run <script></code>';
assert.equal(given, expected);
});
it('should highlight pre/code', function () {
const code = '<pre><code class="lang-javascript">var a = 4;\n' +
'console.log(a + 5);\n</code></pre>';
const given = highlight(code);
const expected = '<pre class="hljs"><span class="hljs-keyword">var</span> a = <span class="hljs-number">4</span>;\n' +
'<span class="hljs-built_in">console</span>.log(a + <span class="hljs-number">5</span>);\n' +
'</pre>';
assert.equal(given, expected);
});
it('should not fail with empty input', function () {
const given = highlight();
const expected = '';
assert.equal(given, expected);
});
it('should support raw output', function () {
const code = 'demo';
const given = loader.call(assign({}, webpackContext, {
query: '?raw=true'
}), code);
const expected = 'module.exports = "<span class=\\"hljs-attribute\\">demo</span>"';
assert.equal(given, expected);
});
it('should support raw output with lang', function () {
const code = 'a = 4';
const given = loader.call(assign({}, webpackContext, {
query: '?raw=true&lang=python'
}), code);
const expected = 'module.exports = "a = <span class=\\"hljs-number\\">4</span>"';
assert.equal(given, expected);
});
it('should support exec', function () {
var executed = false;
const code = 'demo';
const given = loader.call(assign({}, webpackContext, {
exec: function(input) {
executed = true;
return input;
},
query: '?exec=true'
}), code);
const expected = 'demo';
assert.equal(executed, true);
assert.equal(given, expected);
});
});
function noop() {}