genki-mime-types 1.15 → 1.15.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,275 +0,0 @@
1
- #! /usr/bin/env ruby
2
- #--
3
- # MIME::Types for Ruby
4
- # http://rubyforge.org/projects/mime-types/
5
- # Copyright 2003 - 2005 Austin Ziegler.
6
- # Licensed under a MIT-style licence.
7
- #
8
- # $Id$
9
- #++
10
- $LOAD_PATH.unshift("#{File.dirname(__FILE__)}/../lib") if __FILE__ == $0
11
-
12
- require 'mime/types'
13
- require 'test/unit'
14
-
15
- class Test_MIME__Type < Test::Unit::TestCase #:nodoc:
16
- def setup
17
- @zip = MIME::Type.new('x-appl/x-zip') { |t| t.extensions = ['zip', 'zp'] }
18
- end
19
-
20
- def test_CMP # '<=>'
21
- assert(MIME::Type.new('text/plain') == MIME::Type.new('text/plain'))
22
- assert(MIME::Type.new('text/plain') != MIME::Type.new('image/jpeg'))
23
- assert(MIME::Type.new('text/plain') == 'text/plain')
24
- assert(MIME::Type.new('text/plain') != 'image/jpeg')
25
- assert(MIME::Type.new('text/plain') > MIME::Type.new('text/html'))
26
- assert(MIME::Type.new('text/plain') > 'text/html')
27
- assert(MIME::Type.new('text/html') < MIME::Type.new('text/plain'))
28
- assert(MIME::Type.new('text/html') < 'text/plain')
29
- assert('text/html' == MIME::Type.new('text/html'))
30
- assert('text/html' < MIME::Type.new('text/plain'))
31
- assert('text/plain' > MIME::Type.new('text/html'))
32
- end
33
-
34
- def test_ascii?
35
- assert(MIME::Type.new('text/plain').ascii?)
36
- assert(!MIME::Type.new('image/jpeg').ascii?)
37
- assert(!MIME::Type.new('application/x-msword').ascii?)
38
- assert(MIME::Type.new('text/vCard').ascii?)
39
- assert(!MIME::Type.new('application/pkcs7-mime').ascii?)
40
- assert(!@zip.ascii?)
41
- end
42
-
43
- def test_binary?
44
- assert(!MIME::Type.new('text/plain').binary?)
45
- assert(MIME::Type.new('image/jpeg').binary?)
46
- assert(MIME::Type.new('application/x-msword').binary?)
47
- assert(!MIME::Type.new('text/vCard').binary?)
48
- assert(MIME::Type.new('application/pkcs7-mime').binary?)
49
- assert(@zip.binary?)
50
- end
51
-
52
- def test_complete?
53
- assert_nothing_raised do
54
- @yaml = MIME::Type.from_array('text/x-yaml', ['yaml', 'yml'], '8bit',
55
- 'linux')
56
- end
57
- assert(@yaml.complete?)
58
- assert_nothing_raised { @yaml.extensions = nil }
59
- assert(!@yaml.complete?)
60
- end
61
-
62
- def test_content_type
63
- assert_equal(MIME::Type.new('text/plain').content_type, 'text/plain')
64
- assert_equal(MIME::Type.new('image/jpeg').content_type, 'image/jpeg')
65
- assert_equal(MIME::Type.new('application/x-msword').content_type, 'application/x-msword')
66
- assert_equal(MIME::Type.new('text/vCard').content_type, 'text/vCard')
67
- assert_equal(MIME::Type.new('application/pkcs7-mime').content_type, 'application/pkcs7-mime')
68
- assert_equal(@zip.content_type, 'x-appl/x-zip');
69
- end
70
-
71
- def test_encoding
72
- assert_equal(MIME::Type.new('text/plain').encoding, 'quoted-printable')
73
- assert_equal(MIME::Type.new('image/jpeg').encoding, 'base64')
74
- assert_equal(MIME::Type.new('application/x-msword').encoding, 'base64')
75
- assert_equal(MIME::Type.new('text/vCard').encoding, 'quoted-printable')
76
- assert_equal(MIME::Type.new('application/pkcs7-mime').encoding, 'base64')
77
- assert_nothing_raised do
78
- @yaml = MIME::Type.from_array('text/x-yaml', ['yaml', 'yml'], '8bit',
79
- 'linux')
80
- end
81
- assert_equal(@yaml.encoding, '8bit')
82
- assert_nothing_raised { @yaml.encoding = 'base64' }
83
- assert_equal(@yaml.encoding, 'base64')
84
- assert_nothing_raised { @yaml.encoding = :default }
85
- assert_equal(@yaml.encoding, 'quoted-printable')
86
- assert_raises(ArgumentError) { @yaml.encoding = 'binary' }
87
- assert_equal(@zip.encoding, 'base64')
88
- end
89
-
90
- def test_eql?
91
- assert(MIME::Type.new('text/plain').eql?(MIME::Type.new('text/plain')))
92
- assert(!MIME::Type.new('text/plain').eql?(MIME::Type.new('image/jpeg')))
93
- assert(!MIME::Type.new('text/plain').eql?('text/plain'))
94
- assert(!MIME::Type.new('text/plain').eql?('image/jpeg'))
95
- end
96
-
97
- def test_extensions
98
- assert_nothing_raised do
99
- @yaml = MIME::Type.from_array('text/x-yaml', ['yaml', 'yml'], '8bit',
100
- 'linux')
101
- end
102
- assert_equal(@yaml.extensions, ['yaml', 'yml'])
103
- assert_nothing_raised { @yaml.extensions = 'yaml' }
104
- assert_equal(@yaml.extensions, ['yaml'])
105
- assert_equal(@zip.extensions.size, 2)
106
- assert_equal(@zip.extensions, ['zip', 'zp'])
107
- end
108
-
109
- def test_like?
110
- assert(MIME::Type.new('text/plain').like?(MIME::Type.new('text/plain')))
111
- assert(MIME::Type.new('text/plain').like?(MIME::Type.new('text/x-plain')))
112
- assert(!MIME::Type.new('text/plain').like?(MIME::Type.new('image/jpeg')))
113
- assert(MIME::Type.new('text/plain').like?('text/plain'))
114
- assert(MIME::Type.new('text/plain').like?('text/x-plain'))
115
- assert(!MIME::Type.new('text/plain').like?('image/jpeg'))
116
- end
117
-
118
- def test_media_type
119
- assert_equal(MIME::Type.new('text/plain').media_type, 'text')
120
- assert_equal(MIME::Type.new('image/jpeg').media_type, 'image')
121
- assert_equal(MIME::Type.new('application/x-msword').media_type, 'application')
122
- assert_equal(MIME::Type.new('text/vCard').media_type, 'text')
123
- assert_equal(MIME::Type.new('application/pkcs7-mime').media_type, 'application')
124
- assert_equal(MIME::Type.new('x-chemical/x-pdb').media_type, 'chemical')
125
- assert_equal(@zip.media_type, 'appl')
126
- end
127
-
128
- def test_platform?
129
- assert_nothing_raised do
130
- @yaml = MIME::Type.from_array('text/x-yaml', ['yaml', 'yml'], '8bit',
131
- 'oddbox')
132
- end
133
- assert(!@yaml.platform?)
134
- assert_nothing_raised { @yaml.system = nil }
135
- assert(!@yaml.platform?)
136
- assert_nothing_raised { @yaml.system = /#{RUBY_PLATFORM}/ }
137
- assert(@yaml.platform?)
138
- end
139
-
140
- def test_raw_media_type
141
- assert_equal(MIME::Type.new('text/plain').raw_media_type, 'text')
142
- assert_equal(MIME::Type.new('image/jpeg').raw_media_type, 'image')
143
- assert_equal(MIME::Type.new('application/x-msword').raw_media_type, 'application')
144
- assert_equal(MIME::Type.new('text/vCard').raw_media_type, 'text')
145
- assert_equal(MIME::Type.new('application/pkcs7-mime').raw_media_type, 'application')
146
-
147
- assert_equal(MIME::Type.new('x-chemical/x-pdb').raw_media_type, 'x-chemical')
148
- assert_equal(@zip.raw_media_type, 'x-appl')
149
- end
150
-
151
- def test_raw_sub_type
152
- assert_equal(MIME::Type.new('text/plain').raw_sub_type, 'plain')
153
- assert_equal(MIME::Type.new('image/jpeg').raw_sub_type, 'jpeg')
154
- assert_equal(MIME::Type.new('application/x-msword').raw_sub_type, 'x-msword')
155
- assert_equal(MIME::Type.new('text/vCard').raw_sub_type, 'vCard')
156
- assert_equal(MIME::Type.new('application/pkcs7-mime').raw_sub_type, 'pkcs7-mime')
157
- assert_equal(@zip.raw_sub_type, 'x-zip')
158
- end
159
-
160
- def test_registered?
161
- assert(MIME::Type.new('text/plain').registered?)
162
- assert(MIME::Type.new('image/jpeg').registered?)
163
- assert(!MIME::Type.new('application/x-msword').registered?)
164
- assert(MIME::Type.new('text/vCard').registered?)
165
- assert(MIME::Type.new('application/pkcs7-mime').registered?)
166
- assert(!@zip.registered?)
167
- end
168
-
169
- def test_signature?
170
- assert(!MIME::Type.new('text/plain').signature?)
171
- assert(!MIME::Type.new('image/jpeg').signature?)
172
- assert(!MIME::Type.new('application/x-msword').signature?)
173
- assert(MIME::Type.new('text/vCard').signature?)
174
- assert(MIME::Type.new('application/pkcs7-mime').signature?)
175
- end
176
-
177
- def test_simplified
178
- assert_equal(MIME::Type.new('text/plain').simplified, 'text/plain')
179
- assert_equal(MIME::Type.new('image/jpeg').simplified, 'image/jpeg')
180
- assert_equal(MIME::Type.new('application/x-msword').simplified, 'application/msword')
181
- assert_equal(MIME::Type.new('text/vCard').simplified, 'text/vcard')
182
- assert_equal(MIME::Type.new('application/pkcs7-mime').simplified, 'application/pkcs7-mime')
183
- assert_equal(MIME::Type.new('x-chemical/x-pdb').simplified, 'chemical/pdb')
184
- end
185
-
186
- def test_sub_type
187
- assert_equal(MIME::Type.new('text/plain').sub_type, 'plain')
188
- assert_equal(MIME::Type.new('image/jpeg').sub_type, 'jpeg')
189
- assert_equal(MIME::Type.new('application/x-msword').sub_type, 'msword')
190
- assert_equal(MIME::Type.new('text/vCard').sub_type, 'vcard')
191
- assert_equal(MIME::Type.new('application/pkcs7-mime').sub_type, 'pkcs7-mime')
192
- assert_equal(@zip.sub_type, 'zip')
193
- end
194
-
195
- def test_system
196
- assert_nothing_raised do
197
- @yaml = MIME::Type.from_array('text/x-yaml', ['yaml', 'yml'], '8bit',
198
- 'linux')
199
- end
200
- assert_equal(@yaml.system, %r{linux})
201
- assert_nothing_raised { @yaml.system = /win32/ }
202
- assert_equal(@yaml.system, %r{win32})
203
- assert_nothing_raised { @yaml.system = nil }
204
- assert_nil(@yaml.system)
205
- end
206
-
207
- def test_system?
208
- assert_nothing_raised do
209
- @yaml = MIME::Type.from_array('text/x-yaml', ['yaml', 'yml'], '8bit',
210
- 'linux')
211
- end
212
- assert(@yaml.system?)
213
- assert_nothing_raised { @yaml.system = nil }
214
- assert(!@yaml.system?)
215
- end
216
-
217
- def test_to_a
218
- assert_nothing_raised do
219
- @yaml = MIME::Type.from_array('text/x-yaml', ['yaml', 'yml'], '8bit',
220
- 'linux')
221
- end
222
- assert_equal(@yaml.to_a, ['text/x-yaml', ['yaml', 'yml'], '8bit',
223
- /linux/, nil, nil, nil, false])
224
- end
225
-
226
- def test_to_hash
227
- assert_nothing_raised do
228
- @yaml = MIME::Type.from_array('text/x-yaml', ['yaml', 'yml'], '8bit',
229
- 'linux')
230
- end
231
- assert_equal(@yaml.to_hash,
232
- { 'Content-Type' => 'text/x-yaml',
233
- 'Content-Transfer-Encoding' => '8bit',
234
- 'Extensions' => ['yaml', 'yml'],
235
- 'System' => /linux/,
236
- 'Registered' => false,
237
- 'URL' => nil,
238
- 'Obsolete' => nil,
239
- 'Docs' => nil })
240
- end
241
-
242
- def test_to_s
243
- assert_equal("#{MIME::Type.new('text/plain')}", 'text/plain')
244
- end
245
-
246
- def test_s_constructors
247
- assert_not_nil(@zip)
248
- yaml = MIME::Type.from_array('text/x-yaml', ['yaml', 'yml'], '8bit',
249
- 'linux')
250
- assert_instance_of(MIME::Type, yaml)
251
- yaml = MIME::Type.from_hash('Content-Type' => 'text/x-yaml',
252
- 'Content-Transfer-Encoding' => '8bit',
253
- 'System' => 'linux',
254
- 'Extensions' => ['yaml', 'yml'])
255
- assert_instance_of(MIME::Type, yaml)
256
- yaml = MIME::Type.new('text/x-yaml') do |y|
257
- y.extensions = ['yaml', 'yml']
258
- y.encoding = '8bit'
259
- y.system = 'linux'
260
- end
261
- assert_instance_of(MIME::Type, yaml)
262
- assert_raises(MIME::InvalidContentType) { MIME::Type.new('apps') }
263
- assert_raises(MIME::InvalidContentType) { MIME::Type.new(nil) }
264
- end
265
-
266
- def test_s_simplified
267
- assert_equal(MIME::Type.simplified('text/plain'), 'text/plain')
268
- assert_equal(MIME::Type.simplified('image/jpeg'), 'image/jpeg')
269
- assert_equal(MIME::Type.simplified('application/x-msword'), 'application/msword')
270
- assert_equal(MIME::Type.simplified('text/vCard'), 'text/vcard')
271
- assert_equal(MIME::Type.simplified('application/pkcs7-mime'), 'application/pkcs7-mime')
272
- assert_equal(@zip.simplified, 'appl/zip')
273
- assert_equal(MIME::Type.simplified('x-xyz/abc'), 'xyz/abc')
274
- end
275
- end
@@ -1,77 +0,0 @@
1
- #! /usr/bin/env ruby
2
- #--
3
- # MIME::Types for Ruby
4
- # http://rubyforge.org/projects/mime-types/
5
- # Copyright 2003 - 2005 Austin Ziegler.
6
- # Licensed under a MIT-style licence.
7
- #
8
- # $Id$
9
- #++
10
- $LOAD_PATH.unshift("#{File.dirname(__FILE__)}/../lib") if __FILE__ == $0
11
-
12
- require 'mime/types'
13
- require 'test/unit'
14
-
15
- class TestMIME__Types < Test::Unit::TestCase #:nodoc:
16
- def test_s_AREF # singleton method '[]'
17
- text_plain = MIME::Type.new('text/plain') do |t|
18
- t.encoding = '8bit'
19
- t.extensions = ['asc', 'txt', 'c', 'cc', 'h', 'hh', 'cpp', 'hpp',
20
- 'dat', 'hlp']
21
- end
22
- text_plain_vms = MIME::Type.new('text/plain') do |t|
23
- t.encoding = '8bit'
24
- t.extensions = ['doc']
25
- t.system = 'vms'
26
- end
27
- text_vnd_fly = MIME::Type.new('text/vnd.fly')
28
- assert_equal(MIME::Types['text/plain'].sort,
29
- [text_plain, text_plain_vms].sort)
30
-
31
- tst_bmp = MIME::Types["image/x-bmp"] +
32
- MIME::Types["image/vnd.wap.wbmp"] + MIME::Types["image/x-win-bmp"]
33
-
34
- assert_equal(tst_bmp.sort, MIME::Types[/bmp$/].sort)
35
- assert_nothing_raised {
36
- MIME::Types['image/bmp'][0].system = RUBY_PLATFORM
37
- }
38
- assert_equal([MIME::Type.from_array('image/x-bmp', ['bmp'])],
39
- MIME::Types[/bmp$/, { :platform => true }])
40
-
41
- assert(MIME::Types['text/vnd.fly', { :complete => true }].empty?)
42
- assert(!MIME::Types['text/plain', { :complete => true} ].empty?)
43
- end
44
-
45
- def test_s_add
46
- assert_nothing_raised do
47
- @eruby = MIME::Type.new("application/x-eruby") do |t|
48
- t.extensions = "rhtml"
49
- t.encoding = "8bit"
50
- end
51
-
52
- MIME::Types.add(@eruby)
53
- end
54
-
55
- assert_equal(MIME::Types['application/x-eruby'], [@eruby])
56
- end
57
-
58
- def test_s_type_for
59
- assert_equal(MIME::Types.type_for('xml').sort, [ MIME::Types['text/xml'], MIME::Types['application/xml'] ].sort)
60
- assert_equal(MIME::Types.type_for('gif'), MIME::Types['image/gif'])
61
- assert_nothing_raised do
62
- MIME::Types['image/gif'][0].system = RUBY_PLATFORM
63
- end
64
- assert_equal(MIME::Types.type_for('gif', true), MIME::Types['image/gif'])
65
- assert(MIME::Types.type_for('zzz').empty?)
66
- end
67
-
68
- def test_s_of
69
- assert_equal(MIME::Types.of('xml').sort, [ MIME::Types['text/xml'], MIME::Types['application/xml'] ].sort)
70
- assert_equal(MIME::Types.of('gif'), MIME::Types['image/gif'])
71
- assert_nothing_raised do
72
- MIME::Types['image/gif'][0].system = RUBY_PLATFORM
73
- end
74
- assert_equal(MIME::Types.of('gif', true), MIME::Types['image/gif'])
75
- assert(MIME::Types.of('zzz').empty?)
76
- end
77
- end
data/tests/testall.rb DELETED
@@ -1,18 +0,0 @@
1
- #! /usr/bin/env ruby
2
- #--
3
- # MIME::Types for Ruby
4
- # http://rubyforge.org/projects/mime-types/
5
- # Copyright 2003 - 2005 Austin Ziegler.
6
- # Licensed under a MIT-style licence.
7
- #
8
- # $Id$
9
- #++
10
-
11
- $LOAD_PATH.unshift("#{File.dirname(__FILE__)}/../lib") if __FILE__ == $0
12
-
13
- puts "Checking for test cases:"
14
- Dir['tc_*.rb'].each do |testcase|
15
- puts "\t#{testcase}"
16
- require testcase
17
- end
18
- puts