From 1df210d9036abdee6863a573959b03f07c83e2c0 Mon Sep 17 00:00:00 2001 From: Samuel Giddins Date: Wed, 20 Dec 2023 17:55:50 -0800 Subject: [PATCH] Print beginless ranges properly Instead of displaying the start of the range as nil --- lib/pp.rb | 2 +- test/test_pp.rb | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/pp.rb b/lib/pp.rb index 1708dee..4fdeb33 100644 --- a/lib/pp.rb +++ b/lib/pp.rb @@ -442,7 +442,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 '' diff --git a/test/test_pp.rb b/test/test_pp.rb index bb2299a..3e1c725 100644 --- a/test/test_pp.rb +++ b/test/test_pp.rb @@ -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