Add test for summary truncating long anotations

When calling summary command with :annotations hint, if the annotation
is longer than a certain length, it's going to be truncated. The issue
is that the length and truncation are done on a raw string without
considering UTF8 multibyte characters, so there are edge cases when an
annotation is truncated in the middle of a character creating an invalid
UTF8 string.

Added a test case for this scenario.

Signed-off-by: Maxim Beder <macsim.beder@gmail.com>
This commit is contained in:
Maxim Beder 2023-04-03 23:49:33 +02:00 committed by Thomas Lauf
parent c85e0c01ca
commit 68d4978b7d

View file

@ -352,6 +352,16 @@ W\d{1,2} \d{4}-\d{2}-\d{2} .{3} ?0:00:00 0:00:00 0:00:00 0:00:00
[ ]+0:00:00
""")
def test_multibyte_char_annotation_truncated(self):
"""Summary correctly truncates long annotation containing multibyte characters"""
# Using a blue heart emoji as an example of a multibyte (4 bytes in
# this case) character.
long_enough_annotation = "a" + "\N{blue heart}" * 20
self.t("track FOO sod - sod")
self.t("anno @1 " + long_enough_annotation)
code, out, err = self.t("summary :anno")
self.assertIn("a" + "\N{blue heart}" * 11 + "...", out)
if __name__ == "__main__":
from simpletap import TAPTestRunner