summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorFlorian Frank <flori@ping.de>2011-05-12 10:31:40 +0200
committerFlorian Frank <flori@ping.de>2011-05-12 10:31:40 +0200
commit67fbd5bbf2119830d6b0038e1f5e571cb9e21563 (patch)
tree0805c64fb55aacf5b2f294afb0ddeb849306bd15 /tests
parent4f8f7d24fb1cc3bcbe493a2ce625eea488f23dda (diff)
downloadjson-67fbd5bbf2119830d6b0038e1f5e571cb9e21563.tar.gz
Don't optimize calls for ducktypes
Diffstat (limited to 'tests')
-rwxr-xr-xtests/test_json.rb29
1 files changed, 29 insertions, 0 deletions
diff --git a/tests/test_json.rb b/tests/test_json.rb
index 06ee581..3c8477a 100755
--- a/tests/test_json.rb
+++ b/tests/test_json.rb
@@ -208,6 +208,28 @@ class TC_JSON < Test::Unit::TestCase
end
end
+ class MyArray < Array
+ def to_json(*a)
+ {
+ JSON.create_id => self.class.name,
+ data => self,
+ }.to_json(*a)
+ end
+
+ def self.json_create(o)
+ self[*o['data']]
+ end
+
+ def <<(v)
+ @shifted = true
+ super
+ end
+
+ def shifted?
+ @shifted
+ end
+ end
+
def test_parse_object_custom_class
res = parse('{"foo":"bar"}', :object_class => SubHash2)
assert_equal({"foo" => "bar"}, res)
@@ -226,6 +248,13 @@ class TC_JSON < Test::Unit::TestCase
assert_equal ["foo"], JSON(JSON(SubArray2["foo"]))
end
+ def test_parse_array_custom_class
+ res = parse('["foo","bar"]', :array_class => MyArray)
+ assert_equal(["foo", "bar"], res)
+ assert_equal(MyArray, res.class)
+ assert res.shifted?
+ end
+
def test_generation_of_core_subclasses_with_default_to_json
assert_equal '{"foo":"bar"}', JSON(SubHash["foo" => "bar"])
assert_equal '["foo"]', JSON(SubArray["foo"])