Sha256: 9bc0c67653d177de11e4411230fbc6969d250d5ad324fda2585ddf65846bcd7d

Contents?: true

Size: 1.53 KB

Versions: 20

Compression:

Stored size: 1.53 KB

Contents

require 'support/parser_helpers'

describe Opal::Parser do
  describe '-@' do
    context 'with an integer' do
      it "parses unary op. with the right precedence" do
        parsed("-1.hello").should == [:call, [:int, -1], :hello, [:arglist]]
        expected = [:call, [:call, [:int, 1], :**, [:arglist, [:int, 2]]], :-@, [:arglist]]
        parsed("-1 ** 2").should == expected
        expected = [:call, nil, :puts, [:arglist, [:call, [:int, -1], :hello, [:arglist]]]]
        parsed("puts -1.hello").should == expected
      end

      it "parses unary op. as a method call" do
        parsed("-1").should == [:int, -1]
      end

    end

    context 'with a float' do
      it "parses unary op. with the right precedence" do
        parsed("-1.23.hello").should == [:call, [:float, -1.23], :hello, [:arglist]]
      end

      it "parses unary op. as a method call" do
        parsed("-1.23").should == [:float, -1.23]
      end
    end
  end

  describe '+@' do
    context 'with an integer' do
      it "parses unary op. with the right precedence" do
        parsed("+1.hello").should == [:call, [:int, 1], :hello, [:arglist]]
      end

      it "parses unary op. as a method call" do
        parsed("-1").should == [:int, -1]
      end
    end

    context 'with a float' do
      it "parses unary op. with the right precedence" do
        parsed("+1.23.hello").should == [:call, [:float, 1.23], :hello, [:arglist]]
      end

      it "parses unary op. as a method call" do
        parsed("-1.23").should == [:float, -1.23]
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
opal-0.10.6 spec/lib/parser/unary_spec.rb
opal-0.10.6.beta spec/lib/parser/unary_spec.rb
opal-0.10.5 spec/lib/parser/unary_spec.rb
opal-0.10.4 spec/lib/parser/unary_spec.rb
opal-0.10.3 spec/lib/parser/unary_spec.rb
opal-0.10.2 spec/lib/parser/unary_spec.rb
opal-0.10.1 spec/lib/parser/unary_spec.rb
opal-0.10.0 spec/lib/parser/unary_spec.rb
opal-0.10.0.rc2 spec/lib/parser/unary_spec.rb
opal-0.9.4 spec/lib/parser/unary_spec.rb
opal-0.9.3 spec/lib/parser/unary_spec.rb
opal-0.10.0.rc1 spec/lib/parser/unary_spec.rb
opal-0.10.0.beta5 spec/lib/parser/unary_spec.rb
opal-0.10.0.beta4 spec/lib/parser/unary_spec.rb
opal-0.10.0.beta3 spec/lib/parser/unary_spec.rb
opal-0.10.0.beta2 spec/lib/parser/unary_spec.rb
opal-0.10.0.beta1 spec/lib/parser/unary_spec.rb
opal-0.9.2 spec/lib/parser/unary_spec.rb
opal-0.9.0 spec/lib/parser/unary_spec.rb
opal-0.9.0.rc1 spec/lib/parser/unary_spec.rb