-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathshimmer_test.go
58 lines (51 loc) · 1.21 KB
/
shimmer_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package shimmer
import (
"bytes"
"encoding/base64"
"strings"
"syscall/js"
"testing"
"github.com/anthonynsimon/bild/adjust"
"github.com/anthonynsimon/bild/imgio"
)
func TestSimple(t *testing.T) {
sh := New()
if sh.done == nil {
t.Errorf("done chan isn't initialized")
}
}
func TestDOM(t *testing.T) {
doc := js.Global().Get("document")
elem := doc.Call("createElement", "div")
inputString := "hello world"
elem.Set("innerText", inputString)
out := elem.Get("innerText")
// need Contains because a "\n" gets appended in the output
if !strings.Contains(out.String(), inputString) {
t.Errorf("unexpected output string. Expected %q to contain %q", out.String(), inputString)
}
}
func BenchmarkAdjustImage(b *testing.B) {
img, err := imgio.Open("testdata/dragon.jpg")
if err != nil {
b.Error(err)
return
}
// var buf strings.Builder
var buf bytes.Buffer
// b64Enc := base64.NewEncoder(base64.StdEncoding, &buf)
var sink string
for i := 0; i < b.N; i++ {
img2 := adjust.Brightness(img, 0.4)
enc := imgio.JPEGEncoder(90)
err = enc(&buf, img2)
if err != nil {
b.Error(err)
return
}
// b64Enc.Close()
sink = base64.StdEncoding.EncodeToString(buf.Bytes())
buf.Reset()
}
b.Log(sink[:10])
}