mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-06 09:55:40 +00:00
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 <christopher.waldon.dev@gmail.com>
This commit is contained in:
+16
-13
@@ -28,25 +28,28 @@ func TestWrappingTruncation(t *testing.T) {
|
|||||||
}, 200, 200, english, textInput)
|
}, 200, 200, english, textInput)
|
||||||
untruncatedCount := len(cache.txt.lines)
|
untruncatedCount := len(cache.txt.lines)
|
||||||
|
|
||||||
for i := untruncatedCount + 1; i > 0; i-- {
|
for expectedLines := untruncatedCount; expectedLines > 0; expectedLines-- {
|
||||||
cache.LayoutString(Parameters{
|
cache.LayoutString(Parameters{
|
||||||
Alignment: Middle,
|
Alignment: Middle,
|
||||||
PxPerEm: fixed.I(10),
|
PxPerEm: fixed.I(10),
|
||||||
MaxLines: i,
|
MaxLines: expectedLines,
|
||||||
}, 200, 200, english, textInput)
|
}, 200, 200, english, textInput)
|
||||||
lineCount := len(cache.txt.lines)
|
lineCount := 0
|
||||||
glyphs := []Glyph{}
|
lastGlyphWasLineBreak := false
|
||||||
for g, ok := cache.NextGlyph(); ok; g, ok = cache.NextGlyph() {
|
for g, ok := cache.NextGlyph(); ok; g, ok = cache.NextGlyph() {
|
||||||
glyphs = append(glyphs, g)
|
if g.Flags&FlagLineBreak != 0 {
|
||||||
|
lineCount++
|
||||||
|
lastGlyphWasLineBreak = true
|
||||||
|
} else {
|
||||||
|
lastGlyphWasLineBreak = false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if i <= untruncatedCount {
|
if lastGlyphWasLineBreak {
|
||||||
if lineCount != i {
|
// There was no actual line of text following this break.
|
||||||
t.Errorf("expected %d lines, got %d", i, lineCount)
|
lineCount--
|
||||||
}
|
}
|
||||||
} else if i > untruncatedCount {
|
if lineCount != expectedLines {
|
||||||
if lineCount != untruncatedCount {
|
t.Errorf("expected %d lines, got %d", expectedLines, lineCount)
|
||||||
t.Errorf("expected %d lines, got %d", untruncatedCount, lineCount)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user