convert missing unit tests

This commit is contained in:
Fabian Jakobs 2010-12-15 20:01:09 +01:00
commit 36595bd9d6
10 changed files with 191 additions and 153 deletions

View file

@ -35,39 +35,39 @@
*
* ***** END LICENSE BLOCK ***** */
define(function(require, exports, module) {
require("../../../../support/paths");
var Document = require("ace/document").Document;
var Tokenizer = require("ace/tokenizer").Tokenizer;
var JavaScript = require("ace/mode/javascript").Mode;
var JavaScriptMode = require("ace/mode/javascript").Mode;
var assert = require("../assertions");
var JavaScriptTest = new TestCase("mode.JavaScriptTest", {
setUp : function() {
var Test = {
setUp : function() {
this.mode = new JavaScriptMode();
},
"test: getTokenizer() (smoke test)" : function() {
var tokenizer = this.mode.getTokenizer();
assertTrue(tokenizer instanceof Tokenizer);
assert.ok(tokenizer instanceof Tokenizer);
var tokens = tokenizer.getLineTokens("'juhu'", "start").tokens;
assertEquals("string", tokens[0].type);
assert.equal("string", tokens[0].type);
},
"test: toggle comment lines should prepend '//' to each line" : function() {
var doc = new Document([" abc", "cde", "fg"]);
var comment = this.mode.toggleCommentLines("start", doc, 0, 1);
assertEquals(["// abc", "//cde", "fg"].join("\n"), doc.toString());
assert.equal(["// abc", "//cde", "fg"].join("\n"), doc.toString());
},
"test: toggle comment on commented lines should remove leading '//' chars" : function() {
var doc = new Document(["// abc", "//cde", "fg"]);
var comment = this.mode.toggleCommentLines("start", doc, 0, 1);
assertEquals([" abc", "cde", "fg"].join("\n"), doc.toString());
assert.equal([" abc", "cde", "fg"].join("\n"), doc.toString());
},
"test: toggle comment lines twice should return the original text" : function() {
@ -75,74 +75,76 @@ var JavaScriptTest = new TestCase("mode.JavaScriptTest", {
this.mode.toggleCommentLines("start", doc, 0, 2);
this.mode.toggleCommentLines("start", doc, 0, 2);
assertEquals([" abc", "cde", "fg"].join("\n"), doc.toString());
assert.equal([" abc", "cde", "fg"].join("\n"), doc.toString());
},
"test: toggle comment on multiple lines with one commented line prepend '//' to each line" : function() {
var doc = new Document(["// abc", "//cde", "fg"]);
var comment = this.mode.toggleCommentLines("start", doc, 0, 2);
assertEquals(["//// abc", "////cde", "//fg"].join("\n"), doc.toString());
assert.equal(["//// abc", "////cde", "//fg"].join("\n"), doc.toString());
},
"test: toggle comment on a comment line with leading white space": function() {
var doc = new Document(["//cde", " //fg"]);
var comment = this.mode.toggleCommentLines("start", doc, 0, 1);
assertEquals(["cde", " fg"].join("\n"), doc.toString());
assert.equal(["cde", " fg"].join("\n"), doc.toString());
},
"test: auto indent after opening brace" : function() {
assertEquals(" ", this.mode.getNextLineIndent("start", "if () {", " "));
assert.equal(" ", this.mode.getNextLineIndent("start", "if () {", " "));
},
"test: no auto indent after opening brace in multi line comment" : function() {
assertEquals("", this.mode.getNextLineIndent("start", "/*if () {", " "));
assertEquals(" ", this.mode.getNextLineIndent("comment", " abcd", " "));
assert.equal("", this.mode.getNextLineIndent("start", "/*if () {", " "));
assert.equal(" ", this.mode.getNextLineIndent("comment", " abcd", " "));
},
"test: no auto indent after opening brace in single line comment" : function() {
assertEquals("", this.mode.getNextLineIndent("start", "//if () {", " "));
assertEquals(" ", this.mode.getNextLineIndent("start", " //if () {", " "));
assert.equal("", this.mode.getNextLineIndent("start", "//if () {", " "));
assert.equal(" ", this.mode.getNextLineIndent("start", " //if () {", " "));
},
"test: no auto indent should add to existing indent" : function() {
assertEquals(" ", this.mode.getNextLineIndent("start", " if () {", " "));
assertEquals(" ", this.mode.getNextLineIndent("start", " cde", " "));
assert.equal(" ", this.mode.getNextLineIndent("start", " if () {", " "));
assert.equal(" ", this.mode.getNextLineIndent("start", " cde", " "));
},
"test: special indent in doc comments" : function() {
assertEquals(" * ", this.mode.getNextLineIndent("doc-start", "/**", " "));
assertEquals(" * ", this.mode.getNextLineIndent("doc-start", " /**", " "));
assertEquals(" * ", this.mode.getNextLineIndent("doc-start", " *", " "));
assertEquals(" * ", this.mode.getNextLineIndent("doc-start", " *", " "));
assertEquals(" ", this.mode.getNextLineIndent("doc-start", " abc", " "));
assert.equal(" * ", this.mode.getNextLineIndent("doc-start", "/**", " "));
assert.equal(" * ", this.mode.getNextLineIndent("doc-start", " /**", " "));
assert.equal(" * ", this.mode.getNextLineIndent("doc-start", " *", " "));
assert.equal(" * ", this.mode.getNextLineIndent("doc-start", " *", " "));
assert.equal(" ", this.mode.getNextLineIndent("doc-start", " abc", " "));
},
"test: no indent after doc comments" : function() {
assertEquals("", this.mode.getNextLineIndent("doc-start", " */", " "));
assert.equal("", this.mode.getNextLineIndent("doc-start", " */", " "));
},
"test: trigger outdent if line is space and new text starts with closing brace" : function() {
assertTrue(this.mode.checkOutdent("start", " ", " }"));
assertFalse(this.mode.checkOutdent("start", " a ", " }"));
assertFalse(this.mode.checkOutdent("start", "", "}"));
assertFalse(this.mode.checkOutdent("start", " ", "a }"));
assertFalse(this.mode.checkOutdent("start", " }", "}"));
assert.ok(this.mode.checkOutdent("start", " ", " }"));
assert.equal(this.mode.checkOutdent("start", " a ", " }"));
assert.equal(this.mode.checkOutdent("start", "", "}"));
assert.equal(this.mode.checkOutdent("start", " ", "a }"));
assert.equal(this.mode.checkOutdent("start", " }", "}"));
},
"test: auto outdent should indent the line with the same indent as the line with the matching opening brace" : function() {
var doc = new Document([" function foo() {", " bla", " }"]);
this.mode.autoOutdent("start", doc, 2);
assertEquals(" }", doc.getLine(2));
assert.equal(" }", doc.getLine(2));
},
"test: no auto outdent if no matching brace is found" : function() {
var doc = new Document([" function foo()", " bla", " }"]);
this.mode.autoOutdent("start", doc, 2);
assertEquals(" }", doc.getLine(2));
assert.equal(" }", doc.getLine(2));
}
};
});
module.exports = require("async/test").testcase(Test);
});
if (module === require.main)
module.exports.exec()