From 706652048f6f64a8eea292fb4e73cc6eed9922f9 Mon Sep 17 00:00:00 2001 From: ukyo Date: Sun, 30 Sep 2012 18:58:45 +0900 Subject: [PATCH] small fix and add tests --- lib/ace/mode/coffee_highlight_rules.js | 9 +- lib/ace/mode/coffee_highlight_rules_test.js | 106 ++++++++++++++++++++ 2 files changed, 114 insertions(+), 1 deletion(-) diff --git a/lib/ace/mode/coffee_highlight_rules.js b/lib/ace/mode/coffee_highlight_rules.js index c0aab565..7921c486 100644 --- a/lib/ace/mode/coffee_highlight_rules.js +++ b/lib/ace/mode/coffee_highlight_rules.js @@ -160,7 +160,14 @@ define(function(require, exports, module) { "entity.name.function", "text", "keyword.operator", "text", "paren.lparen", "variable.parameter", "paren.rparen", "text", "storage.type" ], - regex : "(" + identifier + ")(\\s*)(=|:)(\\s*)(\\(?)([^)]*)(\\)?)(\\s*)([-=]>)" + regex : "(" + identifier + ")(\\s*)(=|:)(\\s*)(\\()([^)]*)(\\))(\\s*)([\\-=]>)" + }, { + //play = -> + //play : -> + token : [ + "entity.name.function", "text", "keyword.operator", "text", "storage.type" + ], + regex : "(" + identifier + ")(\\s*)(=|:)(\\s*)([\\-=]>)" }, { //(args) -> token : [ diff --git a/lib/ace/mode/coffee_highlight_rules_test.js b/lib/ace/mode/coffee_highlight_rules_test.js index eaf85531..b8ac39c5 100644 --- a/lib/ace/mode/coffee_highlight_rules_test.js +++ b/lib/ace/mode/coffee_highlight_rules_test.js @@ -48,7 +48,113 @@ module.exports = { assert.equal(tokens.length, 1); assert.equal(tokens[0].type, "keyword"); }, + + "test: tokenize function: 'foo = (args) ->'": function() { + var tokens = this.tokenizer.getLineTokens("foo = (args) ->", "start").tokens; + console.log(tokens); + assert.equal(tokens.length, 9); + [ + "entity.name.function", "text", "keyword.operator", "text", + "paren.lparen", "variable.parameter", "paren.rparen", "text", "storage.type" + ].forEach(function(type, i) { + assert.equal(tokens[i].type, type); + }); + }, + "test: tokenize function: 'window.foo = (args) ->'": function() { + var tokens = this.tokenizer.getLineTokens("window.foo = (args) ->", "start").tokens; + console.log(tokens); + assert.equal(tokens.length, 11); + [ + "variable.language", "punctuation.operator", "entity.name.function", "text", "keyword.operator", "text", + "paren.lparen", "variable.parameter", "paren.rparen", "text", "storage.type" + ].forEach(function(type, i) { + assert.equal(tokens[i].type, type); + }); + }, + + "test: tokenize function: 'foo : (args) ->'": function() { + var tokens = this.tokenizer.getLineTokens("foo : (args) ->", "start").tokens; + assert.equal(tokens.length, 9); + [ + "entity.name.function", "text", "keyword.operator", "text", + "paren.lparen", "variable.parameter", "paren.rparen", "text", "storage.type" + ].forEach(function(type, i) { + assert.equal(tokens[i].type, type); + }); + }, + + "test: tokenize function: 'foo = ->'": function() { + var tokens = this.tokenizer.getLineTokens("foo = ->", "start").tokens; + assert.equal(tokens.length, 5); + [ + "entity.name.function", "text", "keyword.operator", "text", "storage.type" + ].forEach(function(type, i) { + assert.equal(tokens[i].type, type); + }); + }, + + "test: tokenize function: 'foo : ->'": function() { + var tokens = this.tokenizer.getLineTokens("foo : ->", "start").tokens; + assert.equal(tokens.length, 5); + [ + "entity.name.function", "text", "keyword.operator", "text", "storage.type" + ].forEach(function(type, i) { + assert.equal(tokens[i].type, type); + }); + }, + + "test: tokenize function: '(args) ->'": function() { + var tokens = this.tokenizer.getLineTokens("(args) ->", "start").tokens; + assert.equal(tokens.length, 5); + [ + "paren.lparen", "variable.parameter", "paren.rparen", "text", "storage.type" + ].forEach(function(type, i) { + assert.equal(tokens[i].type, type); + }); + }, + + "test: tokenize function(callback): 'foo bar: 1, (args) ->'": function() { + var tokens = this.tokenizer.getLineTokens("foo bar: 1, (args) ->", "start").tokens; + assert.equal(tokens.length, 13); + [ + "identifier", "text", "identifier", "punctuation.operator", "text", "constant.numeric", "punctuation.operator", "text", + "paren.lparen", "variable.parameter", "paren.rparen", "text", "storage.type" + ].forEach(function(type, i) { + assert.equal(tokens[i].type, type); + }); + }, + + "test: tokenize class: 'class Foo'": function() { + var tokens = this.tokenizer.getLineTokens("class Foo", "start").tokens; + assert.equal(tokens.length, 3); + [ + "keyword", "text", "language.support.class" + ].forEach(function(type, i) { + assert.equal(tokens[i].type, type); + }); + }, + + "test: tokenize class 'class Foo extends Bar'": function() { + var tokens = this.tokenizer.getLineTokens("class Foo extends Bar", "start").tokens; + assert.equal(tokens.length, 7); + [ + "keyword", "text", "language.support.class", "text", "keyword", "text", "language.support.class" + ].forEach(function(type, i) { + assert.equal(tokens[i].type, type); + }); + }, + + "test: tokenize illegal name property: 'foo.static.function'": function() { + var tokens = this.tokenizer.getLineTokens("foo.static.function", "start").tokens; + assert.equal(tokens.length, 5); + [ + "identifier", "punctuation.operator", "identifier", "punctuation.operator", "identifier" + ].forEach(function(type, i) { + assert.equal(tokens[i].type, type); + }); + }, + // TODO: disable. not yet implemented "!test tokenize string with interpolation": function() { var tokens = this.tokenizer.getLineTokens('"#{ 22 / 7 } is a decent approximation of π"', "start").tokens;