| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
package icons |
| 6 |
|
| 7 |
import ( |
| 8 |
"image" |
| 9 |
"image/draw" |
| 10 |
"image/png" |
| 11 |
"os" |
| 12 |
"path/filepath" |
| 13 |
"testing" |
| 14 |
|
| 15 |
"golang.org/x/exp/shiny/iconvg" |
| 16 |
) |
| 17 |
|
| 18 |
func encodePNG(dstFilename string, src image.Image) error { |
| 19 |
f, err := os.Create(dstFilename) |
| 20 |
if err != nil { |
| 21 |
return err |
| 22 |
} |
| 23 |
encErr := png.Encode(f, src) |
| 24 |
closeErr := f.Close() |
| 25 |
if encErr != nil { |
| 26 |
return encErr |
| 27 |
} |
| 28 |
return closeErr |
| 29 |
} |
| 30 |
|
| 31 |
func TestManualInspection(t *testing.T) { |
| 32 |
|
| 33 |
|
| 34 |
const tmpDir = "" |
| 35 |
|
| 36 |
if tmpDir == "" { |
| 37 |
t.Skip("no tmpDir specified") |
| 38 |
} |
| 39 |
t.Errorf("tmpDir %q is a non-empty string; do not commit code changes", tmpDir) |
| 40 |
|
| 41 |
dst := image.NewAlpha(image.Rect(0, 0, 256, 256)) |
| 42 |
z := &iconvg.Rasterizer{} |
| 43 |
z.SetDstImage(dst, dst.Bounds(), draw.Src) |
| 44 |
for _, v := range list { |
| 45 |
if err := iconvg.Decode(z, v.data, nil); err != nil { |
| 46 |
t.Errorf("%q: %v", v.name, err) |
| 47 |
continue |
| 48 |
} |
| 49 |
filename := filepath.Join(tmpDir, v.name+".png") |
| 50 |
if err := encodePNG(filename, dst); err != nil { |
| 51 |
t.Error(err) |
| 52 |
} |
| 53 |
t.Logf("wrote %s", filename) |
| 54 |
} |
| 55 |
} |
| 56 |
|
| 57 |
func TestDecodeAll(t *testing.T) { |
| 58 |
for _, v := range list { |
| 59 |
if err := iconvg.Decode(nil, v.data, nil); err != nil { |
| 60 |
t.Errorf("%q: %v", v.name, err) |
| 61 |
continue |
| 62 |
} |
| 63 |
} |
| 64 |
} |