-
Notifications
You must be signed in to change notification settings - Fork 34
/
asset_test.go
162 lines (125 loc) · 3.63 KB
/
asset_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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
package train
import (
"github.com/shaoshing/gotest"
"testing"
)
func init() {
Config.Verbose = true
}
func TestReadingNormalAssets(t *testing.T) {
assert.Test = t
var content string
var err error
content, _ = ReadAsset("/assets/javascripts/normal.js")
assert.Equal("@normal.js\n", content)
content, _ = ReadAsset("/assets/javascripts/sub/normal.js")
assert.Equal("@sub/normal.js\n", content)
_, err = ReadAsset("/assets/not/exists/normal.js")
assert.Equal("Asset Not Found: /assets/not/exists/normal.js", err.Error())
content, _ = ReadAsset("/assets/stylesheets/normal.css")
assert.Equal("normal.css\n", content)
content, _ = ReadAsset("/assets/stylesheets/sub/normal.css")
assert.Equal("sub/normal.css\n", content)
_, err = ReadAsset("/assets/not/exists/normal.css")
assert.Equal("Asset Not Found: /assets/not/exists/normal.css", err.Error())
_, err = ReadAsset("/assets/static.txt")
assert.Equal("Unsupported Asset: /assets/static.txt", err.Error())
}
func TestReadingSass(t *testing.T) {
assert.Test = t
content, err := ReadAsset("/assets/stylesheets/app.css")
if err != nil {
panic(err)
}
assert.Contain("h1", content)
assert.Contain("h2", content)
content, err = ReadAsset("/assets/stylesheets/app2.css")
if err != nil {
panic(err)
}
assert.Contain("h2", content)
assert.Contain("h3", content)
}
func TestReadingCoffee(t *testing.T) {
assert.Test = t
content, err := ReadAsset("/assets/javascripts/app.js")
if err != nil {
panic(err)
}
assert.Contain("square", content)
}
func TestRequireDirective(t *testing.T) {
assert.Test = t
Config.BundleAssets = true
defer func() {
Config.BundleAssets = false
}()
content, err := ReadAsset("/assets/javascripts/require2.js")
if err != nil {
panic(err)
}
assert.Equal(`@normal.js
@sub/normal.js
`, content)
content, err = ReadAsset("/assets/stylesheets/require2.css")
if err != nil {
panic(err)
}
assert.Equal(`normal.css
sub/normal.css
`, content)
}
func TestReadingAssetsWithRequire(t *testing.T) {
assert.Test = t
Config.BundleAssets = true
var content string
var err error
content, _ = ReadAsset("/assets/javascripts/require.js")
assert.Contain("@sub/normal.js", content)
assert.Contain("@sub/normal1.coffee", content)
assert.Contain("@sub/require.js", content)
assert.Contain("@normal.js", content)
assert.Contain("@normal1.coffee", content)
assert.Contain("@require.js", content)
content, _ = ReadAsset("/assets/javascripts/require.coffee")
assert.Contain("@normal.js", content)
assert.Contain("@require.coffee", content)
content, _ = ReadAsset("/assets/stylesheets/require.css")
assert.Equal(`normal.css
sub/normal.css
sub/require.css
require.css
`, content)
content, _ = ReadAsset("/assets/stylesheets/require.scss")
assert.Equal(`.normal1-scss {
color: blue; }
sub/normal.css
sub/require.css
.normal1-scss {
color: blue; }
.foo .bar {
color: red; }`, content)
// In current can not remove require comment lines
content, _ = ReadAsset("/assets/stylesheets/require.sass")
assert.Equal(`.normal1-scss {
color: blue; }
sub/normal.css
sub/require.css
.foo {
color: red; }`, content)
_, err = ReadAsset("/assets/javascripts/error.js")
assert.Equal(`Asset Not Found: not/found.js
--- required by /assets/javascripts/error.js`, err.Error())
_, err = ReadAsset("/assets/javascripts/errors.js")
assert.Equal(`Asset Not Found: not/found.js
--- required by javascripts/error.js
--- required by /assets/javascripts/errors.js`, err.Error())
Config.BundleAssets = false
content, _ = ReadAsset("/assets/stylesheets/require.css")
assert.Equal(`/*
*= require stylesheets/normal
*= require stylesheets/sub/require
*/
require.css
`, content)
}