Skip to content

Commit 7bd6343

Browse files
committed
Seperate more parser and compiler specs into correct location
1 parent 7aeae27 commit 7bd6343

File tree

4 files changed

+50
-66
lines changed

4 files changed

+50
-66
lines changed

spec/cli/compiler_spec.rb

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
require File.expand_path('../spec_helper', __FILE__)
2+
3+
describe Opal::Compiler do
4+
it "should compile simple ruby values" do
5+
expect_compiled("3.142").to include("return 3.142")
6+
expect_compiled("123e1").to include("return 1230")
7+
expect_compiled("123E+10").to include("return 1230000000000")
8+
expect_compiled("false").to include("return false")
9+
expect_compiled("true").to include("return true")
10+
expect_compiled("nil").to include("return nil")
11+
end
12+
13+
it "should compile ruby strings" do
14+
expect_compiled('"hello world"').to include('return "hello world"')
15+
expect_compiled('"hello #{100}"').to include('"hello "', '100')
16+
end
17+
18+
it "should compile method calls" do
19+
expect_compiled("self.inspect").to include("$inspect()")
20+
expect_compiled("self.map { |a| a + 10 }").to include("$map")
21+
end
22+
23+
it "should compile constant lookups" do
24+
expect_compiled("Object").to include("scope.Object")
25+
expect_compiled("Array").to include("scope.Array")
26+
end
27+
28+
def expect_compiled(source)
29+
expect(Opal::Compiler.new.compile source)
30+
end
31+
end

spec/cli/parser/call_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,3 +129,11 @@
129129
end
130130
end
131131
end
132+
133+
describe "Command calls with operators" do
134+
it "parses operators before \n in command calls" do
135+
[:<<, :>>, :|, :^, :&, :<=>, :==, :===, :=~, :>, :>=, :<, :<=, :<<, :>>, :%, :**].each do |mid|
136+
opal_parse("self #{mid}\nself").should == [:call, [:self], mid, [:arglist, [:self]]]
137+
end
138+
end
139+
end

spec/cli/parser/comments_spec.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
require File.expand_path('../../spec_helper', __FILE__)
2+
3+
describe "Multiline comments" do
4+
it "parses multiline comments and ignores them" do
5+
opal_parse("=begin\nfoo\n=end\n100").should == [:int, 100]
6+
end
7+
8+
it "raises an exception if not closed before end of file" do
9+
lambda { opal_parse("=begin\nfoo\nbar") }.should raise_error(Exception, /embedded document meets end of file/)
10+
end
11+
end

spec/cli/parser/parse_spec.rb

Lines changed: 0 additions & 66 deletions
This file was deleted.

0 commit comments

Comments
 (0)