Skip to content
Merged
52 changes: 9 additions & 43 deletions stdlib/json/0/json.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ end
class JSON::GeneratorError < JSON::JSONError
end

class JSON::UnparserError < JSON::GeneratorError
end

# <!-- rdoc-file=ext/json/lib/json/common.rb -->
# This exception is raised if a parser error occurs.
#
Expand Down Expand Up @@ -754,13 +751,15 @@ module JSON
# opts = JSON.dump_default_options
# opts # => {:max_nesting=>false, :allow_nan=>true}
#
%a{deprecated}
def self.dump_default_options: () -> options

# <!-- rdoc-file=ext/json/lib/json/common.rb -->
# Sets or returns the default options for the JSON.dump method. Initially:
# opts = JSON.dump_default_options
# opts # => {:max_nesting=>false, :allow_nan=>true}
#
%a{deprecated}
def self.dump_default_options=: (options) -> options

# <!--
Expand All @@ -778,12 +777,9 @@ module JSON
# # Raises SystemStackError (stack level too deep):
# JSON.fast_generate(a)
#
%a{deprecated}
def self?.fast_generate: (_ToJson obj, ?options opts) -> String

alias self.fast_unparse self.fast_generate

alias fast_unparse fast_generate

# <!--
# rdoc-file=ext/json/lib/json/common.rb
# - JSON.generate(obj, opts = nil) -> new_string
Expand Down Expand Up @@ -830,14 +826,6 @@ module JSON

def self.generator=: (generator generator) -> void

# <!--
# rdoc-file=ext/json/lib/json/common.rb
# - iconv(to, from, string)
# -->
# Encodes string using String.encode.
#
def self.iconv: (encoding to, encoding from, String string) -> String

# <!--
# rdoc-file=ext/json/lib/json/common.rb
# - JSON.load(source, proc = nil, options = {}) -> object
Expand Down Expand Up @@ -974,7 +962,8 @@ module JSON
# #<Admin:0x00000000064c41f8
# @attributes={"type"=>"Admin", "password"=>"0wn3d"}>}
#
def self?.load: (string | _ReadableIO | _Read source, ?Proc proc, ?options options) -> untyped
def self?.load: (string | _ReadableIO | _Read source, ?options options) -> untyped
| [T] (string | _ReadableIO | _Read source, ^(?) -> T, ?options options) -> T

# <!--
# rdoc-file=ext/json/lib/json/common.rb
Expand Down Expand Up @@ -1003,13 +992,15 @@ module JSON
# opts = JSON.load_default_options
# opts # => {:max_nesting=>false, :allow_nan=>true, :allow_blank=>true, :create_additions=>true}
#
%a{deprecated}
def self.load_default_options: () -> options

# <!-- rdoc-file=ext/json/lib/json/common.rb -->
# Sets or returns default options for the JSON.load method. Initially:
# opts = JSON.load_default_options
# opts # => {:max_nesting=>false, :allow_nan=>true, :allow_blank=>true, :create_additions=>true}
#
%a{deprecated}
def self.load_default_options=: (options) -> options

# <!--
Expand Down Expand Up @@ -1120,29 +1111,6 @@ module JSON
#
def self?.pretty_generate: (_ToJson obj, ?options opts) -> untyped

alias self.pretty_unparse self.pretty_generate

alias pretty_unparse pretty_generate

# Recursively calls passed *Proc* if the parsed data structure is an *Array* or
# *Hash*
#
def self?.recurse_proc: (untyped result) { (*untyped) -> void } -> void

# <!--
# rdoc-file=ext/json/lib/json/common.rb
# - restore(source, proc = nil, options = nil)
# -->
#
alias self.restore self.load

# <!--
# rdoc-file=ext/json/lib/json/common.rb
# - restore(source, proc = nil, options = nil)
# -->
#
alias restore load

# <!-- rdoc-file=ext/json/lib/json/common.rb -->
# Sets or Returns the JSON generator state class that is used by JSON.
#
Expand All @@ -1152,10 +1120,6 @@ module JSON
# Sets or Returns the JSON generator state class that is used by JSON.
#
def self.state=: (state) -> state

alias self.unparse self.generate

alias unparse generate
end

JSON::FAST_STATE_PROTOTYPE: JSON::state
Expand Down Expand Up @@ -1193,6 +1157,7 @@ module Kernel
# Outputs *objs* to STDOUT as JSON strings in the shortest form, that is in one
# line.
#
%a{deprecated}
def j: (*_ToJson) -> nil

# <!--
Expand All @@ -1202,6 +1167,7 @@ module Kernel
# Outputs *objs* to STDOUT as JSON strings in a pretty format, with indentation
# and over many lines.
#
%a{deprecated}
def jj: (*_ToJson) -> nil

# <!--
Expand Down
22 changes: 0 additions & 22 deletions test/stdlib/json/JSONKernel_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,6 @@ class JSONKernelInstanceTest < Test::Unit::TestCase
library "json"
testing "::Kernel"

def silent
orig_stdout = $stdout
$stdout = StringIO.new
yield
ensure
$stdout = orig_stdout
end

def test_j
silent do
assert_send_type("(Integer) -> nil", self, :j, 1)
assert_send_type("(Array[Integer]) -> nil", self, :j, [1, 2, 3])
end
end

def test_jj
silent do
assert_send_type("(Integer) -> nil", self, :jj, 1)
assert_send_type("(Array[Integer]) -> nil", self, :jj, [1, 2, 3])
end
end

def test_JSON
assert_send_type("(String) -> Hash[String, Integer]", self, :JSON, '{"a": 1}')
assert_send_type("(Array[Integer]) -> String", self, :JSON, [1, 2, 3])
Expand Down
104 changes: 2 additions & 102 deletions test/stdlib/json/JSON_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,27 +61,6 @@ def test_dump
assert_send_type "(ToJson, JsonWrite, Integer) -> JsonWrite", JSON, :dump, ToJson.new, JsonWrite.new, 100
end

def test_dump_default_options
assert_send_type "() -> { max_nesting: false, allow_nan: true }", JSON, :dump_default_options
end

def test_dump_default_options_eq
assert_send_type "(max_nesting: false, allow_nan: true, allow_blank: true) -> { max_nesting: false, allow_nan: true, allow_blank: true }",
JSON,
:dump_default_options=,
{ max_nesting: false, allow_nan: true, allow_blank: true }
end

def test_fast_generate
assert_send_type "(ToJson) -> String", JSON, :fast_generate, ToJson.new
assert_send_type "(ToJson, indent: String) -> String", JSON, :fast_generate, ToJson.new, { indent: "\t" }
end

def test_fast_unparse
assert_send_type "(ToJson) -> String", JSON, :fast_unparse, ToJson.new
assert_send_type "(ToJson, indent: String) -> String", JSON, :fast_unparse, ToJson.new, { indent: "\t" }
end

def test_generate
assert_send_type "(ToJson) -> String", JSON, :generate, ToJson.new
assert_send_type "(ToJson, indent: String) -> String", JSON, :generate, ToJson.new, { indent: "\t" }
Expand All @@ -95,19 +74,13 @@ def test_generator=
assert_send_type "(singleton(JSON::Ext::Generator)) -> void", JSON, :generator=, JSON::Ext::Generator
end

def test_iconv
assert_send_type "(Encoding, Encoding, String) -> String", JSON, :iconv, Encoding::UTF_8, Encoding::UTF_16, "".encode(Encoding::UTF_16)
assert_send_type "(String, String, String) -> String", JSON, :iconv, 'UTF-8', 'UTF-16', "".encode(Encoding::UTF_16)
assert_send_type "(_ToStr, _ToStr, String) -> String", JSON, :iconv, JsonToStr.new('UTF-8'), JsonToStr.new('UTF-16'), "".encode(Encoding::UTF_16)
end

def test_load
assert_send_type "(String) -> 42", JSON, :load, "42"
assert_send_type "(_ToStr) -> 42", JSON, :load, JsonToStr.new("42")
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 { }
assert_send_type "(String, Proc, Hash[untyped, untyped]) -> 42", JSON, :load, "42", proc { }, { alllow_nan: true }
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 }
end

def test_load_file
Expand All @@ -130,14 +103,6 @@ def test_load_file!
end
end

def test_load_default_options
assert_send_type "() -> Hash[untyped, untyped]", JSON, :load_default_options
end

def test_load_default_options_eq
assert_send_type "(allow_nan: true) -> Hash[untyped, untyped]", JSON, :load_default_options=, { allow_nan: true }
end

def test_parse
assert_send_type "(String) -> 42", JSON, :parse, "42"
assert_send_type "(_ToStr) -> 42", JSON, :parse, JsonToStr.new("42")
Expand All @@ -163,36 +128,13 @@ def test_pretty_generate
assert_send_type "(ToJson, indent: String) -> String", JSON, :pretty_generate, ToJson.new, { indent: "\t" }
end

def test_pretty_unparse
assert_send_type "(ToJson) -> String", JSON, :pretty_unparse, ToJson.new
assert_send_type "(ToJson, indent: String) -> String", JSON, :pretty_unparse, ToJson.new, { indent: "\t" }
end

def test_recurse_proc
assert_send_type "(Integer) { (Integer) -> void } -> void", JSON, :recurse_proc, 42 do |_i| end
end

def test_restore
assert_send_type "(String) -> 42", JSON, :restore, "42"
assert_send_type "(_ToStr) -> 42", JSON, :restore, JsonToStr.new("42")
assert_send_type "(JsonToReadableIO) -> 42", JSON, :restore, JsonToReadableIO.new
assert_send_type "(JsonRead) -> 42", JSON, :restore, JsonRead.new
assert_send_type "(String, Proc) -> 42", JSON, :restore, "42", proc { }
assert_send_type "(String, Proc, Hash[untyped, untyped]) -> 42", JSON, :restore, "42", proc { }, { alllow_nan: true }
end

def test_state
assert_send_type "() -> singleton(JSON::Ext::Generator::State)", JSON, :state
end

def test_state_eq
assert_send_type "(singleton(JSON::Ext::Generator::State)) -> singleton(JSON::Ext::Generator::State)", JSON, :state=, JSON::Ext::Generator::State
end

def test_unparse
assert_send_type "(ToJson) -> String", JSON, :unparse, ToJson.new
assert_send_type "(ToJson, indent: String) -> String", JSON, :unparse, ToJson.new, { indent: "\t" }
end
end

class JSONInstanceTest < Test::Unit::TestCase
Expand All @@ -217,30 +159,11 @@ def test_dump
assert_send_type "(ToJson, JsonWrite, Integer) -> JsonWrite", MyJSON.new, :dump, ToJson.new, JsonWrite.new, 100
end

def test_fast_generate
assert_send_type "(ToJson) -> String", MyJSON.new, :fast_generate, ToJson.new
assert_send_type "(ToJson, indent: String) -> String", MyJSON.new, :fast_generate, ToJson.new, { indent: "\t" }
end

def test_fast_unparse
assert_send_type "(ToJson) -> String", MyJSON.new, :fast_unparse, ToJson.new
assert_send_type "(ToJson, indent: String) -> String", MyJSON.new, :fast_unparse, ToJson.new, { indent: "\t" }
end

def test_generate
assert_send_type "(ToJson) -> String", MyJSON.new, :generate, ToJson.new
assert_send_type "(ToJson, indent: String) -> String", MyJSON.new, :generate, ToJson.new, { indent: "\t" }
end

def test_load
assert_send_type "(String) -> 42", MyJSON.new, :load, "42"
assert_send_type "(_ToStr) -> 42", MyJSON.new, :load, JsonToStr.new("42")
assert_send_type "(JsonToReadableIO) -> 42", MyJSON.new, :load, JsonToReadableIO.new
assert_send_type "(JsonRead) -> 42", MyJSON.new, :load, JsonRead.new
assert_send_type "(String, Proc) -> 42", MyJSON.new, :load, "42", proc { }
assert_send_type "(String, Proc, Hash[untyped, untyped]) -> 42", MyJSON.new, :load, "42", proc { }, { alllow_nan: true }
end

def test_parse
assert_send_type "(String) -> 42", MyJSON.new, :parse, "42"
assert_send_type "(_ToStr) -> 42", MyJSON.new, :parse, JsonToStr.new("42")
Expand All @@ -258,29 +181,6 @@ def test_pretty_generate
assert_send_type "(ToJson, indent: String) -> String", MyJSON.new, :pretty_generate, ToJson.new, { indent: "\t" }
end

def test_pretty_unparse
assert_send_type "(ToJson) -> String", MyJSON.new, :pretty_unparse, ToJson.new
assert_send_type "(ToJson, indent: String) -> String", MyJSON.new, :pretty_unparse, ToJson.new, { indent: "\t" }
end

def test_recurse_proc
assert_send_type "(Integer) { (Integer) -> void } -> void", MyJSON.new, :recurse_proc, 42 do |_i| end
end

def test_restore
assert_send_type "(String) -> 42", MyJSON.new, :restore, "42"
assert_send_type "(_ToStr) -> 42", MyJSON.new, :restore, JsonToStr.new("42")
assert_send_type "(JsonToReadableIO) -> 42", MyJSON.new, :restore, JsonToReadableIO.new
assert_send_type "(JsonRead) -> 42", MyJSON.new, :restore, JsonRead.new
assert_send_type "(String, Proc) -> 42", MyJSON.new, :restore, "42", proc { }
assert_send_type "(String, Proc, Hash[untyped, untyped]) -> 42", MyJSON.new, :restore, "42", proc { }, { alllow_nan: true }
end

def test_unparse
assert_send_type "(ToJson) -> String", MyJSON.new, :unparse, ToJson.new
assert_send_type "(ToJson, indent: String) -> String", MyJSON.new, :unparse, ToJson.new, { indent: "\t" }
end

def test_to_json_with_object
assert_send_type "() -> String", Object.new, :to_json
assert_send_type "(JSON::State) -> String", Object.new, :to_json, JSON::State.new
Expand Down