This repository has been archived by the owner on Aug 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
mime-types-spec.io
executable file
·243 lines (208 loc) · 7.71 KB
/
mime-types-spec.io
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
/*
class TestMIMETypes < Minitest::Test
def setup
@mime_types = MIME::Types.new
@mime_types.add(MIME::Type.new(['text/plain', %w(txt)]),
MIME::Type.new(['image/jpeg', %w(jpg jpeg)]),
MIME::Type.new('application/x-wordperfect6.1'),
MIME::Type.new('content-type' => 'application/x-www-form-urlencoded', 'registered' => true),
MIME::Type.new(['application/x-gzip', %w(gz)]),
MIME::Type.new(['application/gzip', %W(gz)]))
end
def test_enumerable
assert(@mime_types.any? {|type| type.content_type == 'text/plain'})
end
def test_index_with_mime_type
xtxp = MIME::Type.new('x-text/x-plain')
assert_includes(@mime_types[xtxp], 'text/plain')
assert_equal(1, @mime_types[xtxp].size)
end
def test_index_with_regex
assert_includes(@mime_types[/plain/], 'text/plain')
assert_equal(1, @mime_types[/plain/].size)
end
def test_index_with_string
assert_includes(@mime_types['text/plain'], 'text/plain')
assert_equal(1, @mime_types['text/plain'].size)
end
def test_index_with_complete_flag
assert_empty(@mime_types['text/vnd.fly', complete: true])
refute_empty(@mime_types['text/plain', complete: true])
end
def test_index_with_registered_flag
assert_empty(@mime_types['application/x-wordperfect6.1',
registered: true])
refute_empty(@mime_types['application/x-www-form-urlencoded',
registered: true])
refute_empty(@mime_types['application/gzip', registered: true])
refute_equal(@mime_types['application/gzip'].size,
@mime_types['application/gzip', registered: true])
end
def test_index_with_platform_flag
assert_deprecated("MIME::Types#[]", "using the :platform flag") do
assert_empty(MIME::Types['text/plain', platform: true])
end
end
def test_add
eruby = MIME::Type.new("application/x-eruby") do |t|
t.extensions = "rhtml"
t.encoding = "8bit"
end
@mime_types.add(eruby)
assert_equal(@mime_types['application/x-eruby'], [eruby])
end
def test_type_for
assert_equal(%w(application/gzip application/x-gzip),
@mime_types.type_for('gz'))
assert_equal(%w(image/jpeg), MIME::Types.of('foo.jpeg'))
assert_equal(%w(image/jpeg text/plain),
MIME::Types.type_for(%w(foo.txt foo.jpeg)))
assert_equal(@mime_types.of('gif', true), @mime_types['image/gif'])
assert_empty(MIME::Types.type_for('coverallsjson'))
assert_deprecated("MIME::Types#type_for", "using the platform parameter") do
assert_empty(MIME::Types.type_for('jpeg', true))
end
assert_empty(@mime_types.type_for('zzz'))
end
def test_count
assert_equal(6, @mime_types.count)
end
# This tests the instance implementation through the class implementation.
def test_add_type_variant
xtxp = MIME::Type.new('x-text/x-plain')
assert_deprecated("MIME::Types#add_type_variant", "and will be private") do
@mime_types.add_type_variant(xtxp)
end
assert_includes(@mime_types['text/plain'], xtxp)
end
def test_data_version
assert_equal(MIME::Type::VERSION, @mime_types.data_version)
end
# This tests the instance implementation through the class implementation.
def test_index_extensions
xtxp = MIME::Type.new(['x-text/x-plain', %w(tzt)])
assert_deprecated("MIME::Types#index_extensions", "and will be private") do
@mime_types.index_extensions(xtxp)
end
assert_includes(@mime_types.of('tzt'), xtxp)
end
def test_defined_types
assert_deprecated("MIME::Types#defined_types") do
assert_empty(MIME::Types.new.defined_types)
end
refute_empty(@mime_types.defined_types)
end
end
class TestMIMETypesQueryClassMethods < Minitest::Test
def setup
MIME::Types.send(:load_default_mime_types)
end
def test_enumerable
assert(MIME::Types.any? {|type| type.content_type == 'text/plain'})
end
def test_load_from_file
fn = File.expand_path('../fixture/old-data', __FILE__)
assert_deprecated("MIME::Types.load_from_file") do
MIME::Types.load_from_file(fn)
end
end
def test_index_with_mime_type
xtxp = MIME::Type.new('x-text/x-plain')
assert_includes(MIME::Types[xtxp], 'text/plain')
assert_equal(1, MIME::Types[xtxp].size)
end
def test_index_with_regex
assert_includes(MIME::Types[/plain/], 'text/plain')
assert_equal(1, MIME::Types[/plain/].size)
end
def test_index_with_string
assert_includes(MIME::Types['text/plain'], 'text/plain')
assert_equal(1, MIME::Types['text/plain'].size)
end
def test_index_with_complete_flag
assert_empty(MIME::Types['application/1d-interleaved-parityfec', complete: true])
refute_empty(MIME::Types['text/plain', complete: true])
end
def test_index_with_registered_flag
assert_empty(MIME::Types['application/x-wordperfect6.1',
registered: true])
refute_empty(MIME::Types['application/x-www-form-urlencoded',
registered: true])
refute_empty(MIME::Types['application/gzip', registered: true])
refute_equal(MIME::Types['application/gzip'].size,
MIME::Types['application/gzip', registered: true])
end
def test_index_with_platform_flag
assert_deprecated("MIME::Types#[]", "using the :platform flag") do
assert_empty(MIME::Types['text/plain', platform: true])
end
end
def test_type_for
assert_equal(%w(application/xml text/xml), MIME::Types.type_for('xml'))
assert_equal(%w(image/gif), MIME::Types.of('foo.gif'))
assert_equal(%w(application/xml image/gif text/xml),
MIME::Types.type_for(%w(xml gif)))
assert_deprecated("MIME::Types#type_for", "using the platform parameter") do
assert_empty(MIME::Types.type_for('gif', true))
end
assert_empty(MIME::Types.type_for('zzz'))
end
def test_count
assert(MIME::Types.count.nonzero?,
"A lot of types are expected to be known.")
end
def test_cache_file
ENV['RUBY_MIME_TYPES_CACHE'] = 'foo'
assert_deprecated("MIME::Types.cache_file") do
assert_equal('foo', MIME::Types.cache_file)
end
ENV.delete('RUBY_MIME_TYPES_CACHE')
assert_nil(MIME::Types.cache_file)
end
end
class TestMIMETypesClassMethods < Minitest::Test
def setup
MIME::Types.instance_variable_set(:@__types__, nil)
MIME::Types.send(:load_default_mime_types)
end
def test_add_with_type
MIME::Types.add(MIME::Type.new("application/x-eruby"))
refute_empty(MIME::Types['application/x-eruby'])
end
def test_add_with_types
mt = MIME::Types.new
mt.add MIME::Type.new("application/x-eruby")
MIME::Types.add(mt)
refute_empty(MIME::Types['application/x-eruby'])
end
def test_add_with_array
MIME::Types.add([MIME::Type.new("application/x-eruby")])
refute_empty(MIME::Types['application/x-eruby'])
end
def test_add_with_noise_suppression
assert_silent do
MIME::Types.add(MIME::Type.new("application/x-eruby"))
end
assert_output(nil, %r{application/x-eruby is already registered}) do
MIME::Types.add(MIME::Type.new("application/x-eruby"))
end
assert_silent do
MIME::Types.add(MIME::Type.new("application/x-eruby"), :silent)
end
end
def test_add_type_variant
xtxp = MIME::Type.new('x-text/x-plain')
assert_deprecated("MIME::Types#add_type_variant", "and will be private") do
MIME::Types.add_type_variant(xtxp)
end
assert_includes(MIME::Types['text/plain'], xtxp)
end
def test_index_extensions
xtxp = MIME::Type.new(['x-text/x-plain', %w(tzt)])
assert_deprecated("MIME::Types#index_extensions", "and will be private") do
MIME::Types.index_extensions(xtxp)
end
assert_includes(MIME::Types.of('tzt'), xtxp)
end
end
*/