Skip to content

Commit

Permalink
Fix empty class pretty print
Browse files Browse the repository at this point in the history
  • Loading branch information
asterite committed Jan 6, 2017
1 parent 1e7f46e commit c6b3e87
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 6 additions & 0 deletions spec/std/reference_spec.cr
Expand Up @@ -105,4 +105,10 @@ describe "Reference" do
clone.y.should_not be(original.y)
clone.y.should eq(original.y)
end

# TODO uncomment after 0.20.3
# it "pretty_print" do
# ReferenceSpec::TestClassBase.new.pretty_inspect.should match(/\A#<ReferenceSpec::TestClassBase:0x[0-9a-f]+>\Z/)
# ReferenceSpec::TestClass.new(42, "foo").pretty_inspect.should match(/\A#<ReferenceSpec::TestClass:0x[0-9a-f]+ @x=42, @y="foo">\Z/)
# end
end
6 changes: 4 additions & 2 deletions src/reference.cr
Expand Up @@ -81,9 +81,11 @@ class Reference
{% else %}
prefix = "#<#{{{@type.name.id.stringify}}}:0x#{object_id.to_s(16)}"
executed = exec_recursive(:pretty_print) do
pp.surround(prefix, ">", left_break: " ", right_break: nil) do
pp.surround(prefix, ">", left_break: nil, right_break: nil) do
{% for ivar, i in @type.instance_vars.map(&.name).sort %}
{% if i > 0 %}
{% if i == 0 %}
pp.breakable
{% else %}
pp.comma
{% end %}
pp.group do
Expand Down

0 comments on commit c6b3e87

Please sign in to comment.