Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions test/stdlib/json/JSONBigDecimal_test.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 1 addition & 0 deletions test/stdlib/json/JSONComplex_test.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 1 addition & 0 deletions test/stdlib/json/JSONDateTime_test.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 1 addition & 0 deletions test/stdlib/json/JSONDate_test.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 1 addition & 0 deletions test/stdlib/json/JSONException_test.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 1 addition & 0 deletions test/stdlib/json/JSONOpenStruct_test.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 1 addition & 0 deletions test/stdlib/json/JSONRange_test.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 1 addition & 0 deletions test/stdlib/json/JSONRational_test.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 1 addition & 0 deletions test/stdlib/json/JSONRegexp_test.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 1 addition & 0 deletions test/stdlib/json/JSONSet_test.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 1 addition & 0 deletions test/stdlib/json/JSONStruct_test.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 1 addition & 0 deletions test/stdlib/json/JSONSymbol_test.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 1 addition & 0 deletions test/stdlib/json/JSONTime_test.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
55 changes: 44 additions & 11 deletions test/stdlib/json/JSON_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -24,6 +30,7 @@ def to_s

class JSONSingletonTest < Test::Unit::TestCase
include TestHelper
include JSONVersionTestHelper

library "json"
testing "singleton(::JSON)"
Expand All @@ -36,23 +43,30 @@ 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"
assert_send_type "() -> String", JSON, :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
Expand All @@ -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
Expand All @@ -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

Expand All @@ -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
Expand All @@ -133,6 +158,7 @@ def test_state_eq

class JSONInstanceTest < Test::Unit::TestCase
include TestHelper
include JSONVersionTestHelper

class MyJSON
include JSON
Expand All @@ -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
Expand All @@ -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
Expand Down
Loading