-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathfindfont_test.go
55 lines (48 loc) · 1.36 KB
/
findfont_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package findfont
import (
"path/filepath"
"strings"
"testing"
)
func TestList(t *testing.T) {
// List must find something
fonts := List()
if len(fonts) == 0 {
t.Errorf("No font files found in system folders")
}
// ListWithSuffix using bad suffix
bad_suffix_fonts := ListWithSuffixes([]string{".bad-suffix"})
if len(bad_suffix_fonts) != 0 {
t.Errorf("Unexpectedly found font files with bad suffix, e.g. %s", bad_suffix_fonts[0])
}
// ListWithSuffixes using good suffix
good_suffix_fonts := ListWithSuffixes([]string{filepath.Ext(fonts[0])})
if len(good_suffix_fonts) == 0 {
t.Errorf("No font files with suffix %s", filepath.Ext(fonts[0]))
}
}
func TestFind(t *testing.T) {
// Try to find a non-existing font
font, err := Find("this-font-does-not-exist.ttf")
if err == nil {
t.Errorf("Expected match when searching for non-existant font: %s", font)
}
fonts := List()
if len(fonts) > 0 {
// Direct search for existing font file
font, err = Find(fonts[0])
if err != nil {
t.Errorf("Direct search failed: %v", err)
}
if font != fonts[0] {
t.Errorf("Unexpected match for direct search: %s, expected: %s", font, fonts[0])
}
// Search only for basename
needle := filepath.Base(fonts[0])
needle = strings.TrimSuffix(needle, filepath.Ext(needle))
_, err = Find(needle)
if err != nil {
t.Errorf("Basename search failed: %v", err)
}
}
}