diff options
author | Florian Frank <flori@ping.de> | 2011-12-20 23:05:15 +0100 |
---|---|---|
committer | Florian Frank <flori@ping.de> | 2011-12-20 23:05:15 +0100 |
commit | aa7feb07b68e13ce2e024669873a8a6a89f304dc (patch) | |
tree | 6c11497c2c6e417cbb56705fb96c7366e6fc58fb /tests | |
parent | dec1286737e8d9c3d61ec9f6726a88d65592f48e (diff) | |
download | json-aa7feb07b68e13ce2e024669873a8a6a89f304dc.tar.gz |
Support duck typed ruby array in JRuby as well
Diffstat (limited to 'tests')
-rwxr-xr-x | tests/test_json.rb | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/tests/test_json.rb b/tests/test_json.rb index fe21475..c06fd19 100755 --- a/tests/test_json.rb +++ b/tests/test_json.rb @@ -219,13 +219,41 @@ class TC_JSON < Test::Unit::TestCase end end - def test_parse_array_custom_class + class SubArrayWrapper + def initialize + @data = [] + end + + attr_reader :data + + def [](index) + @data[index] + end + + def <<(value) + @data << value + @shifted = true + end + + def shifted? + @shifted + end + end + + def test_parse_array_custom_array_derived_class res = parse('[1,2]', :array_class => SubArray) assert_equal([1,2], res) assert_equal(SubArray, res.class) assert res.shifted? end + def test_parse_array_custom_non_array_derived_class + res = parse('[1,2]', :array_class => SubArrayWrapper) + assert_equal([1,2], res.data) + assert_equal(SubArrayWrapper, res.class) + assert res.shifted? + end + def test_parse_object assert_equal({}, parse('{}')) assert_equal({}, parse(' { } ')) |