Sha256: e4861e0a444aa139f34222ad26795558f267ae7b5fa8ffe274f713d65fdbfa12

Contents?: true

Size: 1.19 KB

Versions: 5

Compression:

Stored size: 1.19 KB

Contents

require File.expand_path('../../spec_helper', __FILE__)

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

5 entries across 5 versions & 1 rubygems

Version Path
opal-0.3.20 spec/grammar/masgn_spec.rb
opal-0.3.19 spec/grammar/masgn_spec.rb
opal-0.3.18 spec/grammar/masgn_spec.rb
opal-0.3.17 test/grammar/masgn_spec.rb
opal-0.3.16 spec/grammar/masgn_spec.rb