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
22 changes: 12 additions & 10 deletions stdlib/pp/0/pp.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ class PP < PrettyPrint
VERSION: String

interface _PrettyPrint
def pretty_print: (untyped q) -> untyped
def pretty_print: (untyped q) -> void

def pretty_print_cycle: (untyped q) -> untyped
def pretty_print_cycle: (untyped q) -> void

def is_a?: (Module) -> bool
end
Expand Down Expand Up @@ -127,7 +127,7 @@ class PP < PrettyPrint
# Object#pretty_print_cycle is used when `obj` is already printed, a.k.a the
# object reference chain has a cycle.
#
def pp: (_PrettyPrint obj) -> untyped
def pp: (_PrettyPrint obj) -> void

# <!--
# rdoc-file=lib/pp.rb
Expand Down Expand Up @@ -203,15 +203,15 @@ class PP < PrettyPrint
# -->
# A present standard failsafe for pretty printing any given Object
#
def pp_object: (untyped obj) -> untyped
def pp_object: (untyped obj) -> void

# <!--
# rdoc-file=lib/pp.rb
# - pp_hash(obj)
# -->
# A pretty print for a Hash
#
def pp_hash: (untyped obj) -> untyped
def pp_hash: (untyped obj) -> void
end
include PPMethods

Expand All @@ -220,13 +220,13 @@ class PP < PrettyPrint
end

module ObjectMixin : BasicObject
def pretty_print: (PP q) -> untyped
def pretty_print: (PP q) -> void

def pretty_print_cycle: (PP q) -> untyped
def pretty_print_cycle: (PP q) -> void

def pretty_print_instance_variables: () -> Array[Symbol]

def pretty_print_inspect: () -> untyped
def pretty_print_inspect: () -> String
end

# <!--
Expand Down Expand Up @@ -256,7 +256,8 @@ class PP < PrettyPrint
#
# PP.pp returns `out`.
#
def self.pp: (_PrettyPrint obj, ?_LeftShift out, ?Integer width) -> untyped
def self.pp: (_PrettyPrint obj) -> IO
| [T < _LeftShift] (_PrettyPrint obj, T out, ?Integer width) -> T

# <!--
# rdoc-file=lib/pp.rb
Expand All @@ -266,7 +267,8 @@ class PP < PrettyPrint
#
# PP.singleline_pp returns `out`.
#
def self.singleline_pp: (_PrettyPrint obj, ?_LeftShift out) -> untyped
def self.singleline_pp: (_PrettyPrint obj) -> IO
| [T < _LeftShift] (_PrettyPrint obj, T out) -> T
def self.mcall: (untyped obj, Module mod, interned meth, *untyped args) ?{ (*untyped, **untyped) -> untyped } -> untyped

# <!--
Expand Down
24 changes: 14 additions & 10 deletions test/stdlib/PP_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,15 @@ def test_version
end

def test_pp
assert_send_type "(::PP::_PrettyPrint obj, ?::PP::_LeftShift out, ?::Integer width) -> untyped",
assert_send_type "(::PP::_PrettyPrint obj) -> ::IO",
PP, :pp, Object.new
assert_send_type "(::PP::_PrettyPrint obj, ::String out) -> ::String",
PP, :pp, Object.new, ''.dup
assert_send_type "(::PP::_PrettyPrint obj, ::String out, ::Integer width) -> ::String",
PP, :pp, Object.new, ''.dup, 10

IO.pipe do |r, w|
assert_send_type "(::PP::_PrettyPrint obj, ?::PP::_LeftShift out, ?::Integer width) -> untyped",
assert_send_type "(::PP::_PrettyPrint obj, ::IO out) -> ::IO",
PP, :pp, Object.new, w
end
end
Expand All @@ -29,9 +33,9 @@ def test_width_for
end

def test_singleline_pp
assert_send_type "(::PP::_PrettyPrint obj, ?::PP::_LeftShift out) -> untyped",
assert_send_type "(::PP::_PrettyPrint obj) -> ::IO",
PP, :singleline_pp, Object.new
assert_send_type "(::PP::_PrettyPrint obj, ?::PP::_LeftShift out) -> untyped",
assert_send_type "(::PP::_PrettyPrint obj, ::String out) -> ::String",
PP, :singleline_pp, Object.new, ''.dup
end

Expand Down Expand Up @@ -72,7 +76,7 @@ def test_pop_inspect_key
end

def test_pp
assert_send_type "(::PP::_PrettyPrint obj) -> untyped",
assert_send_type "(::PP::_PrettyPrint obj) -> void",
PP.new, :pp, Object.new
end

Expand Down Expand Up @@ -101,12 +105,12 @@ def test_seplist
end

def test_pp_object
assert_send_type "(untyped obj) -> untyped",
assert_send_type "(untyped obj) -> void",
PP.new, :pp_object, Object.new
end

def test_pp_hash
assert_send_type "(untyped obj) -> untyped",
assert_send_type "(untyped obj) -> void",
PP.new, :pp_hash, {}
end

Expand All @@ -123,12 +127,12 @@ class PP::ObjectMixinTest < Test::Unit::TestCase
testing "::PP::ObjectMixin"

def test_pretty_print
assert_send_type "(PP q) -> untyped",
assert_send_type "(PP q) -> void",
Object.new, :pretty_print, PP.new
end

def test_pretty_print_cycle
assert_send_type "(PP q) -> untyped",
assert_send_type "(PP q) -> void",
Object.new, :pretty_print_cycle, PP.new
end

Expand All @@ -143,7 +147,7 @@ def pretty_print(q)
'ok'
end
end
assert_send_type "() -> untyped",
assert_send_type "() -> ::String",
has_pretty_print.new, :pretty_print_inspect
end
end
Loading