Files
gio-patched/text/lru_test.go
T
Christophe Meessen a34e239c04 text,widget,opentype: change text.Face.Shape to return a clip.PathSpec
With this change, the Shape function returns a clip.PathSpec
instead of a clip.Outline op. It is then possible to create
a clip.Outline or clip.Stroke op to fill the text path or
draw its stroke.

Signed-off-by: Christophe Meessen <meessen@cppm.in2p3.fr>
2021-12-19 13:30:45 +01:00

55 lines
988 B
Go

// SPDX-License-Identifier: Unlicense OR MIT
package text
import (
"strconv"
"testing"
"gioui.org/op/clip"
)
func TestLayoutLRU(t *testing.T) {
c := new(layoutCache)
put := func(i int) {
c.Put(layoutKey{str: strconv.Itoa(i)}, nil)
}
get := func(i int) bool {
_, ok := c.Get(layoutKey{str: strconv.Itoa(i)})
return ok
}
testLRU(t, put, get)
}
func TestPathLRU(t *testing.T) {
c := new(pathCache)
put := func(i int) {
c.Put(pathKey{str: strconv.Itoa(i)}, clip.PathSpec{})
}
get := func(i int) bool {
_, ok := c.Get(pathKey{str: strconv.Itoa(i)})
return ok
}
testLRU(t, put, get)
}
func testLRU(t *testing.T, put func(i int), get func(i int) bool) {
for i := 0; i < maxSize; i++ {
put(i)
}
for i := 0; i < maxSize; i++ {
if !get(i) {
t.Fatalf("key %d was evicted", i)
}
}
put(maxSize)
for i := 1; i < maxSize+1; i++ {
if !get(i) {
t.Fatalf("key %d was evicted", i)
}
}
if i := 0; get(i) {
t.Fatalf("key %d was not evicted", i)
}
}