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
18 changes: 18 additions & 0 deletions lib/prettyprint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -487,8 +487,10 @@ def delete(group)
# It is passed to be similar to a PrettyPrint object itself, by responding to:
# * #text
# * #breakable
# * #fill_breakable
# * #nest
# * #group
# * #group_sub
# * #flush
# * #first?
#
Expand Down Expand Up @@ -522,6 +524,13 @@ def breakable(sep=' ', width=nil)
@output << sep
end

# Appends +sep+ to the text to be output. By default +sep+ is ' '
#
# +width+ argument is here for compatibility. It is a noop argument.
def fill_breakable(sep=' ', width=nil)
@output << sep
end

# Takes +indent+ arg, but does nothing with it.
#
# Yields to a block.
Expand All @@ -545,6 +554,15 @@ def group(indent=nil, open_obj='', close_obj='', open_width=nil, close_width=nil
@first.pop
end

# Yields to a block for compatibility.
def group_sub # :nodoc:
yield
end

# Method present for compatibility, but is a noop
def break_outmost_groups # :nodoc:
end

# Method present for compatibility, but is a noop
def flush # :nodoc:
end
Expand Down
71 changes: 71 additions & 0 deletions test/test_prettyprint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -518,4 +518,75 @@ def test_27

end

class SingleLineFormat < Test::Unit::TestCase # :nodoc:

def test_singleline_format_with_breakables
singleline_format = PrettyPrint.singleline_format("".dup) do |q|
q.group 0, "(", ")" do
q.text "abc"
q.breakable
q.text "def"
q.breakable
q.text "ghi"
q.breakable
q.text "jkl"
q.breakable
q.text "mno"
q.breakable
q.text "pqr"
q.breakable
q.text "stu"
end
end
expected = <<'End'.chomp
(abc def ghi jkl mno pqr stu)
End

assert_equal(expected, singleline_format)
end

def test_singleline_format_with_fill_breakables
singleline_format = PrettyPrint.singleline_format("".dup) do |q|
q.group 0, "(", ")" do
q.text "abc"
q.fill_breakable
q.text "def"
q.fill_breakable
q.text "ghi"
q.fill_breakable
q.text "jkl"
q.fill_breakable
q.text "mno"
q.fill_breakable
q.text "pqr"
q.fill_breakable
q.text "stu"
end
end
expected = <<'End'.chomp
(abc def ghi jkl mno pqr stu)
End

assert_equal(expected, singleline_format)
end

def test_singleline_format_with_group_sub
singleline_format = PrettyPrint.singleline_format("".dup) do |q|
q.group 0, "(", ")" do
q.group_sub do
q.text "abc"
q.breakable
q.text "def"
end
q.breakable
q.text "ghi"
end
end
expected = <<'End'.chomp
(abc def ghi)
End

assert_equal(expected, singleline_format)
end
end
end