| 1 | package cli |
| 2 | |
| 3 | import ( |
| 4 | "strings" |
| 5 | "testing" |
| 6 | ) |
| 7 | |
| 8 | func TestBlockquoteRowsFitTheRenderWidth(t *testing.T) { |
| 9 | quote := "结论:月娘算是一个\"好人\",但她的好是被动的、无力的。她没害人,但她也没救人。她的\"好\"更像是一种性格上的消极,而不是道德上的主动选择。" |
| 10 | cases := map[string]string{ |
| 11 | "top level": "> " + quote, |
| 12 | "inside a list": "- item\n\n > " + quote, |
| 13 | "nested quote": "> > " + quote, |
| 14 | "latin words": "> " + strings.Repeat("wrapping words ", 20), |
| 15 | } |
| 16 | for name, input := range cases { |
| 17 | for _, width := range []int{20, 41, 80} { |
| 18 | out := newMarkdownRenderer(width).Render(input) |
| 19 | for row := range strings.SplitSeq(strings.TrimRight(out, "\n"), "\n") { |
| 20 | if w := visibleWidth(row); w > width { |
| 21 | t.Errorf("%s at width %d: row is %d columns: %q", name, width, w, row) |
| 22 | } |
| 23 | } |
| 24 | } |
| 25 | } |
| 26 | } |
| 27 |