-
Notifications
You must be signed in to change notification settings - Fork 39
/
runner_test.go
129 lines (99 loc) · 3.12 KB
/
runner_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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
package main
import (
"github.com/stretchr/testify/mock"
. "gopkg.in/check.v1"
)
type MockConverter struct {
mock.Mock
}
func (_m *MockConverter) Convert(_a0 string, _a1 string, _a2 Rect) error {
ret := _m.Called(_a0, _a1, _a2)
var r0 error
if rf, ok := ret.Get(0).(func(string, string, Rect) error); ok {
r0 = rf(_a0, _a1, _a2)
} else {
r0 = ret.Error(0)
}
return r0
}
func (_m *MockConverter) Size(_a0 string) (Rect, error) {
ret := _m.Called(_a0)
var r0 Rect
if rf, ok := ret.Get(0).(func(string) Rect); ok {
r0 = rf(_a0)
} else {
r0 = ret.Get(0).(Rect)
}
var r1 error
if rf, ok := ret.Get(1).(func(string) error); ok {
r1 = rf(_a0)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
type RunnerSuite struct {
conv Converter
}
var _ = Suite(&RunnerSuite{
conv: &RunnerSuiteConverter{},
})
type RunnerSuiteConverter struct {
}
func (r *RunnerSuiteConverter) Convert(infile string, outfile string, sourceRect Rect) error {
return nil
}
func (r *RunnerSuiteConverter) Size(infile string) (Rect, error) {
return Rect{60, 60}, nil
}
func (s *RunnerSuite) Testshould_auto_complete_filename_given_missing_in_template(c *C) {
contents := NewContentsFromFile("fixtures/contents-no-sizes-no-files.json")
r := NewRunner(contents, s.conv, "sourcefile.png")
for _, meta := range contents.Images {
c.Check(meta.Filename, Equals, "")
}
r.run()
for _, meta := range contents.Images {
c.Check(meta.Filename, Not(Equals), "")
}
c.Check(contents.Images[0].Filename, Equals, "sourcefile-iphone-20@2x.png")
c.Check(contents.Images[6].Filename, Equals, "sourcefile-ipad-30@1x.png")
}
func (s *RunnerSuite) Test_should_leave_file_as_is_given_in_template(c *C) {
contents := NewContentsFromFile("fixtures/with-files.json")
r := NewRunner(contents, s.conv, "sourcefile.png")
r.run()
for _, meta := range contents.Images {
c.Check(meta.Filename, Not(Equals), "")
}
c.Check(contents.Images[0].Filename, Equals, "Icon-Small@2x.png")
c.Check(contents.Images[1].Filename, Equals, "sourcefile-iphone-20@3x.png")
}
func (s *RunnerSuite) Test_should_use_outdir_given_nonempty(c *C) {
contents := NewContentsFromFile("fixtures/single-file.json")
mk := &MockConverter{}
mk.On("Size", "sourcefile.png").Return(Rect{42, 42}, nil)
// 28 because it's 2/3
mk.On("Convert", "sourcefile.png", "mydir/Icon-Small@2x.png", Rect{42, 42}).Return(nil)
r := NewRunner(contents, mk, "sourcefile.png")
r.OutDir = "mydir"
r.run()
mk.AssertExpectations(c)
}
func (s *RunnerSuite) Test_should_fill_in_computed_size_given_empty_size(c *C) {
contents := NewContentsFromFile("fixtures/contents-no-sizes.json")
r := NewRunner(contents, s.conv, "sourcefile.png")
r.run()
c.Check(contents.Images[0].Size, Equals, "20x20")
}
func (s *RunnerSuite) Test_should_convert_given_list_of_images(c *C) {
contents := NewContentsFromFile("fixtures/contents-appicon.json")
mk := &MockConverter{}
mk.On("Size", "sourcefile.png").Return(Rect{42, 42}, nil)
// 28 because it's 2/3
mk.On("Convert", mock.Anything, mock.Anything, mock.Anything).Return(nil).Times(12)
r := NewRunner(contents, mk, "sourcefile.png")
r.OutDir = "mydir"
r.run()
mk.AssertExpectations(c)
}