all tests are working now
This commit is contained in:
parent
fa4d88830c
commit
97c24a7769
5 changed files with 118 additions and 96 deletions
|
|
@ -64,96 +64,104 @@ JavaScriptHighlightRules = function() {
|
||||||
// regexps are ordered -> the first match is used
|
// regexps are ordered -> the first match is used
|
||||||
|
|
||||||
this.$rules = {
|
this.$rules = {
|
||||||
"start" : [ {
|
"start" : [
|
||||||
token : "comment",
|
{
|
||||||
regex : "\\/\\/.*$"
|
token : "comment",
|
||||||
},
|
regex : "\\/\\/.*$"
|
||||||
docComment.getStartRule("doc-start"),
|
},
|
||||||
{
|
docComment.getStartRule("doc-start"),
|
||||||
token : "comment", // multi line comment
|
{
|
||||||
regex : "\\/\\*",
|
token : "comment", // multi line comment
|
||||||
next : "comment"
|
regex : "\\/\\*",
|
||||||
}, {
|
next : "comment"
|
||||||
token : "string.regexp",
|
}, {
|
||||||
regex : "[/](?:(?:\\[(?:\\\\]|[^\\]])+\\])|(?:\\\\/|[^\\]/]))*[/][gimy]*\\s*(?=[).,;]|$)"
|
token : "string.regexp",
|
||||||
}, {
|
regex : "[/](?:(?:\\[(?:\\\\]|[^\\]])+\\])|(?:\\\\/|[^\\]/]))*[/][gimy]*\\s*(?=[).,;]|$)"
|
||||||
token : "string", // single line
|
}, {
|
||||||
regex : '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]'
|
token : "string", // single line
|
||||||
}, {
|
regex : '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]'
|
||||||
token : "string", // multi line string start
|
}, {
|
||||||
regex : '["].*\\\\$',
|
token : "string", // multi line string start
|
||||||
next : "qqstring"
|
regex : '["].*\\\\$',
|
||||||
}, {
|
next : "qqstring"
|
||||||
token : "string", // single line
|
}, {
|
||||||
regex : "['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']"
|
token : "string", // single line
|
||||||
}, {
|
regex : "['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']"
|
||||||
token : "string", // multi line string start
|
}, {
|
||||||
regex : "['].*\\\\$",
|
token : "string", // multi line string start
|
||||||
next : "qstring"
|
regex : "['].*\\\\$",
|
||||||
}, {
|
next : "qstring"
|
||||||
token : "constant.numeric", // hex
|
}, {
|
||||||
regex : "0[xX][0-9a-fA-F]+\\b"
|
token : "constant.numeric", // hex
|
||||||
}, {
|
regex : "0[xX][0-9a-fA-F]+\\b"
|
||||||
token : "constant.numeric", // float
|
}, {
|
||||||
regex : "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b"
|
token : "constant.numeric", // float
|
||||||
}, {
|
regex : "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b"
|
||||||
token : "constant.boolean", // float
|
}, {
|
||||||
regex : "(?:true|false)\\b"
|
token : "constant.boolean", // float
|
||||||
}, {
|
regex : "(?:true|false)\\b"
|
||||||
token : function(value) {
|
}, {
|
||||||
if (value == "this")
|
token : function(value) {
|
||||||
return "variable.language";
|
if (value == "this")
|
||||||
else if (keywords[value])
|
return "variable.language";
|
||||||
return "keyword";
|
else if (keywords[value])
|
||||||
else if (buildinConstants[value])
|
return "keyword";
|
||||||
return "constant.language";
|
else if (buildinConstants[value])
|
||||||
else if (futureReserved[value])
|
return "constant.language";
|
||||||
return "invalid.illegal";
|
else if (futureReserved[value])
|
||||||
else if (value == "debugger")
|
return "invalid.illegal";
|
||||||
return "invalid.deprecated";
|
else if (value == "debugger")
|
||||||
else
|
return "invalid.deprecated";
|
||||||
return "identifier";
|
else
|
||||||
},
|
return "identifier";
|
||||||
// TODO: Unicode escape sequences
|
},
|
||||||
// TODO: Unicode identifiers
|
// TODO: Unicode escape sequences
|
||||||
regex : "[a-zA-Z_$][a-zA-Z0-9_$]*\\b"
|
// TODO: Unicode identifiers
|
||||||
}, {
|
regex : "[a-zA-Z_$][a-zA-Z0-9_$]*\\b"
|
||||||
token : "keyword.operator",
|
}, {
|
||||||
regex : "!|\\$|%|&|\\*|\\-\\-|\\-|\\+\\+|\\+|~|===|==|=|!=|!==|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\\|\\||\\?\\:|\\*=|%=|\\+=|\\-=|&=|\\^=|\\b(?:in|instanceof|new|delete|typeof|void)"
|
token : "keyword.operator",
|
||||||
}, {
|
regex : "!|\\$|%|&|\\*|\\-\\-|\\-|\\+\\+|\\+|~|===|==|=|!=|!==|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\\|\\||\\?\\:|\\*=|%=|\\+=|\\-=|&=|\\^=|\\b(?:in|instanceof|new|delete|typeof|void)"
|
||||||
token : "lparen",
|
}, {
|
||||||
regex : "[[({]"
|
token : "lparen",
|
||||||
}, {
|
regex : "[[({]"
|
||||||
token : "rparen",
|
}, {
|
||||||
regex : "[\\])}]"
|
token : "rparen",
|
||||||
}, {
|
regex : "[\\])}]"
|
||||||
token : "text",
|
}, {
|
||||||
regex : "\\s+"
|
token : "text",
|
||||||
} ],
|
regex : "\\s+"
|
||||||
"comment" : [ {
|
}
|
||||||
token : "comment", // closing comment
|
],
|
||||||
regex : ".*?\\*\\/",
|
"comment" : [
|
||||||
next : "start"
|
{
|
||||||
}, {
|
token : "comment", // closing comment
|
||||||
token : "comment", // comment spanning whole line
|
regex : ".*?\\*\\/",
|
||||||
regex : ".+"
|
next : "start"
|
||||||
} ],
|
}, {
|
||||||
"qqstring" : [ {
|
token : "comment", // comment spanning whole line
|
||||||
token : "string",
|
regex : ".+"
|
||||||
regex : '(?:(?:\\\\.)|(?:[^"\\\\]))*?"',
|
}
|
||||||
next : "start"
|
],
|
||||||
}, {
|
"qqstring" : [
|
||||||
token : "string",
|
{
|
||||||
regex : '.+'
|
token : "string",
|
||||||
} ],
|
regex : '(?:(?:\\\\.)|(?:[^"\\\\]))*?"',
|
||||||
"qstring" : [ {
|
next : "start"
|
||||||
token : "string",
|
}, {
|
||||||
regex : "(?:(?:\\\\.)|(?:[^'\\\\]))*?'",
|
token : "string",
|
||||||
next : "start"
|
regex : '.+'
|
||||||
}, {
|
}
|
||||||
token : "string",
|
],
|
||||||
regex : '.+'
|
"qstring" : [
|
||||||
} ]
|
{
|
||||||
|
token : "string",
|
||||||
|
regex : "(?:(?:\\\\.)|(?:[^'\\\\]))*?'",
|
||||||
|
next : "start"
|
||||||
|
}, {
|
||||||
|
token : "string",
|
||||||
|
regex : '.+'
|
||||||
|
}
|
||||||
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
this.addRules(docComment.getRules(), "doc-");
|
this.addRules(docComment.getRules(), "doc-");
|
||||||
|
|
|
||||||
|
|
@ -74,10 +74,17 @@ var Test = {
|
||||||
assert.equal("lparen", tokens[0].type);
|
assert.equal("lparen", tokens[0].type);
|
||||||
assert.equal("text", tokens[1].type);
|
assert.equal("text", tokens[1].type);
|
||||||
assert.equal("rparen", tokens[2].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)
|
if (module === require.main)
|
||||||
module.exports.exec()
|
module.exports.exec()
|
||||||
|
|
@ -125,10 +125,10 @@ var Test = {
|
||||||
|
|
||||||
"test: trigger outdent if line is space and new text starts with closing brace" : function() {
|
"test: trigger outdent if line is space and new text starts with closing brace" : function() {
|
||||||
assert.ok(this.mode.checkOutdent("start", " ", " }"));
|
assert.ok(this.mode.checkOutdent("start", " ", " }"));
|
||||||
assert.equal(this.mode.checkOutdent("start", " a ", " }"));
|
assert.ok(!this.mode.checkOutdent("start", " a ", " }"));
|
||||||
assert.equal(this.mode.checkOutdent("start", "", "}"));
|
assert.ok(!this.mode.checkOutdent("start", "", "}"));
|
||||||
assert.equal(this.mode.checkOutdent("start", " ", "a }"));
|
assert.ok(!this.mode.checkOutdent("start", " ", "a }"));
|
||||||
assert.equal(this.mode.checkOutdent("start", " }", "}"));
|
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() {
|
"test: auto outdent should indent the line with the same indent as the line with the matching opening brace" : function() {
|
||||||
|
|
|
||||||
|
|
@ -91,6 +91,13 @@ var Test = {
|
||||||
assert.equal("lparen", tokens[0].type);
|
assert.equal("lparen", tokens[0].type);
|
||||||
assert.equal("text", tokens[1].type);
|
assert.equal("text", tokens[1].type);
|
||||||
assert.equal("rparen", tokens[2].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);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue