@ -439,6 +439,7 @@ end
-- multiple lines. If width is not specified, 72 is used.
function string:wrap(width)
width = width or 72
if width <= 0 then error('expected width > 0; got: '..tostring(width)) end
local wrapped_text = {}
for line in self:gmatch('[^\n]*') do
local line_start_pos = 1
@ -558,7 +558,8 @@ WrappedLabel.ATTRS{
}
function WrappedLabel:getWrappedText(width)
if not self.text_to_wrap then return nil end
-- 0 width can happen if the parent has 0 width
if not self.text_to_wrap or width <= 0 then return nil end
local text_to_wrap = getval(self.text_to_wrap)
if type(text_to_wrap) == 'table' then
text_to_wrap = table.concat(text_to_wrap, NEWLINE)
@ -67,6 +67,8 @@ function test.wrap()
expect.eq('hel\nlo\nwor\nld', ('hello world'):wrap(3))
expect.eq('hel\nloo\nwor\nldo', ('helloo worldo'):wrap(3))
expect.eq('', (''):wrap())
expect.error_match('expected width > 0', function() ('somestr'):wrap(0) end)
end
function test.escape_pattern()