Files
gio-patched/text/lru_test.go
T
Chris Waldon 1e5a3696f5 deps,text,widget,font/opentype: [API] add harfbuzz-powered text shaper
This commit introduces a new text shaping infrastructure
powered by Benoit Kugler's Go source-port of harfbuzz.
This shaper can properly display complex scripts and RTL
text. This commit changes the signature of the text.Shaper
function, which is a breaking API change.

The new functionality is available via opentype.ParseHarfbuzz,
which configures a text.Shaper leveraging the new backend.

References: https://todo.sr.ht/~eliasnaur/gio/146
Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
2022-03-18 08:01:44 +01:00

55 lines
1.1 KiB
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), gidHash: uint64(i)}, Layout{Runes: Range{Count: i}}, clip.PathSpec{})
}
get := func(i int) bool {
_, ok := c.Get(pathKey{str: strconv.Itoa(i), gidHash: uint64(i)}, Layout{Runes: Range{Count: 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)
}
}