From 6ccf196b61b953b9b21fd25eba41b39d6dc96257 Mon Sep 17 00:00:00 2001 From: Jeremy Ashkenas Date: Mon, 15 Mar 2010 21:47:40 -0700 Subject: [PATCH] adding another language extension test, with %w{} style ruby word array literals --- test/test_compilation.coffee | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/test/test_compilation.coffee b/test/test_compilation.coffee index 646b95aa..daf4db78 100644 --- a/test/test_compilation.coffee +++ b/test/test_compilation.coffee @@ -27,8 +27,32 @@ CoffeeScript.extend -> true # Compile with the extension. -js: CoffeeScript.compile('return --tobesplit--', {no_wrap: on}) +js: CoffeeScript.compile 'return --tobesplit--', {no_wrap: on} ok js is "return 'tobesplit'.split('');" -Lexer.extensions: [] \ No newline at end of file + +# Let's try a different extension, for Ruby-style array literals. + +class WordArrayNode extends BaseNode + type: 'WordArray' + + constructor: (words) -> + @words: words + + compile_node: (o) -> + strings = ("\"$word\"" for word in @words).join ', ' + "[$strings]" + +CoffeeScript.extend -> + return false unless words: @chunk.match(/^%w\{(.*)\}/) + @i += words[0].length + @token 'EXTENSION', new WordArrayNode(words[1].split(/\s+/)) + true + +js: CoffeeScript.compile 'puts %w{one two three}', {no_wrap: on} + +ok js is 'puts(["one", "two", "three"]);' + +Lexer.extensions: [] +