-
Notifications
You must be signed in to change notification settings - Fork 4
/
svg_test.go
60 lines (51 loc) · 1.03 KB
/
svg_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
59
60
package qrsvg
import (
"image/color"
"io/ioutil"
"testing"
)
var example = mustReadFile("example.svg")
func mustReadFile(f string) []byte {
b, err := ioutil.ReadFile(f)
if err != nil {
panic(err)
}
return b
}
func TestNew1(t *testing.T) {
qr, err := New("")
if err == nil {
t.Errorf("err = %v; want non-nil", err)
}
if qr != nil {
t.Errorf("qr = %v, want %v", qr, nil)
}
}
func TestNew2(t *testing.T) {
qr, err := New("https://github.com/wamuir/svg-qr-code")
if err != nil {
t.Errorf("err = %v; want %v", err, nil)
}
if qr == nil {
t.Errorf("qr = %v, want non-nil", qr)
}
}
func TestHex(t *testing.T) {
h := hex(color.Black)
if h != "#000000" {
t.Errorf("h = %v, want %v", h, "#000000")
}
}
func TestQRString(t *testing.T) {
qr, err := New("https://github.com/wamuir/svg-qr-code")
if err != nil {
t.Errorf("err = %v; want %v", err, nil)
}
if qr == nil {
t.Errorf("qr = %v, want non-nil", qr)
}
svg := qr.String()
if svg != string(example) {
t.Errorf("svg = %v, want %v", svg, string(example))
}
}