forked from fyne-io/fyne
-
Notifications
You must be signed in to change notification settings - Fork 0
/
json_test.go
88 lines (78 loc) · 3 KB
/
json_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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package theme
import (
"image/color"
"testing"
"fyne.io/fyne/v2"
intRepo "fyne.io/fyne/v2/internal/repository"
"fyne.io/fyne/v2/storage/repository"
"github.com/stretchr/testify/assert"
)
func TestFromJSON(t *testing.T) {
repository.Register("file", intRepo.NewFileRepository()) // file uri resolving (avoid test import loop)
th, err := FromJSON(`{
"Colors": {"background": "#c0c0c0ff"},
"Colors-light": {"foreground": "#ffffffff"},
"Sizes": {"iconInline": 5.0},
"Fonts": {"monospace": "file://./testdata/NotoMono-Regular.ttf"},
"Icons": {"cancel": "file://./testdata/cancel_Paths.svg"}
}`)
assert.Nil(t, err)
assert.Equal(t, &color.NRGBA{R: 0xc0, G: 0xc0, B: 0xc0, A: 0xff}, th.Color(ColorNameBackground, VariantDark))
assert.Equal(t, &color.NRGBA{R: 0xc0, G: 0xc0, B: 0xc0, A: 0xff}, th.Color(ColorNameBackground, VariantLight))
assert.Equal(t, &color.NRGBA{R: 0xff, G: 0xff, B: 0xff, A: 0xff}, th.Color(ColorNameForeground, VariantLight))
assert.Equal(t, float32(5), th.Size(SizeNameInlineIcon))
assert.Equal(t, "NotoMono-Regular.ttf", th.Font(fyne.TextStyle{Monospace: true}).Name())
assert.Equal(t, "cancel_Paths.svg", th.Icon(IconNameCancel).Name())
th, err = FromJSON(`{
"Fonts":{"monospace":"file"}
}0000{
"Fonts":{"monospace":"file"}
}0000{
"Fonts":{"monospace":"file"}
}0000{
"Fonts":{"monospace":"file"}
}0000{
"Fonts":{"monospace":"file"}
}0000{
"Fonts":{"monospace":"file"}
}0000{
"Fonts":{"monospace":"file"}
}0000{
"F
`)
assert.Nil(t, err)
th.Font(fyne.TextStyle{Monospace: true}).Name()
}
func TestFromTOML_Resource(t *testing.T) {
r, err := fyne.LoadResourceFromPath("./testdata/theme.json")
assert.Nil(t, err)
th, err := FromJSON(string(r.Content()))
assert.Nil(t, err)
assert.Equal(t, &color.NRGBA{R: 0x30, G: 0x30, B: 0x30, A: 0xff}, th.Color(ColorNameBackground, VariantLight))
assert.Equal(t, &color.NRGBA{R: 0xff, G: 0xff, B: 0xff, A: 0xff}, th.Color(ColorNameForeground, VariantDark))
assert.Equal(t, &color.NRGBA{R: 0xc0, G: 0xc0, B: 0xc0, A: 0xff}, th.Color(ColorNameForeground, VariantLight))
assert.Equal(t, float32(10), th.Size(SizeNameInlineIcon))
}
func TestHexColor(t *testing.T) {
c, err := hexColor("#abc").color()
assert.Nil(t, err)
assert.Equal(t, &color.NRGBA{R: 0xaa, G: 0xbb, B: 0xcc, A: 0xff}, c)
c, err = hexColor("abc").color()
assert.Nil(t, err)
assert.Equal(t, &color.NRGBA{R: 0xaa, G: 0xbb, B: 0xcc, A: 0xff}, c)
c, err = hexColor("#abcd").color()
assert.Nil(t, err)
assert.Equal(t, &color.NRGBA{R: 0xaa, G: 0xbb, B: 0xcc, A: 0xdd}, c)
c, err = hexColor("#a1b2c3").color()
assert.Nil(t, err)
assert.Equal(t, &color.NRGBA{R: 0xa1, G: 0xb2, B: 0xc3, A: 0xff}, c)
c, err = hexColor("a1b2c3").color()
assert.Nil(t, err)
assert.Equal(t, &color.NRGBA{R: 0xa1, G: 0xb2, B: 0xc3, A: 0xff}, c)
c, err = hexColor("#a1b2c3f4").color()
assert.Nil(t, err)
assert.Equal(t, &color.NRGBA{R: 0xa1, G: 0xb2, B: 0xc3, A: 0xf4}, c)
c, err = hexColor("a1b2c3f4").color()
assert.Nil(t, err)
assert.Equal(t, &color.NRGBA{R: 0xa1, G: 0xb2, B: 0xc3, A: 0xf4}, c)
}