1 | 'use strict';
|
2 |
|
3 |
|
4 | var test = require('tape');
|
5 |
|
6 | +function setup() {
|
7 |
|
8 | function createEditorElem(lang) {
|
9 | var elem = document.createElement('div')
|
10 | elem.setAttribute('id', lang + '-editor')
|
11 | elem.setAttribute('class', 'editor')
|
12 | document.body.appendChild(elem)
|
13 | }
|
14 |
|
15 | function loadStyle() {
|
16 | var css = require('./stringified/style');
|
17 | var head = document.getElementsByTagName('head')[0];
|
18 | var style = document.createElement('style');
|
19 |
|
20 | style.type = 'text/css';
|
21 |
|
22 | if (style.styleSheet){
|
23 | style.styleSheet.cssText = css;
|
24 | } else {
|
25 | style.appendChild(document.createTextNode(css));
|
26 | }
|
27 | head.appendChild(style);
|
28 | }
|
29 |
|
30 | ['javascript', 'coffee', 'json', 'lua', 'xml'].forEach(createEditorElem);
|
31 | loadStyle();
|
32 |
|
33 | require('./fixtures/javascript-editor');
|
34 | require('./fixtures/coffee-editor');
|
35 | require('./fixtures/json-editor');
|
36 | require('./fixtures/lua-editor');
|
37 | require('./fixtures/xml-editor');
|
38 | }()
|
39 |
|
40 | test('error annotations provided by inlined worker', function (t) {
|
41 | function getError(lang) {
|
42 | var editor = document.getElementById(lang + '-editor');
|
43 | var errors = editor.getElementsByClassName('ace_error')
|
44 | return { length: errors.length, line: errors[0] && errors[0].textContent }
|
45 | }
|
46 |
|
47 |
|
48 | var jsCount = 0
|
49 | , coffeeCount = 0
|
50 | , jsonCount = 0
|
51 | , luaCount = 0
|
52 | , xmlCount = 0;
|
53 |
|
54 | var max = 10;
|
55 |
|
56 | +function javascript() {
|
57 | var err = getError('javascript')
|
58 | if (!err.length && ++jsCount < max) return setTimeout(javascript, 1000)
|
59 |
|
60 | t.equal(err.length, 1, 'javascript editor shows one error')
|
61 | t.equal(err.line, '5', 'on line 5')
|
62 | }()
|
63 |
|
64 | +function coffee() {
|
65 | var err = getError('coffee')
|
66 | if (!err.length && ++coffeeCount < max) return setTimeout(coffee, 1000)
|
67 |
|
68 | t.equal(err.length, 1, 'coffee editor shows one error')
|
69 | t.equal(err.line, '5', 'on line 5')
|
70 | }()
|
71 |
|
72 | +function json() {
|
73 | var err = getError('json')
|
74 | if (!err.length && ++jsonCount < max) return setTimeout(json, 1000)
|
75 |
|
76 | t.equal(err.length, 1, 'json editor shows one error')
|
77 | t.equal(err.line, '5', 'on line 5')
|
78 | }()
|
79 |
|
80 | +function lua() {
|
81 | var err = getError('lua')
|
82 | if (!err.length && ++luaCount < max) return setTimeout(lua, 1000)
|
83 |
|
84 | t.equal(err.length, 1, 'lua editor shows one error')
|
85 | t.equal(err.line, '6', 'on line 6')
|
86 |
|
87 | t.end()
|
88 | }()
|
89 | +function xml() {
|
90 | var err = getError('xml')
|
91 | if (!err.length && ++xmlCount < max) return setTimeout(xml, 1000)
|
92 |
|
93 | t.equal(err.length, 1, 'xml editor shows one error')
|
94 | t.equal(err.line, '5', 'on line 5')
|
95 | }()
|
96 | })
|