Class: TestRecursiveOpenStruct

Inherits:
Test::Unit::TestCase
  • Object
show all
Defined in:
lib/Recursive_Open_Struct.rb

Instance Method Summary collapse

Instance Method Details

#setAndAssertValue(val) ⇒ Object



148
149
150
151
152
153
154
155
# File 'lib/Recursive_Open_Struct.rb', line 148

def setAndAssertValue(val)
  @s.test = val
  assert_equal(val, @s.test)
  @s.close
  assert_equal(val, @s.test)
  @s.test = "asdf"
  assert_equal("asdf", @s.test)
end

#setupObject



144
145
146
# File 'lib/Recursive_Open_Struct.rb', line 144

def setup
  @s = Recursive_Open_Struct.new
end

#testAttrsObject



194
195
196
197
198
199
# File 'lib/Recursive_Open_Struct.rb', line 194

def testAttrs
  assert_equal([], @s.attrs)
  @s.b = "x"
  @s.a = "a"
  assert_equal(["a", "b"], @s.attrs)
end

#testDeepObject



224
225
226
227
228
229
230
231
# File 'lib/Recursive_Open_Struct.rb', line 224

def testDeep
  @s.a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q.r.s.t.u.v.w.x.y.z = false
  @s.close
  assert_raise(NoMethodError) do
    @s.blub = "hellow"
  end
  assert_equal(false, @s.a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q.r.s.t.u.v.w.x.y.z)
end

#testKlammerObject



215
216
217
218
219
220
221
222
# File 'lib/Recursive_Open_Struct.rb', line 215

def testKlammer
  @s.a = "asdf"
  assert_equal("asdf", @s["a"])
  @s.b_x = "hog"
  assert_equal("hog", @s["b_x"])
  @s.c.b.a = 1234
  assert_equal(1234, @s["c"]["b"]["a"])
end

#testRaiseTypeErrorObject



187
188
189
190
191
192
# File 'lib/Recursive_Open_Struct.rb', line 187

def testRaiseTypeError
  @s.a.b = 1
  assert_raise(TypeError) do
    @s.a = 3
  end
end

#testRecursiveObject



201
202
203
204
205
# File 'lib/Recursive_Open_Struct.rb', line 201

def testRecursive
  @s.a.b = 1
  @s.a.c = 2
  assert_equal(["a"], @s.attrs)
end

#testSet0Object



183
184
185
# File 'lib/Recursive_Open_Struct.rb', line 183

def testSet0
  setAndAssertValue(0)
end

#testSetClassObject



175
176
177
# File 'lib/Recursive_Open_Struct.rb', line 175

def testSetClass
  setAndAssertValue(String)
end

#testSetFalseObject



167
168
169
# File 'lib/Recursive_Open_Struct.rb', line 167

def testSetFalse
  setAndAssertValue(false)
end

#testSetNilObject



157
158
159
# File 'lib/Recursive_Open_Struct.rb', line 157

def testSetNil
  setAndAssertValue(nil)
end

#testSetStrObject



171
172
173
# File 'lib/Recursive_Open_Struct.rb', line 171

def testSetStr
  setAndAssertValue("topfen")
end

#testSetTrueObject



179
180
181
# File 'lib/Recursive_Open_Struct.rb', line 179

def testSetTrue
  setAndAssertValue(true)
end

#testSimpleObject



161
162
163
164
165
# File 'lib/Recursive_Open_Struct.rb', line 161

def testSimple
  @s.test = "xx"
  @s.close
  assert_equal("xx", @s.test)
end

#testStrangeObject



207
208
209
210
211
212
213
# File 'lib/Recursive_Open_Struct.rb', line 207

def testStrange
  @s.a
  assert_equal(["a"], @s.attrs)
  assert_equal(Recursive_Open_Struct, @s.a.class)
  @s.a.x = "asfd"
  assert_equal("asfd", @s.a.x)
end