summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorFlorian Frank <flori@ping.de>2011-05-12 10:40:17 +0200
committerFlorian Frank <flori@ping.de>2011-05-12 10:40:17 +0200
commit0bca269860274d22908328cfe35b24d21a7e0188 (patch)
tree86d7ffd3835d050bfa4715d2e08c41bc2412b117 /tests
parent67fbd5bbf2119830d6b0038e1f5e571cb9e21563 (diff)
downloadjson-0bca269860274d22908328cfe35b24d21a7e0188.tar.gz
Fix duplicate test
Diffstat (limited to 'tests')
-rwxr-xr-xtests/test_json.rb58
1 files changed, 19 insertions, 39 deletions
diff --git a/tests/test_json.rb b/tests/test_json.rb
index 3c8477a..4fc6a28 100755
--- a/tests/test_json.rb
+++ b/tests/test_json.rb
@@ -154,7 +154,16 @@ class TC_JSON < Test::Unit::TestCase
, [2718.0E-3 ],\r[ null] , [[1, -2, 3 ]], [false ],[ true]\n ] }))
end
- class SubArray < Array; end
+ class SubArray < Array
+ def <<(v)
+ @shifted = true
+ super
+ end
+
+ def shifted?
+ @shifted
+ end
+ end
class SubArray2 < Array
def to_json(*a)
@@ -171,9 +180,10 @@ class TC_JSON < Test::Unit::TestCase
end
def test_parse_array_custom_class
- res = parse('[]', :array_class => SubArray)
- assert_equal([], res)
+ res = parse('[1,2]', :array_class => SubArray)
+ assert_equal([1,2], res)
assert_equal(SubArray, res.class)
+ assert res.shifted?
end
def test_parse_object
@@ -184,20 +194,6 @@ class TC_JSON < Test::Unit::TestCase
end
class SubHash < Hash
- end
-
- class SubHash2 < Hash
- def to_json(*a)
- {
- JSON.create_id => self.class.name,
- }.merge(self).to_json(*a)
- end
-
- def self.json_create(o)
- o.delete JSON.create_id
- self[o]
- end
-
def []=(k, v)
@item_set = true
super
@@ -208,32 +204,23 @@ class TC_JSON < Test::Unit::TestCase
end
end
- class MyArray < Array
+ class SubHash2 < Hash
def to_json(*a)
{
JSON.create_id => self.class.name,
- data => self,
- }.to_json(*a)
+ }.merge(self).to_json(*a)
end
def self.json_create(o)
- self[*o['data']]
- end
-
- def <<(v)
- @shifted = true
- super
- end
-
- def shifted?
- @shifted
+ o.delete JSON.create_id
+ self[o]
end
end
def test_parse_object_custom_class
- res = parse('{"foo":"bar"}', :object_class => SubHash2)
+ res = parse('{"foo":"bar"}', :object_class => SubHash)
assert_equal({"foo" => "bar"}, res)
- assert_equal(SubHash2, res.class)
+ assert_equal(SubHash, res.class)
assert res.item_set?
end
@@ -248,13 +235,6 @@ 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"])