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