1
0
Fork 0
mirror of https://github.com/Luzifer/badge-gen.git synced 2024-11-08 13:20:02 +00:00
badge-gen/font_test.go

32 lines
773 B
Go
Raw Permalink Normal View History

2015-05-25 15:40:46 +00:00
package main
import (
"crypto/sha256"
"fmt"
"testing"
)
func TestEmbeddedFontHash(t *testing.T) {
// Check the embedded font did not change
font, err := assets.ReadFile("assets/DejaVuSans.ttf")
2015-05-25 15:40:46 +00:00
if err != nil {
t.Errorf("Could not load embedded font: %s", err)
}
hash := fmt.Sprintf("%x", sha256.Sum256(font))
if hash != "3fdf69cabf06049ea70a00b5919340e2ce1e6d02b0cc3c4b44fb6801bd1e0d22" {
t.Errorf("Embedded font changed: %s", hash)
}
}
func TestStringLength(t *testing.T) {
// As the font is embedded into the source the length calculation should not change
w, err := calculateTextWidth("Test 123 öäüß … !@#%&")
if err != nil {
t.Errorf("Text length errored: %s", err)
}
if w != 138 {
t.Errorf("Text length changed and is now %d", w)
}
}