forked from joejulian/gio
bef7c39e4c
There is now a single shaping implementation, Shaper, for all fonts, replacing Family that only covered a single typeface. A typeface is identified by a name, where the empty string denotes the default typeface. Font is introduced to specify a particular font from the typeface, style, weight and size. Face is changed to an interface for a particular layout and shaping method. The text/shape package is renamed to text/opentype and contains a Face implementation based on golang.org/x/image/font/sfnt. Signed-off-by: Elias Naur <mail@eliasnaur.com>
55 lines
988 B
Go
55 lines
988 B
Go
// SPDX-License-Identifier: Unlicense OR MIT
|
|
|
|
package text
|
|
|
|
import (
|
|
"strconv"
|
|
"testing"
|
|
|
|
"gioui.org/op/paint"
|
|
)
|
|
|
|
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)}, paint.ClipOp{})
|
|
}
|
|
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)
|
|
}
|
|
}
|