From 97c24a776949ff8fe740c0b1c1b6f29332b44749 Mon Sep 17 00:00:00 2001 From: Fabian Jakobs Date: Thu, 16 Dec 2010 10:56:33 +0100 Subject: [PATCH] all tests are working now --- lib/ace/mode/javascript_highlight_rules.js | 188 +++++++++--------- lib/ace/test/mode/css_tokenizer_test.js | 9 +- lib/ace/test/mode/html_tokenizer_test.js | 2 +- lib/ace/test/mode/javascript_test.js | 8 +- .../test/mode/javascript_tokenizer_test.js | 7 + 5 files changed, 118 insertions(+), 96 deletions(-) diff --git a/lib/ace/mode/javascript_highlight_rules.js b/lib/ace/mode/javascript_highlight_rules.js index 6d6afa2b..d69108c0 100644 --- a/lib/ace/mode/javascript_highlight_rules.js +++ b/lib/ace/mode/javascript_highlight_rules.js @@ -64,96 +64,104 @@ JavaScriptHighlightRules = function() { // regexps are ordered -> the first match is used this.$rules = { - "start" : [ { - token : "comment", - regex : "\\/\\/.*$" - }, - docComment.getStartRule("doc-start"), - { - token : "comment", // multi line comment - regex : "\\/\\*", - next : "comment" - }, { - token : "string.regexp", - regex : "[/](?:(?:\\[(?:\\\\]|[^\\]])+\\])|(?:\\\\/|[^\\]/]))*[/][gimy]*\\s*(?=[).,;]|$)" - }, { - token : "string", // single line - regex : '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]' - }, { - token : "string", // multi line string start - regex : '["].*\\\\$', - next : "qqstring" - }, { - token : "string", // single line - regex : "['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']" - }, { - token : "string", // multi line string start - regex : "['].*\\\\$", - next : "qstring" - }, { - token : "constant.numeric", // hex - regex : "0[xX][0-9a-fA-F]+\\b" - }, { - token : "constant.numeric", // float - regex : "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b" - }, { - token : "constant.boolean", // float - regex : "(?:true|false)\\b" - }, { - token : function(value) { - if (value == "this") - return "variable.language"; - else if (keywords[value]) - return "keyword"; - else if (buildinConstants[value]) - return "constant.language"; - else if (futureReserved[value]) - return "invalid.illegal"; - else if (value == "debugger") - return "invalid.deprecated"; - else - return "identifier"; - }, - // TODO: Unicode escape sequences - // TODO: Unicode identifiers - regex : "[a-zA-Z_$][a-zA-Z0-9_$]*\\b" - }, { - token : "keyword.operator", - regex : "!|\\$|%|&|\\*|\\-\\-|\\-|\\+\\+|\\+|~|===|==|=|!=|!==|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\\|\\||\\?\\:|\\*=|%=|\\+=|\\-=|&=|\\^=|\\b(?:in|instanceof|new|delete|typeof|void)" - }, { - token : "lparen", - regex : "[[({]" - }, { - token : "rparen", - regex : "[\\])}]" - }, { - token : "text", - regex : "\\s+" - } ], - "comment" : [ { - token : "comment", // closing comment - regex : ".*?\\*\\/", - next : "start" - }, { - token : "comment", // comment spanning whole line - regex : ".+" - } ], - "qqstring" : [ { - token : "string", - regex : '(?:(?:\\\\.)|(?:[^"\\\\]))*?"', - next : "start" - }, { - token : "string", - regex : '.+' - } ], - "qstring" : [ { - token : "string", - regex : "(?:(?:\\\\.)|(?:[^'\\\\]))*?'", - next : "start" - }, { - token : "string", - regex : '.+' - } ] + "start" : [ + { + token : "comment", + regex : "\\/\\/.*$" + }, + docComment.getStartRule("doc-start"), + { + token : "comment", // multi line comment + regex : "\\/\\*", + next : "comment" + }, { + token : "string.regexp", + regex : "[/](?:(?:\\[(?:\\\\]|[^\\]])+\\])|(?:\\\\/|[^\\]/]))*[/][gimy]*\\s*(?=[).,;]|$)" + }, { + token : "string", // single line + regex : '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]' + }, { + token : "string", // multi line string start + regex : '["].*\\\\$', + next : "qqstring" + }, { + token : "string", // single line + regex : "['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']" + }, { + token : "string", // multi line string start + regex : "['].*\\\\$", + next : "qstring" + }, { + token : "constant.numeric", // hex + regex : "0[xX][0-9a-fA-F]+\\b" + }, { + token : "constant.numeric", // float + regex : "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b" + }, { + token : "constant.boolean", // float + regex : "(?:true|false)\\b" + }, { + token : function(value) { + if (value == "this") + return "variable.language"; + else if (keywords[value]) + return "keyword"; + else if (buildinConstants[value]) + return "constant.language"; + else if (futureReserved[value]) + return "invalid.illegal"; + else if (value == "debugger") + return "invalid.deprecated"; + else + return "identifier"; + }, + // TODO: Unicode escape sequences + // TODO: Unicode identifiers + regex : "[a-zA-Z_$][a-zA-Z0-9_$]*\\b" + }, { + token : "keyword.operator", + regex : "!|\\$|%|&|\\*|\\-\\-|\\-|\\+\\+|\\+|~|===|==|=|!=|!==|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\\|\\||\\?\\:|\\*=|%=|\\+=|\\-=|&=|\\^=|\\b(?:in|instanceof|new|delete|typeof|void)" + }, { + token : "lparen", + regex : "[[({]" + }, { + token : "rparen", + regex : "[\\])}]" + }, { + token : "text", + regex : "\\s+" + } + ], + "comment" : [ + { + token : "comment", // closing comment + regex : ".*?\\*\\/", + next : "start" + }, { + token : "comment", // comment spanning whole line + regex : ".+" + } + ], + "qqstring" : [ + { + token : "string", + regex : '(?:(?:\\\\.)|(?:[^"\\\\]))*?"', + next : "start" + }, { + token : "string", + regex : '.+' + } + ], + "qstring" : [ + { + token : "string", + regex : "(?:(?:\\\\.)|(?:[^'\\\\]))*?'", + next : "start" + }, { + token : "string", + regex : '.+' + } + ] }; this.addRules(docComment.getRules(), "doc-"); diff --git a/lib/ace/test/mode/css_tokenizer_test.js b/lib/ace/test/mode/css_tokenizer_test.js index 84f63f6f..96f71159 100644 --- a/lib/ace/test/mode/css_tokenizer_test.js +++ b/lib/ace/test/mode/css_tokenizer_test.js @@ -74,10 +74,17 @@ var Test = { assert.equal("lparen", tokens[0].type); assert.equal("text", tokens[1].type); assert.equal("rparen", tokens[2].type); + }, + + "test for last rule in ruleset to catch capturing group bugs" : function() { + var tokens = this.tokenizer.getLineTokens("top", "start").tokens; + + assert.equal(1, tokens.length); + assert.equal("support.type", tokens[0].type); } }; -module.exports = require("async/test").testcase(Test); +module.exports = require("async/test").testcase(Test, "css tokenizer"); if (module === require.main) module.exports.exec() \ No newline at end of file diff --git a/lib/ace/test/mode/html_tokenizer_test.js b/lib/ace/test/mode/html_tokenizer_test.js index da82074b..2aebe38e 100644 --- a/lib/ace/test/mode/html_tokenizer_test.js +++ b/lib/ace/test/mode/html_tokenizer_test.js @@ -62,7 +62,7 @@ var Test = { assert.equal("text", tokens[8].type); assert.equal("keyword", tokens[9].type); assert.equal("text", tokens[10].type); - } + } }; module.exports = require("async/test").testcase(Test); diff --git a/lib/ace/test/mode/javascript_test.js b/lib/ace/test/mode/javascript_test.js index 20a75d14..75844151 100644 --- a/lib/ace/test/mode/javascript_test.js +++ b/lib/ace/test/mode/javascript_test.js @@ -125,10 +125,10 @@ var Test = { "test: trigger outdent if line is space and new text starts with closing brace" : function() { 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", " }", "}")); + assert.ok(!this.mode.checkOutdent("start", " a ", " }")); + assert.ok(!this.mode.checkOutdent("start", "", "}")); + assert.ok(!this.mode.checkOutdent("start", " ", "a }")); + assert.ok(!this.mode.checkOutdent("start", " }", "}")); }, "test: auto outdent should indent the line with the same indent as the line with the matching opening brace" : function() { diff --git a/lib/ace/test/mode/javascript_tokenizer_test.js b/lib/ace/test/mode/javascript_tokenizer_test.js index e292574b..404f1a0f 100644 --- a/lib/ace/test/mode/javascript_tokenizer_test.js +++ b/lib/ace/test/mode/javascript_tokenizer_test.js @@ -91,6 +91,13 @@ var Test = { assert.equal("lparen", tokens[0].type); assert.equal("text", tokens[1].type); assert.equal("rparen", tokens[2].type); + }, + + "test for last rule in ruleset to catch capturing group bugs" : function() { + var tokens = this.tokenizer.getLineTokens("}", "start").tokens; + + assert.equal(1, tokens.length); + assert.equal("rparen", tokens[0].type); } };