-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathprism-element.html
More file actions
163 lines (130 loc) · 4.83 KB
/
prism-element.html
File metadata and controls
163 lines (130 loc) · 4.83 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
<!doctype html>
<!--
@license
Copyright (c) 2016 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->
<html>
<head>
<meta charset="UTF-8">
<title>prism-element basic tests</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
<script src="../../../@webcomponents/webcomponentsjs/webcomponents-lite.js"></script>
<script src="../../../wct-browser-legacy/browser.js"></script>
<script type="module" src="../../test-fixture/test-fixture.js"></script>
<script type="module" src="../prism-highlighter.js"></script>
<script type="module" src="./simple-container.js"></script>
</head>
<body>
<test-fixture id="simple">
<template>
<simple-container>
<prism-highlighter></prism-highlighter>
</simple-container>
</template>
</test-fixture>
<test-fixture id="double-highlight">
<template>
<simple-container id="container-0">
<prism-highlighter></prism-highlighter>
<simple-container id="container-1">
<prism-highlighter></prism-highlighter>
</simple-container>
</simple-container>
</template>
</test-fixture>
<script type="module">
import '../prism-highlighter.js';
import './simple-container.js';
suite('<prism-highlighter>', function() {
var el;
setup(function() {
sinon.spy(Prism, 'highlight');
el = fixture('simple');
});
teardown(function() {
Prism.highlight.restore();
});
test('highlights on syntax-highlight event', function() {
var ev = {
code: '<foo>',
lang: 'markup'
};
el.dispatchEvent(new CustomEvent('syntax-highlight', {detail: ev}));
expect(Prism.highlight.calledWithExactly('<foo>', Prism.languages.markup))
.to.equal(true);
});
test('warns on invalid syntax-highlight event', function() {
var ev;
sinon.spy(console, 'warn');
el.dispatchEvent(new CustomEvent('syntax-highlight'));
expect(console.warn.callCount).to.equal(1);
ev = {
};
el.dispatchEvent(new CustomEvent('syntax-highlight', {detail: ev}));
expect(console.warn.callCount).to.equal(2);
expect(ev.code).to.equal(undefined);
});
test('ignores repeated highlights', function() {
var ev = {
code: '<foo>'
};
el = fixture('double-highlight');
el.querySelector('#container-1').dispatchEvent(new CustomEvent('syntax-highlight', {detail: ev}));
expect(Prism.highlight.callCount).to.equal(1);
});
suite('applies simple lang detection if none specified', function() {
test('detects as markup if begins with tag', function() {
var ev = {
code: '<foo>'
};
el.dispatchEvent(new CustomEvent('syntax-highlight', {detail: ev}));
expect(Prism.highlight.calledWithExactly('<foo>', Prism.languages.markup))
.to.equal(true);
});
test('detects as javascript if no tag at start', function() {
var ev = {
code: 'return;'
};
el.dispatchEvent(new CustomEvent('syntax-highlight', {detail: ev}));
expect(Prism.highlight.calledWithExactly('return;', Prism.languages.javascript))
.to.equal(true);
});
});
suite('detects language for abbreviated lang', function() {
test('detects js as javascript', function() {
var ev = {
code: 'return;',
lang: 'js'
};
el.dispatchEvent(new CustomEvent('syntax-highlight', {detail: ev}));
expect(Prism.highlight.calledWithExactly('return;', Prism.languages.javascript))
.to.equal(true);
});
test('detects es as javascript', function() {
var ev = {
code: 'return;',
lang: 'es'
};
el.dispatchEvent(new CustomEvent('syntax-highlight', {detail: ev}));
expect(Prism.highlight.calledWithExactly('return;', Prism.languages.javascript))
.to.equal(true);
});
test('detects c as clike', function() {
var ev = {
code: 'return;',
lang: 'c'
};
el.dispatchEvent(new CustomEvent('syntax-highlight', {detail: ev}));
expect(Prism.highlight.calledWithExactly('return;', Prism.languages.clike))
.to.equal(true);
});
});
});
</script>
</body>
</html>