glamour icon indicating copy to clipboard operation
glamour copied to clipboard

test: add test for chinese character formatting bug

Open bashbunni opened this issue 1 year ago • 2 comments

related https://github.com/charmbracelet/glow/issues/499

I'm testing to reproduce the formatting issues in this bug report to confirm if Glamour is responsible for this behaviour. (wip)

bashbunni avatar Aug 12 '23 00:08 bashbunni

Tests are failing, but the output isn't hugely helpful... It looks like the ansi code is different on the line where there is a difference, but it doesn't really help me narrow down the issue. The shorter text seems to format correctly which would be consistent with the original issue reported.

=== RUN   TestWrapping
=== RUN   TestWrapping/english_short
=== RUN   TestWrapping/chinese_short
=== RUN   TestWrapping/chinese_long
    glamour_test.go:279: got != want
        -want +got:
        diff:
          string{
          	... // 78204 identical bytes
          	0x6d, 0x1b, 0x5b, 0x33, 0x38, 0x3b, 0x35, 0x3b, 0x32, 0x35, 0x32, 0x6d, 0x1b, 0x5b, 0x30, 0x6d, //  |m.[38;5;252m.[0m|
          	0x20, 0x20, 0x1b, 0x5b, 0x33, 0x38, 0x3b, 0x35, 0x3b, 0x32, 0x35, 0x32, 0x6d, 0x31, 0x3a, 0x34, //  |  .[38;5;252m1:4|
        + 	0x1b, 0x5b, 0x30, 0x6d, 0x1b, 0x5b, 0x33, 0x38, 0x3b, 0x35, 0x3b, 0x32, 0x35, 0x32, 0x6d,       // +|.[0m.[38;5;252m|
          	0x3a, 0x39, 0x1b, 0x5b, 0x33, 0x38, 0x3b, 0x35, 0x3b, 0x32, 0x35, 0x32, 0x6d, 0x20, 0x1b, 0x5b, //  |:9.[38;5;252m .[|
          	0x30, 0x6d, 0x1b, 0x5b, 0x33, 0x38, 0x3b, 0x35, 0x3b, 0x32, 0x35, 0x32, 0x6d, 0x20, 0x1b, 0x5b, //  |0m.[38;5;252m .[|
          	... // 340063 identical bytes
          }
--- FAIL: TestWrapping (0.33s)
    --- PASS: TestWrapping/english_short (0.00s)
    --- PASS: TestWrapping/chinese_short (0.00s)
    --- FAIL: TestWrapping/chinese_long (0.33s)
FAIL

bashbunni avatar Aug 14 '23 22:08 bashbunni

Soooo this is what cmp.Diff does when an output is considered "non-printable". The |.[0m.[38;5;252m| is what differed between the got and want values and this only happens with long chinese text. So far I've tried short english, short chinese, long latin, and long chinese and the final test is the only one failing so I think I've successfully reproduced the issue... Now to try and figure out what that issue is exactly and how to fix it 👍

(also thanks to the Go team for helping me figure out how to read the output: https://github.com/google/go-cmp/issues/334)

bashbunni avatar Aug 15 '23 03:08 bashbunni