forked from codemirror/CodeMirror-v1
-
Notifications
You must be signed in to change notification settings - Fork 1
/
unittests.js
44 lines (40 loc) · 1.59 KB
/
unittests.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
/**
* Test Harness for CodeMirror
* JS-unit compatible tests here. The two available assertions are
* assertEquals (strict equality) and assertEquivalent (looser equivalency).
*
* 'editor' is a global object for the CodeMirror editor shared between all
* tests. After manipulating it in each test, try to restore it to
* approximately its original state.
*/
function testSetGet() {
var code = 'It was the best of times.\nIt was the worst of times.';
editor.setCode(code);
assertEquals(code, editor.getCode());
editor.setCode('');
assertEquals('', editor.getCode());
}
function testSetStylesheet() {
function cssStatus() {
// Returns a list of tuples, for each CSS link return the filename and
// whether it is enabled.
links = editor.win.document.getElementsByTagName('link');
css = [];
for (var x = 0, link; link = links[x]; x++) {
if (link.rel.indexOf("stylesheet") !== -1) {
css.push([link.href.substring(link.href.lastIndexOf('/') + 1),
!link.disabled])
}
}
return css;
}
assertEquivalent([], cssStatus());
editor.setStylesheet('css/jscolors.css');
assertEquivalent([['jscolors.css', true]], cssStatus());
editor.setStylesheet(['css/csscolors.css', 'css/xmlcolors.css']);
assertEquivalent([['jscolors.css', false], ['csscolors.css', true], ['xmlcolors.css', true]], cssStatus());
editor.setStylesheet([]);
assertEquivalent([['jscolors.css', false], ['csscolors.css', false], ['xmlcolors.css', false]], cssStatus());
}
// Update this list of tests as new ones are added.
var tests = ['testSetGet', 'testSetStylesheet'];