Module: Hash::Slop::Etest

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

Instance Method Summary collapse

Instance Method Details

#test_nil_entriesObject



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/vex/base/hash/slop.rb', line 110

def test_nil_entries
  h = { :a => nil, :b => false, :c => 1 }
  h.slop!
  
  assert_equal true, h.a?
  assert_equal true, h.b?
  assert_equal 1, h.c?
  assert_equal nil, h.d?

  assert_equal nil, h.a
  assert_equal false, h.b
  assert_equal 1, h.c
  assert_raises(NoMethodError) {
    h.d
  }
end

#test_slop_assignsObject



142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/vex/base/hash/slop.rb', line 142

def test_slop_assigns
  h = { :a => { "b" => "ccc" }}
  h.slop!
  
  h.a = 2
  
  assert_equal({ :a => 2}, h)
  
  h.b = 2
  assert_equal({ :a => 2, :b => 2}, h)

  v = { :c => { :d => 2 } }
  assert !v.sloppy?
  
  h.b = v.dup
  assert_equal(2, h.b.c.d)
  assert !v.sloppy?
  assert h.b.sloppy?
end

#test_slop_hashesObject



95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/vex/base/hash/slop.rb', line 95

def test_slop_hashes
  h = { :a => { "b" => "ccc" }}
  h1 = h.slop!
  assert h.sloppy?
  assert h1.sloppy?
  
  assert_equal("ccc", h.a.b)
  assert h1.object_id == h.object_id

  assert h.a?
  assert !h.b?
  assert h.a.b?
  assert !h.a.c?
end

#test_slop_hashes_2Object



127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/vex/base/hash/slop.rb', line 127

def test_slop_hashes_2
  h = { :a => { "b" => "ccc" }}
  h1 = h.slop
  assert !h.sloppy?
  assert h1.sloppy?
  
  assert_equal("ccc", h1.a.b)
  assert h1.object_id != h.object_id

  assert h1.a?
  assert !h1.b?
  assert h1.a.b?
  assert !h1.a.c?
end