diff options
Diffstat (limited to 'activesupport/test/json')
-rw-r--r-- | activesupport/test/json/decoding_test.rb | 75 | ||||
-rw-r--r-- | activesupport/test/json/encoding_test.rb | 143 | ||||
-rw-r--r-- | activesupport/test/json/encoding_test_cases.rb | 28 |
3 files changed, 125 insertions, 121 deletions
diff --git a/activesupport/test/json/decoding_test.rb b/activesupport/test/json/decoding_test.rb index 887ef1681d..de314921ec 100644 --- a/activesupport/test/json/decoding_test.rb +++ b/activesupport/test/json/decoding_test.rb @@ -1,7 +1,7 @@ -require 'abstract_unit' -require 'active_support/json' -require 'active_support/time' -require 'time_zone_test_helpers' +require "abstract_unit" +require "active_support/json" +require "active_support/time" +require "time_zone_test_helpers" class TestJSONDecoding < ActiveSupport::TestCase include TimeZoneTestHelpers @@ -22,22 +22,22 @@ class TestJSONDecoding < ActiveSupport::TestCase %({"a": "a's, b's and c's", "b": "5,000"}) => {"a" => "a's, b's and c's", "b" => "5,000"}, # multibyte %({"matzue": "松江", "asakusa": "浅草"}) => {"matzue" => "松江", "asakusa" => "浅草"}, - %({"a": "2007-01-01"}) => {'a' => Date.new(2007, 1, 1)}, - %({"a": "2007-01-01 01:12:34 Z"}) => {'a' => Time.utc(2007, 1, 1, 1, 12, 34)}, + %({"a": "2007-01-01"}) => {"a" => Date.new(2007, 1, 1)}, + %({"a": "2007-01-01 01:12:34 Z"}) => {"a" => Time.utc(2007, 1, 1, 1, 12, 34)}, %(["2007-01-01 01:12:34 Z"]) => [Time.utc(2007, 1, 1, 1, 12, 34)], %(["2007-01-01 01:12:34 Z", "2007-01-01 01:12:35 Z"]) => [Time.utc(2007, 1, 1, 1, 12, 34), Time.utc(2007, 1, 1, 1, 12, 35)], # no time zone - %({"a": "2007-01-01 01:12:34"}) => {'a' => Time.new(2007, 1, 1, 1, 12, 34, "-05:00")}, + %({"a": "2007-01-01 01:12:34"}) => {"a" => Time.new(2007, 1, 1, 1, 12, 34, "-05:00")}, # invalid date - %({"a": "1089-10-40"}) => {'a' => "1089-10-40"}, + %({"a": "1089-10-40"}) => {"a" => "1089-10-40"}, # xmlschema date notation - %({"a": "2009-08-10T19:01:02"}) => {'a' => Time.new(2009, 8, 10, 19, 1, 2, "-04:00")}, - %({"a": "2009-08-10T19:01:02Z"}) => {'a' => Time.utc(2009, 8, 10, 19, 1, 2)}, - %({"a": "2009-08-10T19:01:02+02:00"}) => {'a' => Time.utc(2009, 8, 10, 17, 1, 2)}, - %({"a": "2009-08-10T19:01:02-05:00"}) => {'a' => Time.utc(2009, 8, 11, 00, 1, 2)}, + %({"a": "2009-08-10T19:01:02"}) => {"a" => Time.new(2009, 8, 10, 19, 1, 2, "-04:00")}, + %({"a": "2009-08-10T19:01:02Z"}) => {"a" => Time.utc(2009, 8, 10, 19, 1, 2)}, + %({"a": "2009-08-10T19:01:02+02:00"}) => {"a" => Time.utc(2009, 8, 10, 17, 1, 2)}, + %({"a": "2009-08-10T19:01:02-05:00"}) => {"a" => Time.utc(2009, 8, 11, 00, 1, 2)}, # needs to be *exact* - %({"a": " 2007-01-01 01:12:34 Z "}) => {'a' => " 2007-01-01 01:12:34 Z "}, - %({"a": "2007-01-01 : it's your birthday"}) => {'a' => "2007-01-01 : it's your birthday"}, + %({"a": " 2007-01-01 01:12:34 Z "}) => {"a" => " 2007-01-01 01:12:34 Z "}, + %({"a": "2007-01-01 : it's your birthday"}) => {"a" => "2007-01-01 : it's your birthday"}, %([]) => [], %({}) => {}, %({"a":1}) => {"a" => 1}, @@ -46,37 +46,37 @@ class TestJSONDecoding < ActiveSupport::TestCase %({"a": null}) => {"a" => nil}, %({"a": true}) => {"a" => true}, %({"a": false}) => {"a" => false}, - %q({"bad":"\\\\","trailing":""}) => {"bad" => "\\", "trailing" => ""}, + '{"bad":"\\\\","trailing":""}' => {"bad" => "\\", "trailing" => ""}, %q({"a": "http:\/\/test.host\/posts\/1"}) => {"a" => "http://test.host/posts/1"}, %q({"a": "\u003cunicode\u0020escape\u003e"}) => {"a" => "<unicode escape>"}, - %q({"a": "\\\\u0020skip double backslashes"}) => {"a" => "\\u0020skip double backslashes"}, - %q({"a": "\u003cbr /\u003e"}) => {'a' => "<br />"}, - %q({"b":["\u003ci\u003e","\u003cb\u003e","\u003cu\u003e"]}) => {'b' => ["<i>","<b>","<u>"]}, + '{"a": "\\\\u0020skip double backslashes"}' => {"a" => "\\u0020skip double backslashes"}, + %q({"a": "\u003cbr /\u003e"}) => {"a" => "<br />"}, + %q({"b":["\u003ci\u003e","\u003cb\u003e","\u003cu\u003e"]}) => {"b" => ["<i>","<b>","<u>"]}, # test combination of dates and escaped or unicode encoded data in arrays %q([{"d":"1970-01-01", "s":"\u0020escape"},{"d":"1970-01-01", "s":"\u0020escape"}]) => - [{'d' => Date.new(1970, 1, 1), 's' => ' escape'},{'d' => Date.new(1970, 1, 1), 's' => ' escape'}], + [{"d" => Date.new(1970, 1, 1), "s" => " escape"},{"d" => Date.new(1970, 1, 1), "s" => " escape"}], %q([{"d":"1970-01-01","s":"http:\/\/example.com"},{"d":"1970-01-01","s":"http:\/\/example.com"}]) => - [{'d' => Date.new(1970, 1, 1), 's' => 'http://example.com'}, - {'d' => Date.new(1970, 1, 1), 's' => 'http://example.com'}], + [{"d" => Date.new(1970, 1, 1), "s" => "http://example.com"}, + {"d" => Date.new(1970, 1, 1), "s" => "http://example.com"}], # tests escaping of "\n" char with Yaml backend %q({"a":"\n"}) => {"a"=>"\n"}, %q({"a":"\u000a"}) => {"a"=>"\n"}, %q({"a":"Line1\u000aLine2"}) => {"a"=>"Line1\nLine2"}, # prevent json unmarshalling - %q({"json_class":"TestJSONDecoding::Foo"}) => {"json_class"=>"TestJSONDecoding::Foo"}, + '{"json_class":"TestJSONDecoding::Foo"}' => {"json_class"=>"TestJSONDecoding::Foo"}, # json "fragments" - these are invalid JSON, but ActionPack relies on this - %q("a string") => "a string", - %q(1.1) => 1.1, - %q(1) => 1, - %q(-1) => -1, - %q(true) => true, - %q(false) => false, - %q(null) => nil + '"a string"' => "a string", + "1.1" => 1.1, + "1" => 1, + "-1" => -1, + "true" => true, + "false" => false, + "null" => nil } TESTS.each_with_index do |(json, expected), index| test "json decodes #{index}" do - with_tz_default 'Eastern Time (US & Canada)' do + with_tz_default "Eastern Time (US & Canada)" do with_parse_json_times(true) do silence_warnings do assert_equal expected, ActiveSupport::JSON.decode(json), "JSON decoding \ @@ -107,12 +107,11 @@ class TestJSONDecoding < ActiveSupport::TestCase private - def with_parse_json_times(value) - old_value = ActiveSupport.parse_json_times - ActiveSupport.parse_json_times = value - yield - ensure - ActiveSupport.parse_json_times = old_value - end + def with_parse_json_times(value) + old_value = ActiveSupport.parse_json_times + ActiveSupport.parse_json_times = value + yield + ensure + ActiveSupport.parse_json_times = old_value + end end - diff --git a/activesupport/test/json/encoding_test.rb b/activesupport/test/json/encoding_test.rb index 5fc2e16336..9c95bf35b8 100644 --- a/activesupport/test/json/encoding_test.rb +++ b/activesupport/test/json/encoding_test.rb @@ -1,17 +1,21 @@ -require 'securerandom' -require 'abstract_unit' -require 'active_support/core_ext/string/inflections' -require 'active_support/json' -require 'active_support/time' -require 'time_zone_test_helpers' -require 'json/encoding_test_cases' +require "securerandom" +require "abstract_unit" +require "active_support/core_ext/string/inflections" +require "active_support/core_ext/regexp" +require "active_support/json" +require "active_support/time" +require "time_zone_test_helpers" +require "json/encoding_test_cases" class TestJSONEncoding < ActiveSupport::TestCase include TimeZoneTestHelpers def sorted_json(json) - return json unless json =~ /^\{.*\}$/ - '{' + json[1..-2].split(',').sort.join(',') + '}' + if json.start_with?("{") && json.end_with?("}") + "{" + json[1..-2].split(",").sort.join(",") + "}" + else + json + end end JSONTest::EncodingTestCases.constants.each do |class_tests| @@ -19,8 +23,10 @@ class TestJSONEncoding < ActiveSupport::TestCase begin prev = ActiveSupport.use_standard_json_time_format - ActiveSupport.escape_html_entities_in_json = class_tests !~ /^Standard/ - ActiveSupport.use_standard_json_time_format = class_tests =~ /^Standard/ + standard_class_tests = /Standard/.match?(class_tests) + + ActiveSupport.escape_html_entities_in_json = !standard_class_tests + ActiveSupport.use_standard_json_time_format = standard_class_tests JSONTest::EncodingTestCases.const_get(class_tests).each do |pair| assert_equal pair.last, sorted_json(ActiveSupport::JSON.encode(pair.first)) end @@ -41,12 +47,12 @@ class TestJSONEncoding < ActiveSupport::TestCase end def test_hash_encoding - assert_equal %({\"a\":\"b\"}), ActiveSupport::JSON.encode(:a => :b) - assert_equal %({\"a\":1}), ActiveSupport::JSON.encode('a' => 1) - assert_equal %({\"a\":[1,2]}), ActiveSupport::JSON.encode('a' => [1,2]) + assert_equal %({\"a\":\"b\"}), ActiveSupport::JSON.encode(a: :b) + assert_equal %({\"a\":1}), ActiveSupport::JSON.encode("a" => 1) + assert_equal %({\"a\":[1,2]}), ActiveSupport::JSON.encode("a" => [1,2]) assert_equal %({"1":2}), ActiveSupport::JSON.encode(1 => 2) - assert_equal %({\"a\":\"b\",\"c\":\"d\"}), sorted_json(ActiveSupport::JSON.encode(:a => :b, :c => :d)) + assert_equal %({\"a\":\"b\",\"c\":\"d\"}), sorted_json(ActiveSupport::JSON.encode(a: :b, c: :d)) end def test_hash_keys_encoding @@ -57,24 +63,24 @@ class TestJSONEncoding < ActiveSupport::TestCase end def test_utf8_string_encoded_properly - result = ActiveSupport::JSON.encode('€2.99') + result = ActiveSupport::JSON.encode("€2.99") assert_equal '"€2.99"', result assert_equal(Encoding::UTF_8, result.encoding) - result = ActiveSupport::JSON.encode('✎☺') + result = ActiveSupport::JSON.encode("✎☺") assert_equal '"✎☺"', result assert_equal(Encoding::UTF_8, result.encoding) end def test_non_utf8_string_transcodes - s = '二'.encode('Shift_JIS') + s = "二".encode("Shift_JIS") result = ActiveSupport::JSON.encode(s) assert_equal '"二"', result assert_equal Encoding::UTF_8, result.encoding end def test_wide_utf8_chars - w = '𠜎' + w = "𠜎" result = ActiveSupport::JSON.encode(w) assert_equal '"𠜎"', result end @@ -83,7 +89,7 @@ class TestJSONEncoding < ActiveSupport::TestCase hash = { string: "𐒑" } json = ActiveSupport::JSON.encode(hash) decoded_hash = ActiveSupport::JSON.decode(json) - assert_equal "𐒑", decoded_hash['string'] + assert_equal "𐒑", decoded_hash["string"] end def test_hash_key_identifiers_are_always_quoted @@ -92,16 +98,16 @@ class TestJSONEncoding < ActiveSupport::TestCase end def test_hash_should_allow_key_filtering_with_only - assert_equal %({"a":1}), ActiveSupport::JSON.encode({'a' => 1, :b => 2, :c => 3}, :only => 'a') + assert_equal %({"a":1}), ActiveSupport::JSON.encode({"a" => 1, :b => 2, :c => 3}, only: "a") end def test_hash_should_allow_key_filtering_with_except - assert_equal %({"b":2}), ActiveSupport::JSON.encode({'foo' => 'bar', :b => 2, :c => 3}, :except => ['foo', :c]) + assert_equal %({"b":2}), ActiveSupport::JSON.encode({"foo" => "bar", :b => 2, :c => 3}, except: ["foo", :c]) end def test_time_to_json_includes_local_offset with_standard_json_time_format(true) do - with_env_tz 'US/Eastern' do + with_env_tz "US/Eastern" do assert_equal %("2005-02-01T15:15:10.000-05:00"), ActiveSupport::JSON.encode(Time.local(2005,2,1,15,15,10)) end end @@ -109,7 +115,7 @@ class TestJSONEncoding < ActiveSupport::TestCase def test_hash_with_time_to_json with_standard_json_time_format(false) do - assert_equal '{"time":"2009/01/01 00:00:00 +0000"}', { :time => Time.utc(2009) }.to_json + assert_equal '{"time":"2009/01/01 00:00:00 +0000"}', { time: Time.utc(2009) }.to_json end end @@ -117,8 +123,8 @@ class TestJSONEncoding < ActiveSupport::TestCase assert_nothing_raised do hash = { "CHI" => { - :display_name => "chicago", - :latitude => 123.234 + display_name: "chicago", + latitude: 123.234 } } ActiveSupport::JSON.encode(hash) @@ -127,7 +133,7 @@ class TestJSONEncoding < ActiveSupport::TestCase def test_hash_like_with_options h = JSONTest::Hashlike.new - json = h.to_json :only => [:foo] + json = h.to_json only: [:foo] assert_equal({"foo"=>"hello"}, JSON.parse(json)) end @@ -136,7 +142,7 @@ class TestJSONEncoding < ActiveSupport::TestCase obj = Object.new obj.instance_variable_set :@foo, "hello" obj.instance_variable_set :@bar, "world" - json = obj.to_json :only => ["foo"] + json = obj.to_json only: ["foo"] assert_equal({"foo"=>"hello"}, JSON.parse(json)) end @@ -145,46 +151,46 @@ class TestJSONEncoding < ActiveSupport::TestCase struct = Struct.new(:foo, :bar).new struct.foo = "hello" struct.bar = "world" - json = struct.to_json :only => [:foo] + json = struct.to_json only: [:foo] assert_equal({"foo"=>"hello"}, JSON.parse(json)) end def test_hash_should_pass_encoding_options_to_children_in_as_json person = { - :name => 'John', - :address => { - :city => 'London', - :country => 'UK' + name: "John", + address: { + city: "London", + country: "UK" } } - json = person.as_json :only => [:address, :city] + json = person.as_json only: [:address, :city] - assert_equal({ 'address' => { 'city' => 'London' }}, json) + assert_equal({ "address" => { "city" => "London" }}, json) end def test_hash_should_pass_encoding_options_to_children_in_to_json person = { - :name => 'John', - :address => { - :city => 'London', - :country => 'UK' + name: "John", + address: { + city: "London", + country: "UK" } } - json = person.to_json :only => [:address, :city] + json = person.to_json only: [:address, :city] assert_equal(%({"address":{"city":"London"}}), json) end def test_array_should_pass_encoding_options_to_children_in_as_json people = [ - { :name => 'John', :address => { :city => 'London', :country => 'UK' }}, - { :name => 'Jean', :address => { :city => 'Paris' , :country => 'France' }} + { name: "John", address: { city: "London", country: "UK" }}, + { name: "Jean", address: { city: "Paris" , country: "France" }} ] - json = people.as_json :only => [:address, :city] + json = people.as_json only: [:address, :city] expected = [ - { 'address' => { 'city' => 'London' }}, - { 'address' => { 'city' => 'Paris' }} + { "address" => { "city" => "London" }}, + { "address" => { "city" => "Paris" }} ] assert_equal(expected, json) @@ -192,10 +198,10 @@ class TestJSONEncoding < ActiveSupport::TestCase def test_array_should_pass_encoding_options_to_children_in_to_json people = [ - { :name => 'John', :address => { :city => 'London', :country => 'UK' }}, - { :name => 'Jean', :address => { :city => 'Paris' , :country => 'France' }} + { name: "John", address: { city: "London", country: "UK" }}, + { name: "Jean", address: { city: "Paris" , country: "France" }} ] - json = people.to_json :only => [:address, :city] + json = people.to_json only: [:address, :city] assert_equal(%([{"address":{"city":"London"}},{"address":{"city":"Paris"}}]), json) end @@ -204,8 +210,8 @@ class TestJSONEncoding < ActiveSupport::TestCase include Enumerable def initialize() @people = [ - { :name => 'John', :address => { :city => 'London', :country => 'UK' }}, - { :name => 'Jean', :address => { :city => 'Paris' , :country => 'France' }} + { name: "John", address: { city: "London", country: "UK" }}, + { name: "Jean", address: { city: "Paris" , country: "France" }} ] end def each(*, &blk) @@ -217,32 +223,32 @@ class TestJSONEncoding < ActiveSupport::TestCase end def test_enumerable_should_generate_json_with_as_json - json = People.new.as_json :only => [:address, :city] + json = People.new.as_json only: [:address, :city] expected = [ - { 'address' => { 'city' => 'London' }}, - { 'address' => { 'city' => 'Paris' }} + { "address" => { "city" => "London" }}, + { "address" => { "city" => "Paris" }} ] assert_equal(expected, json) end def test_enumerable_should_generate_json_with_to_json - json = People.new.to_json :only => [:address, :city] + json = People.new.to_json only: [:address, :city] assert_equal(%([{"address":{"city":"London"}},{"address":{"city":"Paris"}}]), json) end def test_enumerable_should_pass_encoding_options_to_children_in_as_json - json = People.new.each.as_json :only => [:address, :city] + json = People.new.each.as_json only: [:address, :city] expected = [ - { 'address' => { 'city' => 'London' }}, - { 'address' => { 'city' => 'Paris' }} + { "address" => { "city" => "London" }}, + { "address" => { "city" => "Paris" }} ] assert_equal(expected, json) end def test_enumerable_should_pass_encoding_options_to_children_in_to_json - json = People.new.each.to_json :only => [:address, :city] + json = People.new.each.to_json only: [:address, :city] assert_equal(%([{"address":{"city":"London"}},{"address":{"city":"Paris"}}]), json) end @@ -293,13 +299,12 @@ class TestJSONEncoding < ActiveSupport::TestCase end def test_struct_encoding - Struct.new('UserNameAndEmail', :name, :email) - Struct.new('UserNameAndDate', :name, :date) - Struct.new('Custom', :name, :sub) - user_email = Struct::UserNameAndEmail.new 'David', 'sample@example.com' - user_birthday = Struct::UserNameAndDate.new 'David', Date.new(2010, 01, 01) - custom = Struct::Custom.new 'David', user_birthday - + Struct.new("UserNameAndEmail", :name, :email) + Struct.new("UserNameAndDate", :name, :date) + Struct.new("Custom", :name, :sub) + user_email = Struct::UserNameAndEmail.new "David", "sample@example.com" + user_birthday = Struct::UserNameAndDate.new "David", Date.new(2010, 01, 01) + custom = Struct::Custom.new "David", user_birthday json_strings = "" json_string_and_date = "" @@ -376,7 +381,7 @@ EXPECTED def test_twz_to_json_with_use_standard_json_time_format_config_set_to_false with_standard_json_time_format(false) do - zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)'] + zone = ActiveSupport::TimeZone["Eastern Time (US & Canada)"] time = ActiveSupport::TimeWithZone.new(Time.utc(2000), zone) assert_equal "\"1999/12/31 19:00:00 -0500\"", ActiveSupport::JSON.encode(time) end @@ -384,7 +389,7 @@ EXPECTED def test_twz_to_json_with_use_standard_json_time_format_config_set_to_true with_standard_json_time_format(true) do - zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)'] + zone = ActiveSupport::TimeZone["Eastern Time (US & Canada)"] time = ActiveSupport::TimeWithZone.new(Time.utc(2000), zone) assert_equal "\"1999-12-31T19:00:00.000-05:00\"", ActiveSupport::JSON.encode(time) end @@ -393,7 +398,7 @@ EXPECTED def test_twz_to_json_with_custom_time_precision with_standard_json_time_format(true) do with_time_precision(0) do - zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)'] + zone = ActiveSupport::TimeZone["Eastern Time (US & Canada)"] time = ActiveSupport::TimeWithZone.new(Time.utc(2000), zone) assert_equal "\"1999-12-31T19:00:00-05:00\"", ActiveSupport::JSON.encode(time) end @@ -417,7 +422,7 @@ EXPECTED end def test_twz_to_json_when_wrapping_a_date_time - zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)'] + zone = ActiveSupport::TimeZone["Eastern Time (US & Canada)"] time = ActiveSupport::TimeWithZone.new(DateTime.new(2000), zone) assert_equal '"1999-12-31T19:00:00.000-05:00"', ActiveSupport::JSON.encode(time) end diff --git a/activesupport/test/json/encoding_test_cases.rb b/activesupport/test/json/encoding_test_cases.rb index e043fadf56..f8c44f314f 100644 --- a/activesupport/test/json/encoding_test_cases.rb +++ b/activesupport/test/json/encoding_test_cases.rb @@ -1,4 +1,4 @@ -require 'bigdecimal' +require "bigdecimal" module JSONTest class Foo @@ -9,7 +9,7 @@ module JSONTest class Hashlike def to_hash - { :foo => "hello", :bar => "world" } + { foo: "hello", bar: "world" } end end @@ -39,20 +39,20 @@ module JSONTest [ 0.0/0.0, %(null) ], [ 1.0/0.0, %(null) ], [ -1.0/0.0, %(null) ], - [ BigDecimal('0.0')/BigDecimal('0.0'), %(null) ], - [ BigDecimal('2.5'), %("#{BigDecimal('2.5')}") ]] + [ BigDecimal("0.0")/BigDecimal("0.0"), %(null) ], + [ BigDecimal("2.5"), %("#{BigDecimal('2.5')}") ]] - StringTests = [[ 'this is the <string>', %("this is the \\u003cstring\\u003e")], + StringTests = [[ "this is the <string>", %("this is the \\u003cstring\\u003e")], [ 'a "string" with quotes & an ampersand', %("a \\"string\\" with quotes \\u0026 an ampersand") ], - [ 'http://test.host/posts/1', %("http://test.host/posts/1")], + [ "http://test.host/posts/1", %("http://test.host/posts/1")], [ "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\"]) ], - [ [1, 'a', :b, nil, false], %([1,\"a\",\"b\",null,false]) ]] + 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}) ]] + [ {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")], @@ -67,18 +67,18 @@ module JSONTest 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(nil), "null" ], [ Custom.new(:a), '"a"' ], [ Custom.new([ :foo, "bar" ]), '["foo","bar"]' ], - [ Custom.new({ :foo => "hello", :bar => "world" }), '{"bar":"world","foo":"hello"}' ], + [ Custom.new(foo: "hello", bar: "world"), '{"bar":"world","foo":"hello"}' ], [ Custom.new(Hashlike.new), '{"bar":"world","foo":"hello"}' ], [ Custom.new(Custom.new(Custom.new(:a))), '"a"' ]] RegexpTests = [[ /^a/, '"(?-mix:^a)"' ], [/^\w{1,2}[a-z]+/ix, '"(?ix-m:^\\\\w{1,2}[a-z]+)"']] - URITests = [[ URI.parse('http://example.com'), %("http://example.com") ]] + URITests = [[ URI.parse("http://example.com"), %("http://example.com") ]] - PathnameTests = [[ Pathname.new('lib/index.rb'), %("lib/index.rb") ]] + PathnameTests = [[ Pathname.new("lib/index.rb"), %("lib/index.rb") ]] DateTests = [[ Date.new(2005,2,1), %("2005/02/01") ]] TimeTests = [[ Time.utc(2005,2,1,15,15,10), %("2005/02/01 15:15:10 +0000") ]] @@ -87,6 +87,6 @@ module JSONTest StandardDateTests = [[ Date.new(2005,2,1), %("2005-02-01") ]] StandardTimeTests = [[ Time.utc(2005,2,1,15,15,10), %("2005-02-01T15:15:10.000Z") ]] StandardDateTimeTests = [[ DateTime.civil(2005,2,1,15,15,10), %("2005-02-01T15:15:10.000+00:00") ]] - StandardStringTests = [[ 'this is the <string>', %("this is the <string>")]] + StandardStringTests = [[ "this is the <string>", %("this is the <string>")]] end end |