Module: Hash::Extract::Etest

Defined in:
lib/vex/base/hash/extract.rb

Instance Method Summary collapse

Instance Method Details

#origObject



41
42
43
# File 'lib/vex/base/hash/extract.rb', line 41

def orig
  { 1 => 2, 3 => 4, 5 => 6}
end

#test_extractObject



36
37
38
39
# File 'lib/vex/base/hash/extract.rb', line 36

def test_extract
  h = { :a => "1", :b => "2" }
  assert_equal(h.extract(:a, :c), {:a => "1"})
end

#test_extract!Object



51
52
53
54
55
56
57
58
59
# File 'lib/vex/base/hash/extract.rb', line 51

def test_extract!
  h = orig
  assert_equal ({1=>2, 3 => 4}), h.extract!(1, 2, 3)
  assert_equal ({5 => 6}), h

  h = orig
  assert_equal ({1=>2, :a => 4}), h.extract!(1, 2, 3 => :a)
  assert_equal ({5 => 6}), h
end

#test_extract2Object



61
62
63
64
65
66
67
68
69
70
# File 'lib/vex/base/hash/extract.rb', line 61

def test_extract2
  assert_nothing_raised {  
    h = orig.freeze
    assert_equal ({1=>2, 3 => 4}), h.extract(1, 2, 3)
    assert_equal orig, h

    assert_equal ({1=>2, :a => 4}), h.extract(1, 2, 3 => :a)
    assert_equal orig, h
  }
end

#test_extract_w_delete!Object



45
46
47
48
49
# File 'lib/vex/base/hash/extract.rb', line 45

def test_extract_w_delete!
  h = orig
  assert_equal ({1=>2}), h.extract!(1, 2, 3 => nil)
  assert_equal ({5 => 6}), h
end