Sha256: 0b5a2e8c0135f771146774a72b6c5bd96b9e913d23539cfa4c2422b0412ce541

Contents?: true

Size: 1.21 KB

Versions: 26

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, [:lit, 1]]]
    opal_parse('bar.foo = 1').should == [:attrasgn, [:call, nil, :bar, [:arglist]], :foo=, [:arglist, [:lit, 1]]]
    opal_parse('@bar.foo = 1').should == [:attrasgn, [:ivar, :@bar], :foo=, [:arglist, [:lit, 1]]]
  end

  it "accepts both '.' and '::' for method call operators" do
    opal_parse('self.foo = 1').should == [:attrasgn, [:self], :foo=, [:arglist, [:lit, 1]]]
    opal_parse('self::foo = 1').should == [:attrasgn, [:self], :foo=, [:arglist, [:lit, 1]]]
  end

  it "can accept a constant as assignable name when using '.'" do
    opal_parse('self.FOO = 1').should == [:attrasgn, [:self], :FOO=, [:arglist, [:lit, 1]]]
  end

  describe "when setting element reference" do
    it "uses []= as the method call" do
      opal_parse('self[1] = 2').should == [:attrasgn, [:self], :[]=, [:arglist, [:lit, 1], [:lit, 2]]]
    end

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

Version data entries

26 entries across 26 versions & 1 rubygems

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