aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/json
diff options
context:
space:
mode:
authorGodfrey Chan <godfreykfc@gmail.com>2015-07-11 12:19:39 -0700
committerGodfrey Chan <godfreykfc@gmail.com>2015-07-11 12:48:16 -0700
commit696a19fb9b82d961217d8cdba85773337bf15b17 (patch)
treea9c46d38cf1daca67d22d5f1f51da99c0ad0cbf4 /activesupport/test/json
parent2926d73e32519d5aae332a86ac3fb3ed320a140d (diff)
downloadrails-696a19fb9b82d961217d8cdba85773337bf15b17.tar.gz
rails-696a19fb9b82d961217d8cdba85773337bf15b17.tar.bz2
rails-696a19fb9b82d961217d8cdba85773337bf15b17.zip
Expand the JSON test coverage for Struct and Hash (?!)
Diffstat (limited to 'activesupport/test/json')
-rw-r--r--activesupport/test/json/encoding_test_cases.rb14
1 files changed, 13 insertions, 1 deletions
diff --git a/activesupport/test/json/encoding_test_cases.rb b/activesupport/test/json/encoding_test_cases.rb
index 00f2fcc207..0159ba8606 100644
--- a/activesupport/test/json/encoding_test_cases.rb
+++ b/activesupport/test/json/encoding_test_cases.rb
@@ -23,6 +23,13 @@ module JSONTest
end
end
+ class MyStruct < Struct.new(:name, :value)
+ def initialize(*)
+ @unused = "unused instance variable"
+ super
+ end
+ end
+
module EncodingTestCases
TrueTests = [[ true, %(true) ]]
FalseTests = [[ false, %(false) ]]
@@ -41,9 +48,12 @@ module JSONTest
[ "Control characters: \x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\u2028\u2029",
%("Control characters: \\u0000\\u0001\\u0002\\u0003\\u0004\\u0005\\u0006\\u0007\\b\\t\\n\\u000b\\f\\r\\u000e\\u000f\\u0010\\u0011\\u0012\\u0013\\u0014\\u0015\\u0016\\u0017\\u0018\\u0019\\u001a\\u001b\\u001c\\u001d\\u001e\\u001f\\u2028\\u2029") ]]
- ArrayTests = [[ ['a', 'b', 'c'], %([\"a\",\"b\",\"c\"]) ],
+ ArrayTests = [[ ['a', 'b', 'c'], %([\"a\",\"b\",\"c\"]) ],
[ [1, 'a', :b, nil, false], %([1,\"a\",\"b\",null,false]) ]]
+ HashTests = [[ {foo: "bar"}, %({\"foo\":\"bar\"}) ],
+ [ {1 => 1, 2 => 'a', 3 => :b, 4 => nil, 5 => false}, %({\"1\":1,\"2\":\"a\",\"3\":\"b\",\"4\":null,\"5\":false}) ]]
+
RangeTests = [[ 1..2, %("1..2")],
[ 1...2, %("1...2")],
[ 1.5..2.5, %("1.5..2.5")]]
@@ -54,6 +64,8 @@ module JSONTest
ObjectTests = [[ Foo.new(1, 2), %({\"a\":1,\"b\":2}) ]]
HashlikeTests = [[ Hashlike.new, %({\"bar\":\"world\",\"foo\":\"hello\"}) ]]
+ StructTests = [[ MyStruct.new(:foo, "bar"), %({\"name\":\"foo\",\"value\":\"bar\"}) ],
+ [ MyStruct.new(nil, nil), %({\"name\":null,\"value\":null}) ]]
CustomTests = [[ Custom.new("custom"), '"custom"' ],
[ Custom.new(nil), 'null' ],
[ Custom.new(:a), '"a"' ],