fedora-migrator /vendor/gems/facets-2.4.5/test/more/test_openobject.rb

Language Ruby Lines 113
MD5 Hash 7ec7b9d2b1df31b3a3a4436caa757960 Estimated Cost $2,131 (why?)
Repository https://bitbucket.org/mediashelf/fedora-migrator View Raw File
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
# Test facets/openobject.rb

require 'facets/openobject.rb'
require 'test/unit'

class TestOpenObject1 < Test::Unit::TestCase

  def test_1_01
    o = OpenObject.new
    assert( o.respond_to?(:key?) )
  end

  def test_1_02
    assert_instance_of( OpenObject, OpenObject[{}] )
  end

  def test_1_03
    f0 = OpenObject.new
    f0[:a] = 1
    #assert_equal( [1], f0.to_a )
    assert_equal( {:a=>1}, f0.to_h )
  end

  def test_1_04
    f0 = OpenObject[:a=>1]
    f0[:b] = 2
    assert_equal( {:a=>1,:b=>2}, f0.to_h )
  end

  def test_1_05
    f0 = OpenObject[:class=>1]
    assert_equal( 1, f0.class )
  end
end

class TestOpenObject2 < Test::Unit::TestCase

  def test_2_01
    f0 = OpenObject[:f0=>"f0"]
    h0 = { :h0=>"h0" }
    assert_equal( OpenObject[:f0=>"f0", :h0=>"h0"], f0.send(:merge,h0) )
    assert_equal( {:f0=>"f0", :h0=>"h0"}, h0.merge( f0 ) )
  end

  def test_2_02
    f1 = OpenObject[:f1=>"f1"]
    h1 = { :h1=>"h1" }
    f1.send(:update,h1)
    h1.update( f1 )
    assert_equal( OpenObject[:f1=>"f1", :h1=>"h1"], f1 )
    assert_equal( {:f1=>"f1", :h1=>"h1"}, h1 )
  end

  def test_2_03
    o = OpenObject[:a=>1,:b=>{:x=>9}]
    assert_equal( 9, o[:b][:x] )
    assert_equal( 9, o.b[:x] )
  end

  def test_2_04
    o = OpenObject["a"=>1,"b"=>{:x=>9}]
    assert_equal( 1, o["a"] )
    assert_equal( 1, o[:a] )
    assert_equal( {:x=>9}, o["b"] )
    assert_equal( {:x=>9}, o[:b] )
    assert_equal( 9, o["b"][:x] )
    assert_equal( nil, o[:b]["x"] )
  end

end

class TestOpenObject3 < Test::Unit::TestCase
  def test_3_01
    fo = OpenObject.new
    9.times{ |i| fo.send( "n#{i}=", 1 ) }
    9.times{ |i|
      assert_equal( 1, fo.send( "n#{i}" ) )
    }
  end
end

class TestOpenObject4 < Test::Unit::TestCase

  def test_4_01
    ho = {}
    fo = OpenObject.new
    5.times{ |i| ho["n#{i}".to_sym]=1 }
    5.times{ |i| fo.send( "n#{i}=", 1 ) }
    assert_equal(ho, fo.to_h)
  end

end

class TestOpenObject5 < Test::Unit::TestCase

  def test_5_01
    p = lambda { |x|
      x.word = "Hello"
    }
    o = p.to_openobject
    assert_equal( "Hello", o.word )
  end

  def test_5_02
    p = lambda { |x|
      x.word = "Hello"
    }
    o = OpenObject[:a=>1,:b=>2]
    assert_instance_of( Proc, o.to_proc )
  end

end
Back to Top