shiny/iconvg: make a decoding example_test.
Change-Id: I5e1c4d317ac00fddc787e41fd966c3f9e221bf78
Reviewed-on: https://go-review.googlesource.com/30570
Reviewed-by: David Crawshaw <crawshaw@golang.org>
diff --git a/shiny/iconvg/decode_test.go b/shiny/iconvg/decode_test.go
index d3be5a6..1b5dfea 100644
--- a/shiny/iconvg/decode_test.go
+++ b/shiny/iconvg/decode_test.go
@@ -122,26 +122,6 @@
}
}
-func rasterizeASCIIArt(width int, encoded []byte) (string, error) {
- dst := image.NewAlpha(image.Rect(0, 0, width, width))
- var z Rasterizer
- z.SetDstImage(dst, dst.Bounds(), draw.Src)
- if err := Decode(&z, encoded, nil); err != nil {
- return "", err
- }
-
- const asciiArt = ".++8"
- buf := make([]byte, 0, width*(width+1))
- for y := 0; y < width; y++ {
- for x := 0; x < width; x++ {
- a := dst.AlphaAt(x, y).A
- buf = append(buf, asciiArt[a>>6])
- }
- buf = append(buf, '\n')
- }
- return string(buf), nil
-}
-
func TestDisassembleActionInfo(t *testing.T) {
ivgData, err := ioutil.ReadFile(filepath.FromSlash("testdata/action-info.ivg"))
if err != nil {
@@ -217,49 +197,6 @@
}
}
-func TestDecodeActionInfo(t *testing.T) {
- ivgData, err := ioutil.ReadFile(filepath.FromSlash("testdata/action-info.ivg"))
- if err != nil {
- t.Fatal(err)
- }
- got, err := rasterizeASCIIArt(24, ivgData)
- if err != nil {
- t.Fatal(err)
- }
-
- want := strings.Join([]string{
- "........................",
- "........................",
- "........++8888++........",
- "......+8888888888+......",
- ".....+888888888888+.....",
- "....+88888888888888+....",
- "...+8888888888888888+...",
- "...88888888..88888888...",
- "..+88888888..88888888+..",
- "..+888888888888888888+..",
- "..88888888888888888888..",
- "..888888888..888888888..",
- "..888888888..888888888..",
- "..888888888..888888888..",
- "..+88888888..88888888+..",
- "..+88888888..88888888+..",
- "...88888888..88888888...",
- "...+8888888888888888+...",
- "....+88888888888888+....",
- ".....+888888888888+.....",
- "......+8888888888+......",
- "........++8888++........",
- "........................",
- "........................",
- }, "\n") + "\n"
-
- if got != want {
- t.Errorf("got:\n%s\nwant:\n%s", got, want)
- diffLines(t, got, want)
- }
-}
-
func TestRasterizer(t *testing.T) {
testCases := []string{
"testdata/action-info",
diff --git a/shiny/iconvg/example_test.go b/shiny/iconvg/example_test.go
new file mode 100644
index 0000000..06346c8
--- /dev/null
+++ b/shiny/iconvg/example_test.go
@@ -0,0 +1,68 @@
+// Copyright 2016 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package iconvg_test
+
+import (
+ "image"
+ "image/draw"
+ "io/ioutil"
+ "log"
+ "os"
+ "path/filepath"
+
+ "golang.org/x/exp/shiny/iconvg"
+)
+
+func Example() {
+ ivgData, err := ioutil.ReadFile(filepath.FromSlash("testdata/action-info.ivg"))
+ if err != nil {
+ log.Fatal(err)
+ }
+
+ const width = 24
+ dst := image.NewAlpha(image.Rect(0, 0, width, width))
+ var z iconvg.Rasterizer
+ z.SetDstImage(dst, dst.Bounds(), draw.Src)
+ if err := iconvg.Decode(&z, ivgData, nil); err != nil {
+ log.Fatal(err)
+ }
+
+ const asciiArt = ".++8"
+ buf := make([]byte, 0, width*(width+1))
+ for y := 0; y < width; y++ {
+ for x := 0; x < width; x++ {
+ a := dst.AlphaAt(x, y).A
+ buf = append(buf, asciiArt[a>>6])
+ }
+ buf = append(buf, '\n')
+ }
+ os.Stdout.Write(buf)
+
+ // Output:
+ // ........................
+ // ........................
+ // ........++8888++........
+ // ......+8888888888+......
+ // .....+888888888888+.....
+ // ....+88888888888888+....
+ // ...+8888888888888888+...
+ // ...88888888..88888888...
+ // ..+88888888..88888888+..
+ // ..+888888888888888888+..
+ // ..88888888888888888888..
+ // ..888888888..888888888..
+ // ..888888888..888888888..
+ // ..888888888..888888888..
+ // ..+88888888..88888888+..
+ // ..+88888888..88888888+..
+ // ...88888888..88888888...
+ // ...+8888888888888888+...
+ // ....+88888888888888+....
+ // .....+888888888888+.....
+ // ......+8888888888+......
+ // ........++8888++........
+ // ........................
+ // ........................
+}