Skip to content

Commit

Permalink
[ruby/pp] Print beginless ranges properly
Browse files Browse the repository at this point in the history
Instead of displaying the start of the range as nil

ruby/pp@1df210d903
  • Loading branch information
segiddins authored and matzbot committed Jan 15, 2024
1 parent 9c32998 commit e0312f9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/pp.rb
Expand Up @@ -444,7 +444,7 @@ def pretty_print_cycle(q) # :nodoc:

class Range # :nodoc:
def pretty_print(q) # :nodoc:
q.pp self.begin
q.pp self.begin if self.begin
q.breakable ''
q.text(self.exclude_end? ? '...' : '..')
q.breakable ''
Expand Down
7 changes: 7 additions & 0 deletions test/test_pp.rb
Expand Up @@ -28,6 +28,13 @@ def o.method
end
assert_equal(%(""\n), PP.pp(o, "".dup))
end

def test_range
assert_equal("0..1\n", PP.pp(0..1, "".dup))
assert_equal("0...1\n", PP.pp(0...1, "".dup))
assert_equal("0...\n", PP.pp(0..., "".dup))
assert_equal("...1\n", PP.pp(...1, "".dup))
end
end

class HasInspect
Expand Down

0 comments on commit e0312f9

Please sign in to comment.