Sha256: 46dd4a2da80b96d8e7bf1b1ef66cc027421bfa8dba615deb7ca9759cbe4bda2a

Contents?: true

Size: 1.21 KB

Versions: 5

Compression:

Stored size: 1.21 KB

Contents

require 'spec_helper'

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]]]
  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]]]
  end

  it "can accept a constant as assignable name when using '.'" do
    opal_parse('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]]]
    end

    it "supports multiple arguments inside brackets" do
      opal_parse('self[1, 2] = 3').should == [:attrasgn, [:self], :[]=, [:arglist, [:int, 1], [:int, 2], [:int, 3]]]
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
opal-0.5.5 spec/opal/parser/attrasgn_spec.rb
opal-0.5.4 spec/opal/parser/attrasgn_spec.rb
opal-0.5.2 spec/opal/parser/attrasgn_spec.rb
opal-0.5.0 spec/opal/parser/attrasgn_spec.rb
opal-0.4.4 spec/parser/attrasgn_spec.rb