MCPcopy Create free account
hub / github.com/Debian/debiman / TestRecode

Function TestRecode

internal/recode/recode_test.go:33–77  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

31}
32
33func TestRecode(t *testing.T) {
34 table := []struct {
35 src string
36 dest string
37 language string
38 }{
39 {
40 src: "../../testdata/kterm.1.ja.gz",
41 // dest was generated using:
42 // gunzip -c testdata/kterm.1.ja.gz| iconv -f EUC-JP -t UTF-8 | gzip -9 -c > testdata/kterm.1.ja.UTF-8.gz
43 dest: "../../testdata/kterm.1.ja.UTF-8.gz",
44 language: "ja",
45 },
46 }
47 for _, entry := range table {
48 entry := entry // capture
49 t.Run(entry.src, func(t *testing.T) {
50 t.Parallel()
51
52 srcb, err := readGzipped(entry.src)
53 if err != nil {
54 t.Fatal(err)
55 }
56
57 destb, err := readGzipped(entry.dest)
58 if err != nil {
59 t.Fatal(err)
60 }
61
62 if utf8.Valid(srcb) {
63 t.Fatalf("source file %q unexpectedly valid UTF-8", entry.src)
64 }
65
66 r := Reader(bytes.NewReader(srcb), entry.language)
67 recoded, err := ioutil.ReadAll(r)
68 if err != nil {
69 t.Fatal(err)
70 }
71
72 if got, want := bytes.Compare(recoded, destb), 0; got != want {
73 t.Fatalf("recoded source file unexpectedly different from golden UTF-8 file: got %d, want %d", got, want)
74 }
75 })
76 }
77}

Callers

nothing calls this directly

Calls 2

readGzippedFunction · 0.85
ReaderFunction · 0.85

Tested by

no test coverage detected