Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: opal/opal
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 9669f3fa75ea
Choose a base ref
...
head repository: opal/opal
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: b1069b802587
Choose a head ref
  • 2 commits
  • 31 files changed
  • 1 contributor

Commits on Dec 3, 2013

  1. Copy the full SHA
    9a56545 View commit details
  2. Clean up cli spec helpers

    adambeynon committed Dec 3, 2013
    1
    Copy the full SHA
    b1069b8 View commit details
26 changes: 17 additions & 9 deletions spec/cli/lexer_spec.rb
Original file line number Diff line number Diff line change
@@ -32,20 +32,28 @@
expect_columns("true; false; self\n ni;").to eq([0, 7, 15, 2])
end

describe "string escapes" do
it "does not escape characters using single-quotes" do
describe "double-quoted strings" do
it "escape backslashes in strings" do
expect_parsed_string("\"foo\"").to eq("foo")
expect_parsed_string("\"foo\\tbar\"").to eq("foo\tbar")
expect_parsed_string("\"\\\"foo\"").to eq("\"foo")
end
end

describe "single-quoted strings" do
it "do not support interpolation" do
expect_parsed_string("'foo\#{self}'").to eq('foo#{self}')
expect_parsed_string("'\#@bar'").to eq('#@bar')
expect_parsed_string("'\#$baz'").to eq('#$baz')
end

it "do not escape backslashed characters" do
expect_parsed_string("'foo'").to eq("foo")
expect_parsed_string("'foo\\tbar'").to eq("foo\\tbar")
end

it "single-quoted strings can escape \\ and \' characters" do
it "can escape \\ and \' characters" do
expect_parsed_string("'a\\\\b\\'c'").to eq("a\\b'c")
end

it "does escape characters using double-quoted strings" do
expect_parsed_string("\"foo\"").to eq("foo")
expect_parsed_string("\"foo\\tbar\"").to eq("foo\tbar")
expect_parsed_string("\"\\\"foo\"").to eq("\"foo")
end
end
end
10 changes: 5 additions & 5 deletions spec/cli/parser/alias_spec.rb
Original file line number Diff line number Diff line change
@@ -3,24 +3,24 @@
describe "The alias keyword" do
describe "with fitem" do
it "should return an s(:alias) with s(:sym)" do
opal_parse("alias a b").should == [:alias, [:sym, :a], [:sym, :b]]
opal_parse("alias == equals").should == [:alias, [:sym, :==], [:sym, :equals]]
parsed("alias a b").should == [:alias, [:sym, :a], [:sym, :b]]
parsed("alias == equals").should == [:alias, [:sym, :==], [:sym, :equals]]
end

it "should accept symbols as names" do
opal_parse("alias :foo :bar").should == [:alias, [:sym, :foo], [:sym, :bar]]
parsed("alias :foo :bar").should == [:alias, [:sym, :foo], [:sym, :bar]]
end
end

describe "with gvar" do
it "should return a s(:valias) with two gvars as arguments" do
opal_parse("alias $foo $bar").should == [:valias, :$foo, :$bar]
parsed("alias $foo $bar").should == [:valias, :$foo, :$bar]
end
end

describe "with gvar and nth ref" do
it "should return a s(:valias) with two values as arguments" do
opal_parse("alias $foo $1").should == [:valias, :$foo, :"1"]
parsed("alias $foo $1").should == [:valias, :$foo, :"1"]
end
end
end
4 changes: 2 additions & 2 deletions spec/cli/parser/and_spec.rb
Original file line number Diff line number Diff line change
@@ -2,12 +2,12 @@

describe "The and statement" do
it "should always return s(:and)" do
opal_parse("1 and 2").should == [:and, [:int, 1], [:int, 2]]
parsed("1 and 2").should == [:and, [:int, 1], [:int, 2]]
end
end

describe "The && expression" do
it "should always return s(:and)" do
opal_parse("1 && 2").should == [:and, [:int, 1], [:int, 2]]
parsed("1 && 2").should == [:and, [:int, 1], [:int, 2]]
end
end
16 changes: 8 additions & 8 deletions spec/cli/parser/attrasgn_spec.rb
Original file line number Diff line number Diff line change
@@ -2,27 +2,27 @@

describe "Attribute assignments" do
it "should return a s(:attrasgn) for simple assignments" do
opal_parse('self.foo = 1').should == [:attrasgn, [:self], :foo=, [:arglist, [:int, 1]]]
opal_parse('bar.foo = 1').should == [:attrasgn, [:call, nil, :bar, [:arglist]], :foo=, [:arglist, [:int, 1]]]
opal_parse('@bar.foo = 1').should == [:attrasgn, [:ivar, :@bar], :foo=, [:arglist, [:int, 1]]]
parsed('self.foo = 1').should == [:attrasgn, [:self], :foo=, [:arglist, [:int, 1]]]
parsed('bar.foo = 1').should == [:attrasgn, [:call, nil, :bar, [:arglist]], :foo=, [:arglist, [:int, 1]]]
parsed('@bar.foo = 1').should == [:attrasgn, [:ivar, :@bar], :foo=, [:arglist, [:int, 1]]]
end

it "accepts both '.' and '::' for method call operators" do
opal_parse('self.foo = 1').should == [:attrasgn, [:self], :foo=, [:arglist, [:int, 1]]]
opal_parse('self::foo = 1').should == [:attrasgn, [:self], :foo=, [:arglist, [:int, 1]]]
parsed('self.foo = 1').should == [:attrasgn, [:self], :foo=, [:arglist, [:int, 1]]]
parsed('self::foo = 1').should == [:attrasgn, [:self], :foo=, [:arglist, [:int, 1]]]
end

it "can accept a constant as assignable name when using '.'" do
opal_parse('self.FOO = 1').should == [:attrasgn, [:self], :FOO=, [:arglist, [:int, 1]]]
parsed('self.FOO = 1').should == [:attrasgn, [:self], :FOO=, [:arglist, [:int, 1]]]
end

describe "when setting element reference" do
it "uses []= as the method call" do
opal_parse('self[1] = 2').should == [:attrasgn, [:self], :[]=, [:arglist, [:int, 1], [:int, 2]]]
parsed('self[1] = 2').should == [:attrasgn, [:self], :[]=, [:arglist, [:int, 1], [:int, 2]]]
end

it "supports multiple arguments inside brackets" do
opal_parse('self[1, 2] = 3').should == [:attrasgn, [:self], :[]=, [:arglist, [:int, 1], [:int, 2], [:int, 3]]]
parsed('self[1, 2] = 3').should == [:attrasgn, [:self], :[]=, [:arglist, [:int, 1], [:int, 2], [:int, 3]]]
end
end
end
22 changes: 11 additions & 11 deletions spec/cli/parser/begin_spec.rb
Original file line number Diff line number Diff line change
@@ -2,41 +2,41 @@

describe "The begin keyword" do
it "should be removed when used without a resuce or enusre body" do
opal_parse('begin; 1; end').should == [:int, 1]
opal_parse('begin; 1; 2; end').should == [:block, [:int, 1], [:int, 2]]
parsed('begin; 1; end').should == [:int, 1]
parsed('begin; 1; 2; end').should == [:block, [:int, 1], [:int, 2]]
end

describe "with 'rescue' bodies" do
it "should create a s(:rescue) sexp" do
opal_parse('begin; 1; rescue; 2; end').should == [:rescue, [:int, 1], [:resbody, [:array], [:int, 2]]]
parsed('begin; 1; rescue; 2; end').should == [:rescue, [:int, 1], [:resbody, [:array], [:int, 2]]]
end

it "allows multiple rescue bodies" do
opal_parse('begin 1; rescue; 2; rescue; 3; end').should == [:rescue, [:int, 1], [:resbody, [:array], [:int, 2]], [:resbody, [:array], [:int, 3]]]
parsed('begin 1; rescue; 2; rescue; 3; end').should == [:rescue, [:int, 1], [:resbody, [:array], [:int, 2]], [:resbody, [:array], [:int, 3]]]
end

it "accepts a list of classes used to match against the exception" do
opal_parse('begin 1; rescue Klass; 2; end').should == [:rescue, [:int, 1], [:resbody, [:array, [:const, :Klass]], [:int, 2]]]
parsed('begin 1; rescue Klass; 2; end').should == [:rescue, [:int, 1], [:resbody, [:array, [:const, :Klass]], [:int, 2]]]
end

it "accepts an identifier to assign exception to" do
opal_parse('begin 1; rescue => a; 2; end').should == [:rescue, [:int, 1], [:resbody, [:array, [:lasgn, :a, [:gvar, :$!]]], [:int, 2]]]
opal_parse('begin 1; rescue Klass => a; 2; end').should == [:rescue, [:int, 1], [:resbody, [:array, [:const, :Klass],[:lasgn, :a, [:gvar, :$!]]], [:int, 2]]]
parsed('begin 1; rescue => a; 2; end').should == [:rescue, [:int, 1], [:resbody, [:array, [:lasgn, :a, [:gvar, :$!]]], [:int, 2]]]
parsed('begin 1; rescue Klass => a; 2; end').should == [:rescue, [:int, 1], [:resbody, [:array, [:const, :Klass],[:lasgn, :a, [:gvar, :$!]]], [:int, 2]]]
end

it "accepts an ivar to assign exception to" do
opal_parse('begin 1; rescue => @a; 2; end').should == [:rescue, [:int, 1], [:resbody, [:array, [:iasgn, :@a, [:gvar, :$!]]], [:int, 2]]]
opal_parse('begin 1; rescue Klass => @a; 2; end').should == [:rescue, [:int, 1], [:resbody, [:array, [:const, :Klass],[:iasgn, :@a, [:gvar, :$!]]], [:int, 2]]]
parsed('begin 1; rescue => @a; 2; end').should == [:rescue, [:int, 1], [:resbody, [:array, [:iasgn, :@a, [:gvar, :$!]]], [:int, 2]]]
parsed('begin 1; rescue Klass => @a; 2; end').should == [:rescue, [:int, 1], [:resbody, [:array, [:const, :Klass],[:iasgn, :@a, [:gvar, :$!]]], [:int, 2]]]
end

it "should parse newline right after rescue" do
opal_parse("begin; 1; rescue\n 2; end").should == [:rescue, [:int, 1], [:resbody, [:array], [:int, 2]]]
parsed("begin; 1; rescue\n 2; end").should == [:rescue, [:int, 1], [:resbody, [:array], [:int, 2]]]
end
end

describe "with an 'ensure' block" do
it "should propagate into single s(:ensure) statement when no rescue block given" do
opal_parse('begin; 1; ensure; 2; end').should == [:ensure, [:int, 1], [:int, 2]]
parsed('begin; 1; ensure; 2; end').should == [:ensure, [:int, 1], [:int, 2]]
end
end
end
6 changes: 3 additions & 3 deletions spec/cli/parser/block_spec.rb
Original file line number Diff line number Diff line change
@@ -2,11 +2,11 @@

describe "Block statements" do
it "should return the direct expression if only one expresssion in block" do
opal_parse("42").should == [:int, 42]
parsed("42").should == [:int, 42]
end

it "should return an s(:block) with all expressions appended for > 1 expression" do
opal_parse("42; 43").should == [:block, [:int, 42], [:int, 43]]
opal_parse("42; 43\n44").should == [:block, [:int, 42], [:int, 43], [:int, 44]]
parsed("42; 43").should == [:block, [:int, 42], [:int, 43]]
parsed("42; 43\n44").should == [:block, [:int, 42], [:int, 43], [:int, 44]]
end
end
10 changes: 5 additions & 5 deletions spec/cli/parser/break_spec.rb
Original file line number Diff line number Diff line change
@@ -2,16 +2,16 @@

describe "The break keyword" do
it "should return s(:break) when given no args" do
opal_parse("break").should == [:break]
parsed("break").should == [:break]
end

it "returns s(:break) with a single arg not wrapped in s(:array)" do
opal_parse("break 1").should == [:break, [:int, 1]]
opal_parse("break *1").should == [:break, [:splat, [:int, 1]]]
parsed("break 1").should == [:break, [:int, 1]]
parsed("break *1").should == [:break, [:splat, [:int, 1]]]
end

it "returns s(:break) with an s(:array) for args size > 1" do
opal_parse("break 1, 2").should == [:break, [:array, [:int, 1], [:int, 2]]]
opal_parse("break 1, *2").should == [:break, [:array, [:int, 1], [:splat, [:int, 2]]]]
parsed("break 1, 2").should == [:break, [:array, [:int, 1], [:int, 2]]]
parsed("break 1, *2").should == [:break, [:array, [:int, 1], [:splat, [:int, 2]]]]
end
end
96 changes: 48 additions & 48 deletions spec/cli/parser/call_spec.rb
Original file line number Diff line number Diff line change
@@ -2,102 +2,102 @@

describe "Method calls" do
it "should use 'nil' for calls without a receiver" do
opal_parse("foo").should == [:call, nil, :foo, [:arglist]]
opal_parse("foo()").should == [:call, nil, :foo, [:arglist]]
parsed("foo").should == [:call, nil, :foo, [:arglist]]
parsed("foo()").should == [:call, nil, :foo, [:arglist]]
end

it "should always have an arglist when not passed any arguments" do
opal_parse("foo").should == [:call, nil, :foo, [:arglist]]
opal_parse("self.foo").should == [:call, [:self], :foo, [:arglist]]
opal_parse("foo()").should == [:call, nil, :foo, [:arglist]]
opal_parse("self.foo()").should == [:call, [:self], :foo, [:arglist]]
parsed("foo").should == [:call, nil, :foo, [:arglist]]
parsed("self.foo").should == [:call, [:self], :foo, [:arglist]]
parsed("foo()").should == [:call, nil, :foo, [:arglist]]
parsed("self.foo()").should == [:call, [:self], :foo, [:arglist]]
end

it "appends all arguments onto arglist" do
opal_parse("foo 1").should == [:call, nil, :foo, [:arglist, [:int, 1]]]
opal_parse("foo 1, 2").should == [:call, nil, :foo, [:arglist, [:int, 1], [:int, 2]]]
opal_parse("foo 1, *2").should == [:call, nil, :foo, [:arglist, [:int, 1], [:splat, [:int, 2]]]]
parsed("foo 1").should == [:call, nil, :foo, [:arglist, [:int, 1]]]
parsed("foo 1, 2").should == [:call, nil, :foo, [:arglist, [:int, 1], [:int, 2]]]
parsed("foo 1, *2").should == [:call, nil, :foo, [:arglist, [:int, 1], [:splat, [:int, 2]]]]
end

it "supports leading dots on newline" do
opal_parse("foo\n.bar").should == [:call, [:call, nil, :foo, [:arglist]], :bar, [:arglist]]
lambda { opal_parse("foo\n..bar") }.should raise_error(Exception)
parsed("foo\n.bar").should == [:call, [:call, nil, :foo, [:arglist]], :bar, [:arglist]]
lambda { parsed("foo\n..bar") }.should raise_error(Exception)
end
end

describe "Operator calls" do
it "should parse all other operators into method calls" do
opal_parse("1 % 2").should == [:call, [:int, 1], :%, [:arglist, [:int, 2]]]
opal_parse("1 ** 2").should == [:call, [:int, 1], :**, [:arglist, [:int, 2]]]
parsed("1 % 2").should == [:call, [:int, 1], :%, [:arglist, [:int, 2]]]
parsed("1 ** 2").should == [:call, [:int, 1], :**, [:arglist, [:int, 2]]]

opal_parse("+self").should == [:call, [:self], :+@, [:arglist]]
opal_parse("-self").should == [:call, [:self], :-@, [:arglist]]
parsed("+self").should == [:call, [:self], :+@, [:arglist]]
parsed("-self").should == [:call, [:self], :-@, [:arglist]]

opal_parse("1 | 2").should == [:call, [:int, 1], :|, [:arglist, [:int, 2]]]
opal_parse("1 ^ 2").should == [:call, [:int, 1], :^, [:arglist, [:int, 2]]]
opal_parse("1 & 2").should == [:call, [:int, 1], :&, [:arglist, [:int, 2]]]
opal_parse("1 <=> 2").should == [:call, [:int, 1], :<=>, [:arglist, [:int, 2]]]
parsed("1 | 2").should == [:call, [:int, 1], :|, [:arglist, [:int, 2]]]
parsed("1 ^ 2").should == [:call, [:int, 1], :^, [:arglist, [:int, 2]]]
parsed("1 & 2").should == [:call, [:int, 1], :&, [:arglist, [:int, 2]]]
parsed("1 <=> 2").should == [:call, [:int, 1], :<=>, [:arglist, [:int, 2]]]

opal_parse("1 < 2").should == [:call, [:int, 1], :<, [:arglist, [:int, 2]]]
opal_parse("1 <= 2").should == [:call, [:int, 1], :<=, [:arglist, [:int, 2]]]
opal_parse("1 > 2").should == [:call, [:int, 1], :>, [:arglist, [:int, 2]]]
opal_parse("1 >= 2").should == [:call, [:int, 1], :>=, [:arglist, [:int, 2]]]
parsed("1 < 2").should == [:call, [:int, 1], :<, [:arglist, [:int, 2]]]
parsed("1 <= 2").should == [:call, [:int, 1], :<=, [:arglist, [:int, 2]]]
parsed("1 > 2").should == [:call, [:int, 1], :>, [:arglist, [:int, 2]]]
parsed("1 >= 2").should == [:call, [:int, 1], :>=, [:arglist, [:int, 2]]]

opal_parse("1 == 2").should == [:call, [:int, 1], :==, [:arglist, [:int, 2]]]
opal_parse("1 === 2").should == [:call, [:int, 1], :===, [:arglist, [:int, 2]]]
opal_parse("1 =~ 2").should == [:call, [:int, 1], :=~, [:arglist, [:int, 2]]]
parsed("1 == 2").should == [:call, [:int, 1], :==, [:arglist, [:int, 2]]]
parsed("1 === 2").should == [:call, [:int, 1], :===, [:arglist, [:int, 2]]]
parsed("1 =~ 2").should == [:call, [:int, 1], :=~, [:arglist, [:int, 2]]]

opal_parse("~1").should == [:call, [:int, 1], :~, [:arglist]]
opal_parse("1 << 2").should == [:call, [:int, 1], :<<, [:arglist, [:int, 2]]]
opal_parse("1 >> 2").should == [:call, [:int, 1], :>>, [:arglist, [:int, 2]]]
parsed("~1").should == [:call, [:int, 1], :~, [:arglist]]
parsed("1 << 2").should == [:call, [:int, 1], :<<, [:arglist, [:int, 2]]]
parsed("1 >> 2").should == [:call, [:int, 1], :>>, [:arglist, [:int, 2]]]
end

it "optimizes +@ and -@ on numerics" do
opal_parse("+1").should == [:int, 1]
opal_parse("-1").should == [:int, -1]
parsed("+1").should == [:int, 1]
parsed("-1").should == [:int, -1]
end
end

describe "Optional paren calls" do
it "should correctly parse - and -@" do
opal_parse("x - 1").should == [:call, [:call, nil, :x, [:arglist]], :-, [:arglist, [:int, 1]]]
opal_parse("x -1").should == [:call, nil, :x, [:arglist, [:int, -1]]]
parsed("x - 1").should == [:call, [:call, nil, :x, [:arglist]], :-, [:arglist, [:int, 1]]]
parsed("x -1").should == [:call, nil, :x, [:arglist, [:int, -1]]]
end

it "should correctly parse + and +@" do
opal_parse("x + 1").should == [:call, [:call, nil, :x, [:arglist]], :+, [:arglist, [:int, 1]]]
opal_parse("x +1").should == [:call, nil, :x, [:arglist, [:int, 1]]]
parsed("x + 1").should == [:call, [:call, nil, :x, [:arglist]], :+, [:arglist, [:int, 1]]]
parsed("x +1").should == [:call, nil, :x, [:arglist, [:int, 1]]]
end

it "should correctly parse / and regexps" do
opal_parse("x / 500").should == [:call, [:call, nil, :x, [:arglist]], :/, [:arglist, [:int, 500]]]
opal_parse("x /foo/").should == [:call, nil, :x, [:arglist, [:regexp, /foo/]]]
parsed("x / 500").should == [:call, [:call, nil, :x, [:arglist]], :/, [:arglist, [:int, 500]]]
parsed("x /foo/").should == [:call, nil, :x, [:arglist, [:regexp, /foo/]]]
end

it "should parse LPAREN_ARG correctly" do
opal_parse("x (1).y").should == [:call, nil, :x, [:arglist, [:call, [:int, 1], :y, [:arglist]]]]
opal_parse("x(1).y").should == [:call, [:call, nil, :x, [:arglist, [:int, 1]]], :y, [:arglist]]
parsed("x (1).y").should == [:call, nil, :x, [:arglist, [:call, [:int, 1], :y, [:arglist]]]]
parsed("x(1).y").should == [:call, [:call, nil, :x, [:arglist, [:int, 1]]], :y, [:arglist]]
end
end

describe "Operator precedence" do
it "should be raised with parentheses" do
opal_parse("(1 + 2) + (3 - 4)").should == [:call,
parsed("(1 + 2) + (3 - 4)").should == [:call,
[:paren, [:call, [:int, 1], :+, [:arglist, [:int, 2]]]],
:+,
[:arglist, [:paren, [:call, [:int, 3], :-, [:arglist, [:int, 4]]]]],
]
opal_parse("(1 + 2) - (3 - 4)").should == [:call,
parsed("(1 + 2) - (3 - 4)").should == [:call,
[:paren, [:call, [:int, 1], :+, [:arglist, [:int, 2]]]],
:-,
[:arglist, [:paren, [:call, [:int, 3], :-, [:arglist, [:int, 4]]]]],
]
opal_parse("(1 + 2) * (3 - 4)").should == [:call,
parsed("(1 + 2) * (3 - 4)").should == [:call,
[:paren, [:call, [:int, 1], :+, [:arglist, [:int, 2]]]],
:*,
[:arglist, [:paren, [:call, [:int, 3], :-, [:arglist, [:int, 4]]]]],
]
opal_parse("(1 + 2) / (3 - 4)").should == [:call,
parsed("(1 + 2) / (3 - 4)").should == [:call,
[:paren, [:call, [:int, 1], :+, [:arglist, [:int, 2]]]],
:/,
[:arglist, [:paren, [:call, [:int, 3], :-, [:arglist, [:int, 4]]]]],
@@ -113,7 +113,7 @@

it "should correctly parse the keyword as a method name when after a '.'" do
keywords.each do |kw|
opal_parse("self.#{kw}").should == [:call, [:self], kw.to_sym, [:arglist]]
parsed("self.#{kw}").should == [:call, [:self], kw.to_sym, [:arglist]]
end
end
end
@@ -123,17 +123,17 @@

it "should correctly parse the operator as method name after '.'" do
operators.each do |op|
opal_parse("self.#{op}").should == [:call, [:self], op.to_sym, [:arglist]]
opal_parse("self.#{op}(1)").should == [:call, [:self], op.to_sym, [:arglist, [:int, 1]]]
opal_parse("self.#{op}(1, 2)").should == [:call, [:self], op.to_sym, [:arglist, [:int, 1], [:int, 2]]]
parsed("self.#{op}").should == [:call, [:self], op.to_sym, [:arglist]]
parsed("self.#{op}(1)").should == [:call, [:self], op.to_sym, [:arglist, [:int, 1]]]
parsed("self.#{op}(1, 2)").should == [:call, [:self], op.to_sym, [:arglist, [:int, 1], [:int, 2]]]
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]]]
parsed("self #{mid}\nself").should == [:call, [:self], mid, [:arglist, [:self]]]
end
end
end
Loading