Files
ngzz-mc/internal/font/font_test.go

38 lines
990 B
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package font
import (
"path/filepath"
"testing"
"mc/internal/assets"
)
// TestBuild 验证从真实素材包构建字体图集(UI还原.md §4)。
func TestBuild(t *testing.T) {
m := assets.New()
packDir := filepath.Join("..", "..", "resourcepacks")
if err := m.Load(filepath.Join("..", "..", "assets"), packDir); err != nil {
t.Fatalf("加载内容包失败: %v", err)
}
at, err := Build(m, "default")
if err != nil {
t.Fatalf("构建字体失败: %v", err)
}
for _, ch := range []rune{'A', 'a', '0', '!'} {
g, ok := at.Glyphs[ch]
if !ok {
t.Fatalf("缺少字形 %q", ch)
}
if g.W != 8 {
t.Fatalf("字形 %q 宽度期望 8,实际 %d", ch, g.W)
}
}
// 主位图:宽 128(16 列 × 8px),高为 8 的整数倍(原版 ascii.png 为 128×536)
if at.Image == nil {
t.Fatal("主位图为空")
}
if b := at.Image.Bounds(); b.Dx() != 128 || b.Dy()%8 != 0 || b.Dy() < 128 {
t.Fatalf("ascii 位图尺寸异常: %dx%d", b.Dx(), b.Dy())
}
}