text: update fuzzer to sometimes truncate

This commit updates the shaper fuzzer to try truncating the text, exposing
new edge cases.

Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
This commit is contained in:
Chris Waldon
2023-08-02 10:44:15 -04:00
parent 341978dbcd
commit d414116990
15 changed files with 26 additions and 2 deletions
+7 -2
View File
@@ -567,10 +567,10 @@ func TestComputeVisualOrder(t *testing.T) {
func FuzzLayout(f *testing.F) {
ltrFace, _ := opentype.Parse(goregular.TTF)
rtlFace, _ := opentype.Parse(nsareg.TTF)
f.Add("د عرمثال dstي met لم aqل جدmوpمg lرe dرd لو عل ميrةsdiduntut lab renنيتذدagلaaiua.ئPocttأior رادرsاي mيrbلmnonaيdتد ماةعcلخ.", true, uint8(10), uint16(200))
f.Add("د عرمثال dstي met لم aqل جدmوpمg lرe dرd لو عل ميrةsdiduntut lab renنيتذدagلaaiua.ئPocttأior رادرsاي mيrbلmnonaيdتد ماةعcلخ.", true, false, uint8(10), uint16(200))
shaper := testShaper(ltrFace, rtlFace)
f.Fuzz(func(t *testing.T, txt string, rtl bool, fontSize uint8, width uint16) {
f.Fuzz(func(t *testing.T, txt string, rtl bool, truncate bool, fontSize uint8, width uint16) {
locale := system.Locale{
Direction: system.LTR,
}
@@ -580,9 +580,14 @@ func FuzzLayout(f *testing.F) {
if fontSize < 1 {
fontSize = 1
}
maxLines := 0
if truncate {
maxLines = 1
}
lines := shaper.LayoutRunes(Parameters{
PxPerEm: fixed.I(int(fontSize)),
MaxWidth: int(width),
MaxLines: maxLines,
Locale: locale,
}, []rune(txt))
validateLines(t, lines.lines, len([]rune(txt)))
@@ -1,5 +1,6 @@
go test fuzz v1
string("\x1d")
bool(true)
bool(false)
byte('\x1c')
uint16(227)
@@ -1,5 +1,6 @@
go test fuzz v1
string("0")
bool(true)
bool(false)
uint8(27)
uint16(200)
+6
View File
@@ -0,0 +1,6 @@
go test fuzz v1
string("\n")
bool(false)
bool(true)
byte('±')
uint16(0)
+1
View File
@@ -1,5 +1,6 @@
go test fuzz v1
string("\n")
bool(false)
bool(false)
byte('±')
uint16(0)
@@ -1,5 +1,6 @@
go test fuzz v1
string("\u2029")
bool(false)
bool(false)
byte('*')
uint16(72)
@@ -1,5 +1,6 @@
go test fuzz v1
string("Aͮ000000000000000")
bool(false)
bool(false)
byte('\u0087')
uint16(111)
@@ -1,5 +1,6 @@
go test fuzz v1
string("\x1e")
bool(true)
bool(false)
byte('\n')
uint16(254)
+1
View File
@@ -1,5 +1,6 @@
go test fuzz v1
string("000000000000000 00000000 ٰ00000")
bool(true)
bool(false)
byte('\n')
uint16(121)
@@ -1,5 +1,6 @@
go test fuzz v1
string("\r")
bool(false)
bool(false)
byte('T')
uint16(200)
@@ -1,5 +1,6 @@
go test fuzz v1
string("\u0085")
bool(true)
bool(false)
byte('\x10')
uint16(271)
@@ -1,5 +1,6 @@
go test fuzz v1
string("0")
bool(false)
bool(false)
byte('\x00')
uint16(142)
@@ -1,5 +1,6 @@
go test fuzz v1
string("\n")
bool(true)
bool(false)
byte('\t')
uint16(200)
@@ -1,5 +1,6 @@
go test fuzz v1
string("ع0 ׂ0")
bool(false)
bool(false)
byte('\u0098')
uint16(198)
@@ -1,5 +1,6 @@
go test fuzz v1
string("\x1c")
bool(true)
bool(false)
byte('\u009c')
uint16(200)