diff --git a/test/stdlib/json/JSONBigDecimal_test.rb b/test/stdlib/json/JSONBigDecimal_test.rb index e63c9b4599..9187ae6639 100644 --- a/test/stdlib/json/JSONBigDecimal_test.rb +++ b/test/stdlib/json/JSONBigDecimal_test.rb @@ -1,5 +1,6 @@ require_relative "../test_helper" require "json" +return if Gem::Version.new(JSON::VERSION).release >= Gem::Version.new("3.0.0") require "json/add/bigdecimal" class JSONBigDecimalSingletonTest < Test::Unit::TestCase diff --git a/test/stdlib/json/JSONComplex_test.rb b/test/stdlib/json/JSONComplex_test.rb index b9fc36772b..055c2c371b 100644 --- a/test/stdlib/json/JSONComplex_test.rb +++ b/test/stdlib/json/JSONComplex_test.rb @@ -1,5 +1,6 @@ require_relative "../test_helper" require "json" +return if Gem::Version.new(JSON::VERSION).release >= Gem::Version.new("3.0.0") require "json/add/complex" class JSONComplexSingletonTest < Test::Unit::TestCase diff --git a/test/stdlib/json/JSONDateTime_test.rb b/test/stdlib/json/JSONDateTime_test.rb index fd3c50d632..3aedb9d15c 100644 --- a/test/stdlib/json/JSONDateTime_test.rb +++ b/test/stdlib/json/JSONDateTime_test.rb @@ -1,5 +1,6 @@ require_relative "../test_helper" require "json" +return if Gem::Version.new(JSON::VERSION).release >= Gem::Version.new("3.0.0") require "json/add/date_time" class JSONDateTimeSingletonTest < Test::Unit::TestCase diff --git a/test/stdlib/json/JSONDate_test.rb b/test/stdlib/json/JSONDate_test.rb index a2d317fa19..c331762fb0 100644 --- a/test/stdlib/json/JSONDate_test.rb +++ b/test/stdlib/json/JSONDate_test.rb @@ -1,5 +1,6 @@ require_relative "../test_helper" require "json" +return if Gem::Version.new(JSON::VERSION).release >= Gem::Version.new("3.0.0") require "json/add/date" class JSONDateSingletonTest < Test::Unit::TestCase diff --git a/test/stdlib/json/JSONException_test.rb b/test/stdlib/json/JSONException_test.rb index 42cf2c408b..060de5b9f2 100644 --- a/test/stdlib/json/JSONException_test.rb +++ b/test/stdlib/json/JSONException_test.rb @@ -1,5 +1,6 @@ require_relative "../test_helper" require "json" +return if Gem::Version.new(JSON::VERSION).release >= Gem::Version.new("3.0.0") require "json/add/exception" class JSONExceptionSingletonTest < Test::Unit::TestCase diff --git a/test/stdlib/json/JSONOpenStruct_test.rb b/test/stdlib/json/JSONOpenStruct_test.rb index 4aacb54810..28ed9b54d4 100644 --- a/test/stdlib/json/JSONOpenStruct_test.rb +++ b/test/stdlib/json/JSONOpenStruct_test.rb @@ -1,5 +1,6 @@ require_relative "../test_helper" require "json" +return if Gem::Version.new(JSON::VERSION).release >= Gem::Version.new("3.0.0") require "json/add/ostruct" class JSONOpenStructSingletonTest < Test::Unit::TestCase diff --git a/test/stdlib/json/JSONRange_test.rb b/test/stdlib/json/JSONRange_test.rb index e5a7ba2a1c..807b5158f6 100644 --- a/test/stdlib/json/JSONRange_test.rb +++ b/test/stdlib/json/JSONRange_test.rb @@ -1,5 +1,6 @@ require_relative "../test_helper" require "json" +return if Gem::Version.new(JSON::VERSION).release >= Gem::Version.new("3.0.0") require "json/add/range" class JSONRangeSingletonTest < Test::Unit::TestCase diff --git a/test/stdlib/json/JSONRational_test.rb b/test/stdlib/json/JSONRational_test.rb index 61c9fa697d..0d81ccc7b7 100644 --- a/test/stdlib/json/JSONRational_test.rb +++ b/test/stdlib/json/JSONRational_test.rb @@ -1,5 +1,6 @@ require_relative "../test_helper" require "json" +return if Gem::Version.new(JSON::VERSION).release >= Gem::Version.new("3.0.0") require "json/add/rational" class JSONRationalSingletonTest < Test::Unit::TestCase diff --git a/test/stdlib/json/JSONRegexp_test.rb b/test/stdlib/json/JSONRegexp_test.rb index b30b794153..c2bb62f853 100644 --- a/test/stdlib/json/JSONRegexp_test.rb +++ b/test/stdlib/json/JSONRegexp_test.rb @@ -1,5 +1,6 @@ require_relative "../test_helper" require "json" +return if Gem::Version.new(JSON::VERSION).release >= Gem::Version.new("3.0.0") require "json/add/regexp" class JSONRegexpSingletonTest < Test::Unit::TestCase diff --git a/test/stdlib/json/JSONSet_test.rb b/test/stdlib/json/JSONSet_test.rb index 339c83950c..d75a057ced 100644 --- a/test/stdlib/json/JSONSet_test.rb +++ b/test/stdlib/json/JSONSet_test.rb @@ -1,5 +1,6 @@ require_relative "../test_helper" require "json" +return if Gem::Version.new(JSON::VERSION).release >= Gem::Version.new("3.0.0") require "json/add/set" class JSONSetSingletonTest < Test::Unit::TestCase diff --git a/test/stdlib/json/JSONStruct_test.rb b/test/stdlib/json/JSONStruct_test.rb index 422c9a8152..3c606eeb90 100644 --- a/test/stdlib/json/JSONStruct_test.rb +++ b/test/stdlib/json/JSONStruct_test.rb @@ -1,5 +1,6 @@ require_relative "../test_helper" require "json" +return if Gem::Version.new(JSON::VERSION).release >= Gem::Version.new("3.0.0") require "json/add/struct" class JSONStructSingletonTest < Test::Unit::TestCase diff --git a/test/stdlib/json/JSONSymbol_test.rb b/test/stdlib/json/JSONSymbol_test.rb index e1dc006c0e..080bc3afd0 100644 --- a/test/stdlib/json/JSONSymbol_test.rb +++ b/test/stdlib/json/JSONSymbol_test.rb @@ -1,5 +1,6 @@ require_relative "../test_helper" require "json" +return if Gem::Version.new(JSON::VERSION).release >= Gem::Version.new("3.0.0") require "json/add/symbol" class JSONSymbolSingletonTest < Test::Unit::TestCase diff --git a/test/stdlib/json/JSONTime_test.rb b/test/stdlib/json/JSONTime_test.rb index 53fc174b17..f62eca79eb 100644 --- a/test/stdlib/json/JSONTime_test.rb +++ b/test/stdlib/json/JSONTime_test.rb @@ -1,5 +1,6 @@ require_relative "../test_helper" require "json" +return if Gem::Version.new(JSON::VERSION).release >= Gem::Version.new("3.0.0") require "json/add/time" class JSONTimeSingletonTest < Test::Unit::TestCase diff --git a/test/stdlib/json/JSON_test.rb b/test/stdlib/json/JSON_test.rb index 8b63cfe389..80004feaac 100644 --- a/test/stdlib/json/JSON_test.rb +++ b/test/stdlib/json/JSON_test.rb @@ -2,6 +2,12 @@ require "json" require "tempfile" +module JSONVersionTestHelper + def json_version_3_or_later? + Gem::Version.new(JSON::VERSION).release >= Gem::Version.new("3.0.0") + end +end + class JsonToStr def initialize(value = "") @value = value @@ -24,6 +30,7 @@ def to_s class JSONSingletonTest < Test::Unit::TestCase include TestHelper + include JSONVersionTestHelper library "json" testing "singleton(::JSON)" @@ -36,6 +43,8 @@ def test_aref end def test_create_id + omit_if json_version_3_or_later? + JSON.create_id = JsonToS.new("json_class") assert_send_type "() -> _ToS", JSON, :create_id JSON.create_id = "json_class" @@ -43,16 +52,21 @@ def test_create_id end def test_create_id_eq + omit_if json_version_3_or_later? + assert_send_type "(_ToS) -> _ToS", JSON, :create_id=, JsonToS.new("json_class") assert_send_type "(String) -> String", JSON, :create_id=, "json_class" end def test_dump assert_send_type "(ToJson) -> String", JSON, :dump, ToJson.new - assert_send_type "(ToJson, Integer) -> String", JSON, :dump, ToJson.new, 100 assert_send_type "(ToJson, JsonToWritableIO) -> JsonWrite", JSON, :dump, ToJson.new, JsonToWritableIO.new assert_send_type "(ToJson, JsonWrite) -> JsonWrite", JSON, :dump, ToJson.new, JsonWrite.new - assert_send_type "(ToJson, JsonWrite, Integer) -> JsonWrite", JSON, :dump, ToJson.new, JsonWrite.new, 100 + + unless json_version_3_or_later? + assert_send_type "(ToJson, Integer) -> String", JSON, :dump, ToJson.new, 100 + assert_send_type "(ToJson, JsonWrite, Integer) -> JsonWrite", JSON, :dump, ToJson.new, JsonWrite.new, 100 + end end def test_generate @@ -74,7 +88,10 @@ def test_load assert_send_type "(JsonToReadableIO) -> 42", JSON, :load, JsonToReadableIO.new assert_send_type "(JsonRead) -> 42", JSON, :load, JsonRead.new assert_send_type "(String, Proc) -> 42", JSON, :load, "42", proc { |a| a } - assert_send_type "(String, Proc, Hash[untyped, untyped]) -> 42", JSON, :load, "42", proc { |a| a }, { alllow_nan: true } + + unless json_version_3_or_later? + assert_send_type "(String, Proc, Hash[untyped, untyped]) -> 42", JSON, :load, "42", proc { |a| a }, { alllow_nan: true } + end end def test_load_file @@ -83,7 +100,9 @@ def test_load_file f.close assert_send_type "(String) -> untyped", JSON, :load_file, f.path - assert_send_type "(String, Hash[untyped, untyped]) -> untyped", JSON, :load_file, f.path, { allow_nan: true } + unless json_version_3_or_later? + assert_send_type "(String, Hash[untyped, untyped]) -> untyped", JSON, :load_file, f.path, { allow_nan: true } + end end end @@ -93,20 +112,26 @@ def test_load_file! f.close assert_send_type "(String) -> untyped", JSON, :load_file!, f.path - assert_send_type "(String, Hash[untyped, untyped]) -> untyped", JSON, :load_file!, f.path, { allow_nan: true } + unless json_version_3_or_later? + assert_send_type "(String, Hash[untyped, untyped]) -> untyped", JSON, :load_file!, f.path, { allow_nan: true } + end end end def test_parse assert_send_type "(String) -> 42", JSON, :parse, "42" assert_send_type "(_ToStr) -> 42", JSON, :parse, JsonToStr.new("42") - assert_send_type "(String, Hash[untyped, untyped]) -> 42", JSON, :parse, "42", { allow_nan: true } + unless json_version_3_or_later? + assert_send_type "(String, Hash[untyped, untyped]) -> 42", JSON, :parse, "42", { allow_nan: true } + end end def test_parse! assert_send_type "(String) -> 42", JSON, :parse!, "42" assert_send_type "(_ToStr) -> 42", JSON, :parse!, JsonToStr.new("42") - assert_send_type "(String, Hash[untyped, untyped]) -> 42", JSON, :parse!, "42", { allow_nan: true } + unless json_version_3_or_later? + assert_send_type "(String, Hash[untyped, untyped]) -> 42", JSON, :parse!, "42", { allow_nan: true } + end end def test_parser @@ -133,6 +158,7 @@ def test_state_eq class JSONInstanceTest < Test::Unit::TestCase include TestHelper + include JSONVersionTestHelper class MyJSON include JSON @@ -147,10 +173,13 @@ def load_default_options def test_dump assert_send_type "(ToJson) -> String", MyJSON.new, :dump, ToJson.new - assert_send_type "(ToJson, Integer) -> String", MyJSON.new, :dump, ToJson.new, 100 assert_send_type "(ToJson, JsonToWritableIO) -> JsonWrite", MyJSON.new, :dump, ToJson.new, JsonToWritableIO.new assert_send_type "(ToJson, JsonWrite) -> JsonWrite", MyJSON.new, :dump, ToJson.new, JsonWrite.new - assert_send_type "(ToJson, JsonWrite, Integer) -> JsonWrite", MyJSON.new, :dump, ToJson.new, JsonWrite.new, 100 + + unless json_version_3_or_later? + assert_send_type "(ToJson, Integer) -> String", MyJSON.new, :dump, ToJson.new, 100 + assert_send_type "(ToJson, JsonWrite, Integer) -> JsonWrite", MyJSON.new, :dump, ToJson.new, JsonWrite.new, 100 + end end def test_generate @@ -161,13 +190,17 @@ def test_generate def test_parse assert_send_type "(String) -> 42", MyJSON.new, :parse, "42" assert_send_type "(_ToStr) -> 42", MyJSON.new, :parse, JsonToStr.new("42") - assert_send_type "(String, Hash[untyped, untyped]) -> 42", MyJSON.new, :parse, "42", { allow_nan: true } + unless json_version_3_or_later? + assert_send_type "(String, Hash[untyped, untyped]) -> 42", MyJSON.new, :parse, "42", { allow_nan: true } + end end def test_parse! assert_send_type "(String) -> 42", MyJSON.new, :parse!, "42" assert_send_type "(_ToStr) -> 42", MyJSON.new, :parse!, JsonToStr.new("42") - assert_send_type "(String, Hash[untyped, untyped]) -> 42", MyJSON.new, :parse!, "42", { allow_nan: true } + unless json_version_3_or_later? + assert_send_type "(String, Hash[untyped, untyped]) -> 42", MyJSON.new, :parse!, "42", { allow_nan: true } + end end def test_pretty_generate