From 1210bbb34a767cef92bfe9a5a71a0104a0864aeb Mon Sep 17 00:00:00 2001 From: Chris Waldon Date: Fri, 24 Feb 2023 10:23:04 -0500 Subject: [PATCH] text: test maxlines with exported API This commit changes _how_ the test for line wrapping is implemented to rely on the exported API rather than internal symbols. Thanks to https://github.com/gioui/gio/pull/109 for pointing this out. Signed-off-by: Chris Waldon --- text/shaper_test.go | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/text/shaper_test.go b/text/shaper_test.go index a150c3dc..825ca6c5 100644 --- a/text/shaper_test.go +++ b/text/shaper_test.go @@ -28,26 +28,29 @@ func TestWrappingTruncation(t *testing.T) { }, 200, 200, english, textInput) untruncatedCount := len(cache.txt.lines) - for i := untruncatedCount + 1; i > 0; i-- { + for expectedLines := untruncatedCount; expectedLines > 0; expectedLines-- { cache.LayoutString(Parameters{ Alignment: Middle, PxPerEm: fixed.I(10), - MaxLines: i, + MaxLines: expectedLines, }, 200, 200, english, textInput) - lineCount := len(cache.txt.lines) - glyphs := []Glyph{} + lineCount := 0 + lastGlyphWasLineBreak := false for g, ok := cache.NextGlyph(); ok; g, ok = cache.NextGlyph() { - glyphs = append(glyphs, g) - } - if i <= untruncatedCount { - if lineCount != i { - t.Errorf("expected %d lines, got %d", i, lineCount) - } - } else if i > untruncatedCount { - if lineCount != untruncatedCount { - t.Errorf("expected %d lines, got %d", untruncatedCount, lineCount) + if g.Flags&FlagLineBreak != 0 { + lineCount++ + lastGlyphWasLineBreak = true + } else { + lastGlyphWasLineBreak = false } } + if lastGlyphWasLineBreak { + // There was no actual line of text following this break. + lineCount-- + } + if lineCount != expectedLines { + t.Errorf("expected %d lines, got %d", expectedLines, lineCount) + } } } -- 2.45.2