Sha256: e55fe1d81bce636a1c5932ab9b95dfd8f983aa211273ddab8a74db15440046fa

Contents?: true

Size: 915 Bytes

Versions: 13

Compression:

Stored size: 915 Bytes

Contents

# -*- coding: utf-8 -*-


require_relative 'helper'


class TestUniversalAccessor < Test::Unit::TestCase

  class Accessor

    attr_accessor :val

    attr_reader :args

    def args=(*args)
      @args = args
    end

    universal_accessor :val, :args

  end# Accessor

  def accessor(*args)
    Accessor.new(*args)
  end

  def test_accessor()
    a = accessor
    assert_equal nil, a.val

    a.val 1
    assert_equal 1, a.val
    assert_equal 2, a.val(2)

    a.val = 3
    assert_equal 3, a.val
  end

  def test_accessor_splat_args()
    a = accessor

    a.args =   1, 2, 3;  assert_equal [[1, 2, 3]], a.args
    a.args =  [1, 2, 3]; assert_equal [[1, 2, 3]], a.args
    a.args = *[1, 2, 3]; assert_equal [[1, 2, 3]], a.args

    assert_equal  [1, 2, 3],  a.args(  1, 2, 3)
    assert_equal [[1, 2, 3]], a.args( [1, 2, 3])
    assert_equal  [1, 2, 3],  a.args(*[1, 2, 3])
  end

end# TestUniversalAccessor

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
xot-0.1.34 test/test_universal_accessor.rb
xot-0.1.33 test/test_universal_accessor.rb
xot-0.1.32 test/test_universal_accessor.rb
xot-0.1.31 test/test_universal_accessor.rb
xot-0.1.30 test/test_universal_accessor.rb
xot-0.1.29 test/test_universal_accessor.rb
xot-0.1.28 test/test_universal_accessor.rb
xot-0.1.27 test/test_universal_accessor.rb
xot-0.1.26 test/test_universal_accessor.rb
xot-0.1.25 test/test_universal_accessor.rb
xot-0.1.24 test/test_universal_accessor.rb
xot-0.1.23 test/test_universal_accessor.rb
xot-0.1.22 test/test_universal_accessor.rb