Skip to content

Commit

Permalink
added some execution test
Browse files Browse the repository at this point in the history
  • Loading branch information
jashkenas committed Dec 24, 2009
1 parent 417753b commit b743e32
Show file tree
Hide file tree
Showing 12 changed files with 110 additions and 23 deletions.
2 changes: 1 addition & 1 deletion README
Expand Up @@ -35,4 +35,4 @@
http://github.com/jashkenas/coffee-script/issues/

The source repository:
git://github.com/jashkenas/coffee-script.git
git://github.com/jashkenas/coffee-script.git
13 changes: 0 additions & 13 deletions TODO

This file was deleted.

21 changes: 17 additions & 4 deletions documentation/index.html.erb
Expand Up @@ -32,7 +32,7 @@
<p>
CoffeeScript is a little language that compiles into JavaScript. Think
of it as JavaScript's less ostentatious kid brother &mdash; the same genes,
the same accent, but a different sense of style. Apart from a handful of
roughly the same height, but a different sense of style. Apart from a handful of
bonus goodies, statements in CoffeeScript correspond one-to-one with their
equivalent in JavaScript, it's just another way of saying it.
</p>
Expand Down Expand Up @@ -72,6 +72,7 @@
<a href="#switch">Switch/Case/Else</a><br />
<a href="#try">Try/Catch/Finally</a><br />
<a href="#strings">Multiline Strings</a><br />
<a href="#change_log">Change Log</a><br />
</p>

<h2 id="overview">Mini Overview</h2>
Expand All @@ -81,9 +82,14 @@
<%= code_for('overview', 'cubed_list') %>

<h2 id="installation">Installation and Usage</h2>

<p>
The CoffeeScript compiler is written in pure Ruby, and is available
as a Ruby Gem.
</p>

<pre>
sudo gem install coffee-script</pre>
gem install coffee-script</pre>

<p>
Installing the gem provides the <tt>coffee-script</tt> command, which can
Expand Down Expand Up @@ -339,7 +345,7 @@ coffee-script --print app/scripts/*.cs > concatenation.js</pre>
<p id="switch">
<b class="header">Switch/Case/Else</b>
<b>Switch</b> statements in JavaScript are rather broken. You can only
do string comparisons, and need to remember to <b>break</b> at the end of
do comparisons based on string equality, and need to remember to <b>break</b> at the end of
every <b>case</b> statement to avoid accidentally falling through to
the default case. CoffeeScript
compiles <b>switch</b> statements into JavaScript if-else chains, allowing you to
Expand All @@ -352,7 +358,7 @@ coffee-script --print app/scripts/*.cs > concatenation.js</pre>
<p id="try">
<b class="header">Try/Catch/Finally</b>
Try/catch statements are just about the same as JavaScript (although
they work as expressions). No braces required.
they work as expressions).
</p>
<%= code_for('try') %>

Expand All @@ -361,6 +367,13 @@ coffee-script --print app/scripts/*.cs > concatenation.js</pre>
Multiline strings are allowed in CoffeeScript.
</p>
<%= code_for('strings', 'moby_dick') %>

<h2 id="change_log">Change Log</h2>

<p>
<b class="header" style="margin-top: 25px;">0.1.0</b>
Initial CoffeeScript release.
</p>

</div>

Expand Down
21 changes: 17 additions & 4 deletions index.html
Expand Up @@ -18,7 +18,7 @@ <h1><sub style="font-size: 100px;">&#9749;</sub> CoffeeScript</h1>
<p>
CoffeeScript is a little language that compiles into JavaScript. Think
of it as JavaScript's less ostentatious kid brother &mdash; the same genes,
the same accent, but a different sense of style. Apart from a handful of
roughly the same height, but a different sense of style. Apart from a handful of
bonus goodies, statements in CoffeeScript correspond one-to-one with their
equivalent in JavaScript, it's just another way of saying it.
</p>
Expand Down Expand Up @@ -58,6 +58,7 @@ <h2>Table of Contents</h2>
<a href="#switch">Switch/Case/Else</a><br />
<a href="#try">Try/Catch/Finally</a><br />
<a href="#strings">Multiline Strings</a><br />
<a href="#change_log">Change Log</a><br />
</p>

<h2 id="overview">Mini Overview</h2>
Expand Down Expand Up @@ -151,9 +152,14 @@ <h2 id="overview">Mini Overview</h2>
;alert(cubed_list);'>run: cubed_list</button><br class='clear' /></div>

<h2 id="installation">Installation and Usage</h2>

<p>
The CoffeeScript compiler is written in pure Ruby, and is available
as a Ruby Gem.
</p>

<pre>
sudo gem install coffee-script</pre>
gem install coffee-script</pre>

<p>
Installing the gem provides the <tt>coffee-script</tt> command, which can
Expand Down Expand Up @@ -654,7 +660,7 @@ <h2>Language Reference</h2>
<p id="switch">
<b class="header">Switch/Case/Else</b>
<b>Switch</b> statements in JavaScript are rather broken. You can only
do string comparisons, and need to remember to <b>break</b> at the end of
do comparisons based on string equality, and need to remember to <b>break</b> at the end of
every <b>case</b> statement to avoid accidentally falling through to
the default case. CoffeeScript
compiles <b>switch</b> statements into JavaScript if-else chains, allowing you to
Expand Down Expand Up @@ -690,7 +696,7 @@ <h2>Language Reference</h2>
<p id="try">
<b class="header">Try/Catch/Finally</b>
Try/catch statements are just about the same as JavaScript (although
they work as expressions). No braces required.
they work as expressions).
</p>
<div class='code'><pre class="idle"><span class="Keyword">try</span>
all_hell_breaks_loose()
Expand Down Expand Up @@ -733,6 +739,13 @@ <h2>Language Reference</h2>
about a little and see the watery part of the \
world...";
;alert(moby_dick);'>run: moby_dick</button><br class='clear' /></div>

<h2 id="change_log">Change Log</h2>

<p>
<b class="header" style="margin-top: 25px;">0.1.0</b>
Initial CoffeeScript release.
</p>

</div>

Expand Down
2 changes: 1 addition & 1 deletion lib/coffee_script/nodes.rb
Expand Up @@ -507,7 +507,7 @@ def compile(o={})
return_result = "\n#{o[:indent]}#{return_result}"
if @filter
body = CallNode.new(ValueNode.new(LiteralNode.new(rvar), [AccessorNode.new('push')]), [@body])
body = IfNode.new(@filter, body, nil, :statement)
body = IfNode.new(@filter, body, nil, :statement => true)
save_result = ''
suffix = ''
end
Expand Down
4 changes: 4 additions & 0 deletions test/fixtures/execution/array_comprehension.cs
@@ -0,0 +1,4 @@
nums: n * n for n in [1, 2, 3] if n % 2 aint 0.
result: n * 2 for n in nums.

print(result.join(',') is '2,18')
21 changes: 21 additions & 0 deletions test/fixtures/execution/array_comprehension.js
@@ -0,0 +1,21 @@
(function(){
var nums;
var a = [1, 2, 3];
var d = [];
for (var b=0, c=a.length; b<c; b++) {
var n = a[b];
if (n % 2 !== 0) {
nums = d.push(n * n);
}
}
nums = d;
var result;
var e = nums;
var h = [];
for (var f=0, g=e.length; f<g; f++) {
n = e[f];
h[f] = n * 2;
}
result = h;
print(result.join(',') === '2,18');
})();
6 changes: 6 additions & 0 deletions test/fixtures/execution/assign_to_try_catch.cs
@@ -0,0 +1,6 @@
result: try
nonexistent * missing
catch error
true.

print(result)
9 changes: 9 additions & 0 deletions test/fixtures/execution/assign_to_try_catch.js
@@ -0,0 +1,9 @@
(function(){
var result;
try {
result = nonexistent * missing;
} catch (error) {
result = true;
}
print(result);
})();
11 changes: 11 additions & 0 deletions test/fixtures/execution/fancy_if_statement.cs
@@ -0,0 +1,11 @@
a: b: d: true
c: false

result: if a
if b
if c then false
else
if d
true....

print(result)
6 changes: 6 additions & 0 deletions test/fixtures/execution/fancy_if_statement.js
@@ -0,0 +1,6 @@
(function(){
var a = b = d = true;
var c = false;
var result = a ? b ? c ? false : d ? true : null : null : null;
print(result);
})();
17 changes: 17 additions & 0 deletions test/unit/test_execution.rb
@@ -0,0 +1,17 @@
require 'test_helper'

class ExecutionTest < Test::Unit::TestCase

def test_execution_of_coffeescript
`bin/coffee-script test/fixtures/execution/*.cs`
sources = Dir['test/fixtures/execution/*.js'].map {|f| File.expand_path(f) }
starting_place = File.expand_path(Dir.pwd)
Dir.chdir('/Users/jashkenas/Desktop/Beauty/Code/v8')
sources.each do |source|
assert `./shell #{source}`.chomp.to_sym == :true
end
ensure
Dir.chdir(starting_place)
end

end

0 comments on commit b743e32

Please sign in to comment.