Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use external testdata module #12

Merged
merged 6 commits into from
May 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
5 changes: 3 additions & 2 deletions fonts/truetype/aat_table_ankr_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package truetype

import (
"io/ioutil"
"testing"

testdata "github.com/benoitkugler/textlayout-testdata/truetype"
)

func TestParseTableAnkr(t *testing.T) {
data, err := ioutil.ReadFile("testdata/ankr.bin")
data, err := testdata.Files.ReadFile("ankr.bin")
if err != nil {
t.Fatal(err)
}
Expand Down
8 changes: 5 additions & 3 deletions fonts/truetype/aat_table_feat_test.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
package truetype

import (
"os"
"bytes"
"testing"

testdata "github.com/benoitkugler/textlayout-testdata/truetype"
)

func TestFeat(t *testing.T) {
f, err := os.Open("testdata/ToyFeat.ttf")
f, err := testdata.Files.ReadFile("ToyFeat.ttf")
if err != nil {
t.Fatal(err)
}

font, err := NewFontParser(f)
font, err := NewFontParser(bytes.NewReader(f))
if err != nil {
t.Fatal(err)
}
Expand Down
15 changes: 8 additions & 7 deletions fonts/truetype/aat_table_kerx_test.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
package truetype

import (
"io/ioutil"
"os"
"bytes"
"testing"

testdata "github.com/benoitkugler/textlayout-testdata/truetype"
)

func TestKerx(t *testing.T) {
filename := "testdata/Bangla Sangam MN.ttc"
file, err := os.Open(filename)
filename := "Bangla Sangam MN.ttc"
file, err := testdata.Files.ReadFile(filename)
if err != nil {
t.Fatalf("Failed to open %q: %s\n", filename, err)
}

fonts, err := NewFontParsers(file)
fonts, err := NewFontParsers(bytes.NewReader(file))
if err != nil {
t.Fatalf("Parse(%q) err = %q, want nil", filename, err)
}
Expand All @@ -32,7 +33,7 @@ func TestKerx(t *testing.T) {
}

func TestKern0(t *testing.T) {
data, err := ioutil.ReadFile("testdata/kernSubtable0.bin")
data, err := testdata.Files.ReadFile("kernSubtable0.bin")
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -122,7 +123,7 @@ func TestKern0(t *testing.T) {
}

func TestKerx6(t *testing.T) {
data, err := ioutil.ReadFile("testdata/kerxSubtable6.bin")
data, err := testdata.Files.ReadFile("kerxSubtable6.bin")
if err != nil {
t.Fatal(err)
}
Expand Down
9 changes: 5 additions & 4 deletions fonts/truetype/aat_table_mortx_test.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
package truetype

import (
"os"
"bytes"
"reflect"
"testing"

testdata "github.com/benoitkugler/textlayout-testdata/truetype"
"github.com/benoitkugler/textlayout/fonts"
)

func TestMort(t *testing.T) {
for _, filename := range dirFiles(t, "testdata/layout_fonts/morx") {
file, err := os.Open(filename)
for _, filename := range dirFiles(t, "layout_fonts/morx") {
file, err := testdata.Files.ReadFile(filename)
if err != nil {
t.Fatalf("Failed to open %q: %s\n", filename, err)
}

font, err := NewFontParser(file)
font, err := NewFontParser(bytes.NewReader(file))
if err != nil {
t.Fatalf("Parse(%q) err = %q, want nil", filename, err)
}
Expand Down
8 changes: 5 additions & 3 deletions fonts/truetype/aat_table_trak_test.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
package truetype

import (
"os"
"bytes"
"reflect"
"testing"

testdata "github.com/benoitkugler/textlayout-testdata/truetype"
)

func TestTrak(t *testing.T) {
f, err := os.Open("testdata/ToyTrak.ttf")
f, err := testdata.Files.ReadFile("ToyTrak.ttf")
if err != nil {
t.Fatal(err)
}

font, err := NewFontParser(f)
font, err := NewFontParser(bytes.NewReader(f))
if err != nil {
t.Fatal(err)
}
Expand Down
63 changes: 28 additions & 35 deletions fonts/truetype/bitmaps_test.go
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
package truetype

import (
"bytes"
"fmt"
"os"
"reflect"
"testing"

testdata "github.com/benoitkugler/textlayout-testdata/truetype"
"github.com/benoitkugler/textlayout/fonts"
)

func TestSbix(t *testing.T) {
for _, filename := range []string{
"testdata/ToyFeat.ttf",
"testdata/ToySbix.ttf",
"ToyFeat.ttf",
"ToySbix.ttf",
} {
file, err := os.Open(filename)
file, err := testdata.Files.ReadFile(filename)
if err != nil {
t.Fatalf("Failed to open %q: %s\n", filename, err)
}

font, err := NewFontParser(file)
font, err := NewFontParser(bytes.NewReader(file))
if err != nil {
t.Fatalf("Parse(%q) err = %q, want nil", filename, err)
}
Expand Down Expand Up @@ -47,23 +48,21 @@ func TestSbix(t *testing.T) {
}
}
}

file.Close()
}
}

func TestCblc(t *testing.T) {
for _, filename := range []string{
"testdata/ToyCBLC1.ttf",
"testdata/ToyCBLC2.ttf",
"testdata/NotoColorEmoji.ttf",
"ToyCBLC1.ttf",
"ToyCBLC2.ttf",
"NotoColorEmoji.ttf",
} {
file, err := os.Open(filename)
file, err := testdata.Files.ReadFile(filename)
if err != nil {
t.Fatalf("Failed to open %q: %s\n", filename, err)
}

pr, err := NewFontParser(file)
pr, err := NewFontParser(bytes.NewReader(file))
if err != nil {
t.Fatalf("Parse(%q) err = %q, want nil", filename, err)
}
Expand All @@ -88,8 +87,6 @@ func TestCblc(t *testing.T) {
t.Fatal(err)
}

file.Close()

font := Font{bitmap: gs, upem: head.Upem()}
cmap, _ := cmaps.BestEncoding()
iter := cmap.Iter()
Expand All @@ -102,15 +99,15 @@ func TestCblc(t *testing.T) {

func TestEblc(t *testing.T) {
for _, filename := range []string{
"testdata/mry_KacstQurn.ttf",
"testdata/IBM3161-bitmap.otb",
"mry_KacstQurn.ttf",
"IBM3161-bitmap.otb",
} {
file, err := os.Open(filename)
file, err := testdata.Files.ReadFile(filename)
if err != nil {
t.Fatal(filename, err)
}

font, err := NewFontParser(file)
font, err := NewFontParser(bytes.NewReader(file))
if err != nil {
t.Fatal(filename, err)
}
Expand All @@ -125,19 +122,17 @@ func TestEblc(t *testing.T) {
strike.subTables = nil // not to flood the terminal
fmt.Println(strike)
}
file.Close()
}
}

func TestAppleBitmap(t *testing.T) {
filename := "testdata/Gacha_9.dfont"
file, err := os.Open(filename)
filename := "Gacha_9.dfont"
file, err := testdata.Files.ReadFile(filename)
if err != nil {
t.Fatal(filename, err)
}
defer file.Close()

fonts, err := NewFontParsers(file)
fonts, err := NewFontParsers(bytes.NewReader(file))
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -183,21 +178,21 @@ func TestSize(t *testing.T) {
},
}
for i, filename := range []string{
"testdata/ToyFeat.ttf",
"testdata/ToySbix.ttf",
"testdata/ToyCBLC1.ttf",
"testdata/ToyCBLC2.ttf",
"testdata/NotoColorEmoji.ttf",
"testdata/mry_KacstQurn.ttf",
"testdata/IBM3161-bitmap.otb",
"testdata/Gacha_9.dfont",
"ToyFeat.ttf",
"ToySbix.ttf",
"ToyCBLC1.ttf",
"ToyCBLC2.ttf",
"NotoColorEmoji.ttf",
"mry_KacstQurn.ttf",
"IBM3161-bitmap.otb",
"Gacha_9.dfont",
} {
file, err := os.Open(filename)
file, err := testdata.Files.ReadFile(filename)
if err != nil {
t.Fatal(filename, err)
}

fonts, err := Load(file)
fonts, err := Load(bytes.NewReader(file))
if err != nil {
t.Fatal(filename, err)
}
Expand All @@ -207,7 +202,5 @@ func TestSize(t *testing.T) {
if !reflect.DeepEqual(got, expectedSizes[i]) {
t.Fatalf("font %s, expected %v got %v", filename, expectedSizes[i], got)
}

file.Close()
}
}
Loading