Skip to content

Commit

Permalink
Seperate more parser and compiler specs into correct location
Browse files Browse the repository at this point in the history
  • Loading branch information
adambeynon committed Nov 23, 2013
1 parent 7aeae27 commit 7bd6343
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 66 deletions.
31 changes: 31 additions & 0 deletions spec/cli/compiler_spec.rb
@@ -0,0 +1,31 @@
require File.expand_path('../spec_helper', __FILE__)

describe Opal::Compiler do
it "should compile simple ruby values" do
expect_compiled("3.142").to include("return 3.142")
expect_compiled("123e1").to include("return 1230")
expect_compiled("123E+10").to include("return 1230000000000")
expect_compiled("false").to include("return false")
expect_compiled("true").to include("return true")
expect_compiled("nil").to include("return nil")
end

it "should compile ruby strings" do
expect_compiled('"hello world"').to include('return "hello world"')
expect_compiled('"hello #{100}"').to include('"hello "', '100')
end

it "should compile method calls" do
expect_compiled("self.inspect").to include("$inspect()")
expect_compiled("self.map { |a| a + 10 }").to include("$map")
end

it "should compile constant lookups" do
expect_compiled("Object").to include("scope.Object")
expect_compiled("Array").to include("scope.Array")
end

def expect_compiled(source)
expect(Opal::Compiler.new.compile source)
end
end
8 changes: 8 additions & 0 deletions spec/cli/parser/call_spec.rb
Expand Up @@ -129,3 +129,11 @@
end
end
end

describe "Command calls with operators" do
it "parses operators before \n in command calls" do
[:<<, :>>, :|, :^, :&, :<=>, :==, :===, :=~, :>, :>=, :<, :<=, :<<, :>>, :%, :**].each do |mid|
opal_parse("self #{mid}\nself").should == [:call, [:self], mid, [:arglist, [:self]]]
end
end
end
11 changes: 11 additions & 0 deletions spec/cli/parser/comments_spec.rb
@@ -0,0 +1,11 @@
require File.expand_path('../../spec_helper', __FILE__)

describe "Multiline comments" do
it "parses multiline comments and ignores them" do
opal_parse("=begin\nfoo\n=end\n100").should == [:int, 100]
end

it "raises an exception if not closed before end of file" do
lambda { opal_parse("=begin\nfoo\nbar") }.should raise_error(Exception, /embedded document meets end of file/)
end
end
66 changes: 0 additions & 66 deletions spec/cli/parser/parse_spec.rb

This file was deleted.

0 comments on commit 7bd6343

Please sign in to comment.