This repository has been archived by the owner on Apr 6, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
/
language_test.js
148 lines (128 loc) · 5.99 KB
/
language_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
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
/*global describe it before after beforeEach onload*/
"use client";
require(["plugins/c9.ide.language/test_base"], function(base) {
base.setup(function(err, imports, helpers) {
if (err) throw err;
var language = imports.language;
var chai = require("lib/chai/chai");
var expect = chai.expect;
var assert = require("assert");
var tabs = imports.tabManager;
var complete = imports["language.complete"];
describe("analysis", function() {
var jsTab;
var jsSession;
// Setup
beforeEach(function(done) {
tabs.getTabs().forEach(function(tab) {
tab.close(true);
});
// tab.close() isn't quite synchronous, wait for it :(
setTimeout(function() {
tabs.openFile("/language.js", function(err, tab) {
if (err) return done(err);
jsTab = tab;
jsSession = jsTab.document.getSession().session;
expect(jsSession).to.not.equal(null);
setTimeout(function() {
complete.closeCompletionBox();
done();
});
});
}, 0);
});
it("has three markers initially", function(done) {
jsSession.on("changeAnnotation", function onAnnos() {
if (!jsSession.getAnnotations().length)
return;
if (jsSession.getAnnotations().length !== 3)
return; // for this test, it's fine as long as it's eventually 3
jsSession.off("changeAnnotation", onAnnos);
expect(jsSession.getAnnotations()).to.have.length(3);
done();
});
});
it('parses jsx', function(done) {
jsSession.setValue("x = <a/>;");
jsSession.on("changeAnnotation", function onAnnos() {
var annos = jsSession.getAnnotations();
if (!annos.length)
return;
if (annos.some(function(a) { // annotations for previous file
return a.text.match(/language.*never used/);
}))
return;
jsSession.off("changeAnnotation", onAnnos);
expect(annos).to.have.length(1);
expect(annos[0].text).contain("x is not defined");
done();
});
});
it("supports linting basic es6", function(done) {
tabs.openFile("/test_es6.js", function(err, _tab) {
if (err) return done(err);
var tab = _tab;
tabs.focusTab(tab);
var session = tab.document.getSession().session;
session.on("changeAnnotation", testAnnos);
testAnnos();
function testAnnos() {
var annos = session.getAnnotations();
if (!annos.length)
return;
session.off("changeAnnotation", testAnnos);
assert(annos.length === 1);
assert(annos[0].text.match(/param2.*defined/));
done();
}
});
});
it("supports warnings for Cloud9's plugin unload event", function(done) {
tabs.openFile("/plugins/c9.dummy/architect_test_dummy.js", function(err, _tab) {
if (err) return done(err);
var tab = _tab;
tabs.focusTab(tab);
var session = tab.document.getSession().session;
session.on("changeAnnotation", testAnnos);
testAnnos();
function testAnnos() {
var annos = session.getAnnotations();
if (!annos.length)
return;
annos.sort(function(a, b) {return a.row - b.row;});
session.off("changeAnnotation", testAnnos);
var foundBar;
var foundLoaded;
annos.forEach(function(anno) {
if (anno.text.match(/bar.*unload/))
foundBar = true;
if (anno.text.match(/loaded.*unload/))
foundLoaded = true;
});
assert(foundBar && foundLoaded);
done();
}
});
});
it("supports linting python", function(done) {
tabs.openFile("/python/test_user.py", function(err, _tab) {
if (err) return done(err);
var tab = _tab;
tabs.focusTab(tab);
var session = tab.document.getSession().session;
session.on("changeAnnotation", testAnnos);
testAnnos();
function testAnnos() {
var annos = session.getAnnotations();
if (!annos.length)
return;
session.off("changeAnnotation", testAnnos);
assert(annos.length === 1);
assert(annos[0].text.match(/bad_call/));
done();
}
});
});
});
});
});