Sha256: 3660ca40f7cab23ae5af1a926e89c100fdd8f61a06a9cce46d1f20e7d6204d21

Contents?: true

Size: 1.19 KB

Versions: 39

Compression:

Stored size: 1.19 KB

Contents

require 'support/parser_helpers'

describe "Attribute assignments" do
  it "should return a s(:attrasgn) for simple assignments" do
    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
    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
    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
      parsed('self[1] = 2').should == [:attrasgn, [:self], :[]=, [:arglist, [:int, 1], [:int, 2]]]
    end

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

Version data entries

39 entries across 39 versions & 3 rubygems

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