2003-09-04 12:18:59 -04:00
|
|
|
require 'test/unit'
|
|
|
|
|
|
|
|
class TestStruct < Test::Unit::TestCase
|
|
|
|
def test_struct
|
|
|
|
struct_test = Struct.new("Test", :foo, :bar)
|
2003-09-05 11:15:43 -04:00
|
|
|
assert_equal(Struct::Test, struct_test)
|
|
|
|
|
2003-09-04 12:18:59 -04:00
|
|
|
test = struct_test.new(1, 2)
|
2003-09-05 11:15:43 -04:00
|
|
|
assert_equal(1, test.foo)
|
|
|
|
assert_equal(2, test.bar)
|
|
|
|
assert_equal(1, test[0])
|
|
|
|
assert_equal(2, test[1])
|
|
|
|
|
2003-09-04 12:18:59 -04:00
|
|
|
a, b = test.to_a
|
2003-09-05 11:15:43 -04:00
|
|
|
assert_equal(1, a)
|
|
|
|
assert_equal(2, b)
|
|
|
|
|
2003-09-04 12:18:59 -04:00
|
|
|
test[0] = 22
|
2003-09-05 11:15:43 -04:00
|
|
|
assert_equal(22, test.foo)
|
|
|
|
|
2003-09-04 12:18:59 -04:00
|
|
|
test.bar = 47
|
2003-09-05 11:15:43 -04:00
|
|
|
assert_equal(47, test.bar)
|
|
|
|
end
|
2003-09-04 12:18:59 -04:00
|
|
|
end
|