Sha256: 49ff8b28f9ed242d02280fe25a8eb39e616cbb84b27dc99858c6cd745f886e84

Contents?: true

Size: 1.15 KB

Versions: 26

Compression:

Stored size: 1.15 KB

Contents

require 'spec_helper'

describe "Masgn" do
  describe "with a single lhs splat" do
    it "returns a s(:masgn)" do
      opal_parse('*a = 1, 2').first.should == :masgn
      opal_parse('* = 1, 2').first.should == :masgn
    end

    it "wraps splat inside a s(:array)" do
      opal_parse('*a = 1, 2')[1].should == [:array, [:splat, [:lasgn, :a]]]
      opal_parse('* = 1, 2')[1].should == [:array, [:splat]]
    end
  end

  describe "with more than 1 lhs item" do
    it "returns a s(:masgn) " do
      opal_parse('a, b = 1, 2').first.should == :masgn
    end

    it "collects all lhs args into an s(:array)" do
      opal_parse('a, b = 1, 2')[1].should == [:array, [:lasgn, :a], [:lasgn, :b]]
      opal_parse('@a, @b = 1, 2')[1].should == [:array, [:iasgn, :@a], [:iasgn, :@b]]
    end

    it "supports splat parts" do
      opal_parse('a, *b = 1, 2')[1].should == [:array, [:lasgn, :a], [:splat, [:lasgn, :b]]]
      opal_parse('@a, * = 1, 2')[1].should == [:array, [:iasgn, :@a], [:splat]]
    end
  end

  describe "with a single rhs argument" do
    it "should wrap rhs in an s(:to_ary)" do
      opal_parse('a, b = 1')[2].should == [:to_ary, [:lit, 1]]
    end
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
opal-0.4.3 spec/parser/masgn_spec.rb
opal-0.4.2 spec/parser/masgn_spec.rb
opal-0.4.1 spec/parser/masgn_spec.rb
opal-0.4.0 spec/parser/masgn_spec.rb
opal-0.3.44 spec/parser/masgn_spec.rb
opal-0.3.43 spec/parser/masgn_spec.rb
opal-0.3.42 spec/grammar/masgn_spec.rb
opal-0.3.41 spec/grammar/masgn_spec.rb
opal-0.3.40 spec/grammar/masgn_spec.rb
opal-0.3.39 spec/grammar/masgn_spec.rb
opal-0.3.38 spec/grammar/masgn_spec.rb
opal-0.3.37 spec/grammar/masgn_spec.rb
opal-0.3.36 spec/grammar/masgn_spec.rb
opal-0.3.35 spec/grammar/masgn_spec.rb
opal-0.3.34 spec/grammar/masgn_spec.rb
opal-0.3.33 spec/grammar/masgn_spec.rb
opal-0.3.32 spec/grammar/masgn_spec.rb
opal-0.3.31 spec/grammar/masgn_spec.rb
opal-0.3.30 spec/grammar/masgn_spec.rb
opal-0.3.29 spec/grammar/masgn_spec.rb