self
at max_length
characters and append an informative message
.assert "hello".trunc(10) == "hello"
assert "hello".trunc(2) == "he[truncated. Full size is 5]"
assert "hello".trunc(2, "...") == "he..."
# If needed, truncate `self` at `max_length` characters and append an informative `message`.
#
# ~~~
# assert "hello".trunc(10) == "hello"
# assert "hello".trunc(2) == "he[truncated. Full size is 5]"
# assert "hello".trunc(2, "...") == "he..."
# ~~~
fun trunc(max_length: Int, message: nullable String): String
do
if length <= max_length then return self
if message == null then message = "[truncated. Full size is {length}]"
return substring(0, max_length) + message
end
src/testing/testing_base.nit:301,2--313,4