-
Notifications
You must be signed in to change notification settings - Fork 0
/
ots_test.go
76 lines (72 loc) · 2.22 KB
/
ots_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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package gots_test
import (
"bytes"
"errors"
"io/fs"
"os"
"path/filepath"
"strings"
"testing"
"github.com/pgaskin/gots"
)
func init() {
gots.Compile()
}
func TestOTS(t *testing.T) {
if _, err := os.Stat(filepath.Join("ots", "tests", "fonts")); errors.Is(err, fs.ErrNotExist) {
t.Skip("ots test fonts directory doesn't exist (is the git submodule initialized?), skipping tests")
return
}
for _, kind := range []string{"bad", "fuzzing", "good"} {
t.Run(strings.ToUpper(kind[0:1])+kind[1:], func(t *testing.T) {
dir := filepath.Join("ots", "tests", "fonts", kind)
fis, err := os.ReadDir(dir)
if err != nil {
panic(err)
}
for _, fi := range fis {
t.Run(fi.Name(), func(t *testing.T) {
fn := filepath.Join(dir, fi.Name())
input, err := os.ReadFile(fn)
if err != nil {
panic(err)
}
extF := filepath.Ext(fi.Name())
extI := gots.Extension(input)
if kind == "good" && extI != extF && !(extI == ".ttc" && extF == ".ttf") {
t.Errorf("%s: file extension is %s, we detected %s", fn, extF, extI)
}
output, err := gots.Process(input, gots.WithMessages(func(level gots.MessageLevel, msg string) {
t.Logf("%s: ots: %s: %s", fn, level, msg)
}))
if kind != "fuzzing" {
if success := (kind == "good"); (err == nil) != success {
t.Errorf("%s: expected success=%t, got error: %v", fn, success, err)
}
if err == nil && gots.Extension(output) == "" {
t.Errorf("%s: failed to get extension of processed font", fn)
}
}
if err == nil {
switch fi.Name() {
case "4765a8901e377d1e767f67e1cc768ae3c9207bd1.ttc":
case "7043d3c69c50da8eba1a0ad627b9f6de70e832e5.ttf":
case "8330c9816493e1adccc0500b414455b85088d7d1.ttf":
case "b927e6af295696a2307641eb9679d0832dd7c22d.ttf":
case "f5ff6aaa96256b0e2c1abfdebf592c0987a1637a.ttf":
case "3ee1ab163f0029bdd8f90b79f2c0e798bc26957b.ttf":
default:
output1, err := gots.Process(output)
if err != nil {
t.Errorf("%s: re-process processed output: unexpected error: %v", fn, err)
}
if !bytes.Equal(output, output1) {
t.Errorf("%s: re-processed output doesn't match", fn)
}
}
}
})
}
})
}
}