Class: TestMIME::TestType

Inherits:
Test::Unit::TestCase
  • Object
show all
Defined in:
lib/mime-types-1.16/test/test_mime_type.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#__test_use_insteadObject

Raises:

  • (NotImplementedError)


352
353
354
# File 'lib/mime-types-1.16/test/test_mime_type.rb', line 352

def __test_use_instead
  raise NotImplementedError, 'Need to write test_use_instead'
end

#_test_default_encodingObject

Raises:

  • (NotImplementedError)


132
133
134
# File 'lib/mime-types-1.16/test/test_mime_type.rb', line 132

def _test_default_encoding
  raise NotImplementedError, 'Need to write test_default_encoding'
end

#_test_docsObject

Raises:

  • (NotImplementedError)


136
137
138
# File 'lib/mime-types-1.16/test/test_mime_type.rb', line 136

def _test_docs
  raise NotImplementedError, 'Need to write test_docs'
end

#_test_docs_equalsObject

Raises:

  • (NotImplementedError)


140
141
142
# File 'lib/mime-types-1.16/test/test_mime_type.rb', line 140

def _test_docs_equals
  raise NotImplementedError, 'Need to write test_docs_equals'
end

#_test_encodingObject

Raises:

  • (NotImplementedError)


151
152
153
# File 'lib/mime-types-1.16/test/test_mime_type.rb', line 151

def _test_encoding
  raise NotImplementedError, 'Need to write test_encoding'
end

#_test_encoding_equalsObject

Raises:

  • (NotImplementedError)


155
156
157
# File 'lib/mime-types-1.16/test/test_mime_type.rb', line 155

def _test_encoding_equals
  raise NotImplementedError, 'Need to write test_encoding_equals'
end

#_test_extensions_equalsObject

Raises:

  • (NotImplementedError)


171
172
173
# File 'lib/mime-types-1.16/test/test_mime_type.rb', line 171

def _test_extensions_equals
  raise NotImplementedError, 'Need to write test_extensions_equals'
end

#_test_obsolete_ehObject

Raises:

  • (NotImplementedError)


194
195
196
# File 'lib/mime-types-1.16/test/test_mime_type.rb', line 194

def _test_obsolete_eh
  raise NotImplementedError, 'Need to write test_obsolete_eh'
end

#_test_obsolete_equalsObject

Raises:

  • (NotImplementedError)


198
199
200
# File 'lib/mime-types-1.16/test/test_mime_type.rb', line 198

def _test_obsolete_equals
  raise NotImplementedError, 'Need to write test_obsolete_equals'
end

#_test_registered_equalsObject

Raises:

  • (NotImplementedError)


243
244
245
# File 'lib/mime-types-1.16/test/test_mime_type.rb', line 243

def _test_registered_equals
  raise NotImplementedError, 'Need to write test_registered_equals'
end

#_test_to_strObject

Raises:

  • (NotImplementedError)


336
337
338
# File 'lib/mime-types-1.16/test/test_mime_type.rb', line 336

def _test_to_str
  raise NotImplementedError, 'Need to write test_to_str'
end

#_test_urlObject

Raises:

  • (NotImplementedError)


340
341
342
# File 'lib/mime-types-1.16/test/test_mime_type.rb', line 340

def _test_url
  raise NotImplementedError, 'Need to write test_url'
end

#_test_url_equalsObject

Raises:

  • (NotImplementedError)


344
345
346
# File 'lib/mime-types-1.16/test/test_mime_type.rb', line 344

def _test_url_equals
  raise NotImplementedError, 'Need to write test_url_equals'
end

#_test_urlsObject

Raises:

  • (NotImplementedError)


348
349
350
# File 'lib/mime-types-1.16/test/test_mime_type.rb', line 348

def _test_urls
  raise NotImplementedError, 'Need to write test_urls'
end

#setupObject



20
21
22
# File 'lib/mime-types-1.16/test/test_mime_type.rb', line 20

def setup
  @zip = MIME::Type.new('x-appl/x-zip') { |t| t.extensions = ['zip', 'zp'] }
end

#test_ascii_ehObject



76
77
78
79
80
81
82
83
# File 'lib/mime-types-1.16/test/test_mime_type.rb', line 76

def test_ascii_eh
  assert(MIME::Type.new('text/plain').ascii?)
  assert(!MIME::Type.new('image/jpeg').ascii?)
  assert(!MIME::Type.new('application/x-msword').ascii?)
  assert(MIME::Type.new('text/vCard').ascii?)
  assert(!MIME::Type.new('application/pkcs7-mime').ascii?)
  assert(!@zip.ascii?)
end

#test_binary_ehObject



85
86
87
88
89
90
91
92
# File 'lib/mime-types-1.16/test/test_mime_type.rb', line 85

def test_binary_eh
  assert(!MIME::Type.new('text/plain').binary?)
  assert(MIME::Type.new('image/jpeg').binary?)
  assert(MIME::Type.new('application/x-msword').binary?)
  assert(!MIME::Type.new('text/vCard').binary?)
  assert(MIME::Type.new('application/pkcs7-mime').binary?)
  assert(@zip.binary?)
end

#test_class_constructorsObject



324
325
326
327
328
329
330
331
332
333
334
# File 'lib/mime-types-1.16/test/test_mime_type.rb', line 324

def test_class_constructors
  assert_not_nil(@zip)
  yaml = MIME::Type.new('text/x-yaml') do |y|
    y.extensions = %w(yaml yml)
    y.encoding = '8bit'
    y.system = 'linux'
  end
  assert_instance_of(MIME::Type, yaml)
  assert_raises(MIME::InvalidContentType) { MIME::Type.new('apps') }
  assert_raises(MIME::InvalidContentType) { MIME::Type.new(nil) }
end

#test_class_from_arrayObject



24
25
26
27
28
29
30
# File 'lib/mime-types-1.16/test/test_mime_type.rb', line 24

def test_class_from_array
  assert_nothing_raised do
    @yaml = MIME::Type.from_array('text/x-yaml', %w(yaml yml), '8bit', 'linux')
  end
  assert_instance_of(MIME::Type, @yaml)
  assert_equal('text/yaml', @yaml.simplified)
end

#test_class_from_hashObject



32
33
34
35
36
37
38
39
40
41
# File 'lib/mime-types-1.16/test/test_mime_type.rb', line 32

def test_class_from_hash
  assert_nothing_raised do
    @yaml = MIME::Type.from_hash('Content-Type' => 'text/x-yaml',
                               'Content-Transfer-Encoding' => '8bit',
                               'System' => 'linux',
                               'Extensions' => %w(yaml yml))
  end
  assert_instance_of(MIME::Type, @yaml)
  assert_equal('text/yaml', @yaml.simplified)
end

#test_class_from_mime_typeObject



43
44
45
46
47
48
49
50
# File 'lib/mime-types-1.16/test/test_mime_type.rb', line 43

def test_class_from_mime_type
  assert_nothing_raised do
    @zip2 = MIME::Type.from_mime_type(@zip)
  end
  assert_instance_of(MIME::Type, @zip)
  assert_equal('appl/zip', @zip.simplified)
  assert_not_equal(@zip.object_id, @zip2.object_id)
end

#test_class_simplifiedObject



52
53
54
55
56
57
58
59
60
# File 'lib/mime-types-1.16/test/test_mime_type.rb', line 52

def test_class_simplified
  assert_equal(MIME::Type.simplified('text/plain'), 'text/plain')
  assert_equal(MIME::Type.simplified('image/jpeg'), 'image/jpeg')
  assert_equal(MIME::Type.simplified('application/x-msword'), 'application/msword')
  assert_equal(MIME::Type.simplified('text/vCard'), 'text/vcard')
  assert_equal(MIME::Type.simplified('application/pkcs7-mime'), 'application/pkcs7-mime')
  assert_equal(@zip.simplified, 'appl/zip')
  assert_equal(MIME::Type.simplified('x-xyz/abc'), 'xyz/abc')
end

#test_CMPObject

‘<=>’



62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/mime-types-1.16/test/test_mime_type.rb', line 62

def test_CMP # '<=>'
  assert(MIME::Type.new('text/plain') == MIME::Type.new('text/plain'))
  assert(MIME::Type.new('text/plain') != MIME::Type.new('image/jpeg'))
  assert(MIME::Type.new('text/plain') == 'text/plain')
  assert(MIME::Type.new('text/plain') != 'image/jpeg')
  assert(MIME::Type.new('text/plain') > MIME::Type.new('text/html'))
  assert(MIME::Type.new('text/plain') > 'text/html')
  assert(MIME::Type.new('text/html') < MIME::Type.new('text/plain'))
  assert(MIME::Type.new('text/html') < 'text/plain')
  assert('text/html' == MIME::Type.new('text/html'))
  assert('text/html' < MIME::Type.new('text/plain'))
  assert('text/plain' > MIME::Type.new('text/html'))
end

#test_complete_ehObject



94
95
96
97
98
99
100
101
102
# File 'lib/mime-types-1.16/test/test_mime_type.rb', line 94

def test_complete_eh
  assert_nothing_raised do
    @yaml = MIME::Type.from_array('text/x-yaml', %w(yaml yml), '8bit',
                                'linux')
  end
  assert(@yaml.complete?)
  assert_nothing_raised { @yaml.extensions = nil }
  assert(!@yaml.complete?)
end

#test_content_typeObject



104
105
106
107
108
109
110
111
# File 'lib/mime-types-1.16/test/test_mime_type.rb', line 104

def test_content_type
  assert_equal(MIME::Type.new('text/plain').content_type, 'text/plain')
  assert_equal(MIME::Type.new('image/jpeg').content_type, 'image/jpeg')
  assert_equal(MIME::Type.new('application/x-msword').content_type, 'application/x-msword')
  assert_equal(MIME::Type.new('text/vCard').content_type, 'text/vCard')
  assert_equal(MIME::Type.new('application/pkcs7-mime').content_type, 'application/pkcs7-mime')
  assert_equal(@zip.content_type, 'x-appl/x-zip');
end

#test_encodingObject



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/mime-types-1.16/test/test_mime_type.rb', line 113

def test_encoding
  assert_equal(MIME::Type.new('text/plain').encoding, 'quoted-printable')
  assert_equal(MIME::Type.new('image/jpeg').encoding, 'base64')
  assert_equal(MIME::Type.new('application/x-msword').encoding, 'base64')
  assert_equal(MIME::Type.new('text/vCard').encoding, 'quoted-printable')
  assert_equal(MIME::Type.new('application/pkcs7-mime').encoding, 'base64')
  assert_nothing_raised do
    @yaml = MIME::Type.from_array('text/x-yaml', %w(yaml yml), '8bit',
                                'linux')
  end
  assert_equal(@yaml.encoding, '8bit')
  assert_nothing_raised { @yaml.encoding = 'base64' }
  assert_equal(@yaml.encoding, 'base64')
  assert_nothing_raised { @yaml.encoding = :default }
  assert_equal(@yaml.encoding, 'quoted-printable')
  assert_raises(ArgumentError) { @yaml.encoding = 'binary' }
  assert_equal(@zip.encoding, 'base64')
end

#test_eql?Boolean

Returns:

  • (Boolean)


144
145
146
147
148
149
# File 'lib/mime-types-1.16/test/test_mime_type.rb', line 144

def test_eql?
  assert(MIME::Type.new('text/plain').eql?(MIME::Type.new('text/plain')))
  assert(!MIME::Type.new('text/plain').eql?(MIME::Type.new('image/jpeg')))
  assert(!MIME::Type.new('text/plain').eql?('text/plain'))
  assert(!MIME::Type.new('text/plain').eql?('image/jpeg'))
end

#test_extensionsObject



159
160
161
162
163
164
165
166
167
168
169
# File 'lib/mime-types-1.16/test/test_mime_type.rb', line 159

def test_extensions
  assert_nothing_raised do
    @yaml = MIME::Type.from_array('text/x-yaml', %w(yaml yml), '8bit',
                                'linux')
  end
  assert_equal(@yaml.extensions, %w(yaml yml))
  assert_nothing_raised { @yaml.extensions = 'yaml' }
  assert_equal(@yaml.extensions, ['yaml'])
  assert_equal(@zip.extensions.size, 2)
  assert_equal(@zip.extensions, ['zip', 'zp'])
end

#test_like_ehObject



175
176
177
178
179
180
181
182
# File 'lib/mime-types-1.16/test/test_mime_type.rb', line 175

def test_like_eh
  assert(MIME::Type.new('text/plain').like?(MIME::Type.new('text/plain')))
  assert(MIME::Type.new('text/plain').like?(MIME::Type.new('text/x-plain')))
  assert(!MIME::Type.new('text/plain').like?(MIME::Type.new('image/jpeg')))
  assert(MIME::Type.new('text/plain').like?('text/plain'))
  assert(MIME::Type.new('text/plain').like?('text/x-plain'))
  assert(!MIME::Type.new('text/plain').like?('image/jpeg'))
end

#test_media_typeObject



184
185
186
187
188
189
190
191
192
# File 'lib/mime-types-1.16/test/test_mime_type.rb', line 184

def test_media_type
  assert_equal(MIME::Type.new('text/plain').media_type, 'text')
  assert_equal(MIME::Type.new('image/jpeg').media_type, 'image')
  assert_equal(MIME::Type.new('application/x-msword').media_type, 'application')
  assert_equal(MIME::Type.new('text/vCard').media_type, 'text')
  assert_equal(MIME::Type.new('application/pkcs7-mime').media_type, 'application')
  assert_equal(MIME::Type.new('x-chemical/x-pdb').media_type, 'chemical')
  assert_equal(@zip.media_type, 'appl')
end

#test_platform_ehObject



202
203
204
205
206
207
208
209
210
211
212
# File 'lib/mime-types-1.16/test/test_mime_type.rb', line 202

def test_platform_eh
  assert_nothing_raised do
    @yaml = MIME::Type.from_array('text/x-yaml', %w(yaml yml), '8bit',
                                'oddbox')
  end
  assert(!@yaml.platform?)
  assert_nothing_raised { @yaml.system = nil }
  assert(!@yaml.platform?)
  assert_nothing_raised { @yaml.system = /#{RUBY_PLATFORM}/ }
    assert(@yaml.platform?)
end

#test_raw_media_typeObject



214
215
216
217
218
219
220
221
222
223
# File 'lib/mime-types-1.16/test/test_mime_type.rb', line 214

def test_raw_media_type
  assert_equal(MIME::Type.new('text/plain').raw_media_type, 'text')
  assert_equal(MIME::Type.new('image/jpeg').raw_media_type, 'image')
  assert_equal(MIME::Type.new('application/x-msword').raw_media_type, 'application')
  assert_equal(MIME::Type.new('text/vCard').raw_media_type, 'text')
  assert_equal(MIME::Type.new('application/pkcs7-mime').raw_media_type, 'application')

  assert_equal(MIME::Type.new('x-chemical/x-pdb').raw_media_type, 'x-chemical')
  assert_equal(@zip.raw_media_type, 'x-appl')
end

#test_raw_sub_typeObject



225
226
227
228
229
230
231
232
# File 'lib/mime-types-1.16/test/test_mime_type.rb', line 225

def test_raw_sub_type
  assert_equal(MIME::Type.new('text/plain').raw_sub_type, 'plain')
  assert_equal(MIME::Type.new('image/jpeg').raw_sub_type, 'jpeg')
  assert_equal(MIME::Type.new('application/x-msword').raw_sub_type, 'x-msword')
  assert_equal(MIME::Type.new('text/vCard').raw_sub_type, 'vCard')
  assert_equal(MIME::Type.new('application/pkcs7-mime').raw_sub_type, 'pkcs7-mime')
  assert_equal(@zip.raw_sub_type, 'x-zip')
end

#test_registered_ehObject



234
235
236
237
238
239
240
241
# File 'lib/mime-types-1.16/test/test_mime_type.rb', line 234

def test_registered_eh
  assert(MIME::Type.new('text/plain').registered?)
  assert(MIME::Type.new('image/jpeg').registered?)
  assert(!MIME::Type.new('application/x-msword').registered?)
  assert(MIME::Type.new('text/vCard').registered?)
  assert(MIME::Type.new('application/pkcs7-mime').registered?)
  assert(!@zip.registered?)
end

#test_signature_ehObject



247
248
249
250
251
252
253
# File 'lib/mime-types-1.16/test/test_mime_type.rb', line 247

def test_signature_eh
  assert(!MIME::Type.new('text/plain').signature?)
  assert(!MIME::Type.new('image/jpeg').signature?)
  assert(!MIME::Type.new('application/x-msword').signature?)
  assert(MIME::Type.new('text/vCard').signature?)
  assert(MIME::Type.new('application/pkcs7-mime').signature?)
end

#test_simplifiedObject



255
256
257
258
259
260
261
262
# File 'lib/mime-types-1.16/test/test_mime_type.rb', line 255

def test_simplified
  assert_equal(MIME::Type.new('text/plain').simplified, 'text/plain')
  assert_equal(MIME::Type.new('image/jpeg').simplified, 'image/jpeg')
  assert_equal(MIME::Type.new('application/x-msword').simplified, 'application/msword')
  assert_equal(MIME::Type.new('text/vCard').simplified, 'text/vcard')
  assert_equal(MIME::Type.new('application/pkcs7-mime').simplified, 'application/pkcs7-mime')
  assert_equal(MIME::Type.new('x-chemical/x-pdb').simplified, 'chemical/pdb')
end

#test_sub_typeObject



264
265
266
267
268
269
270
271
# File 'lib/mime-types-1.16/test/test_mime_type.rb', line 264

def test_sub_type
  assert_equal(MIME::Type.new('text/plain').sub_type, 'plain')
  assert_equal(MIME::Type.new('image/jpeg').sub_type, 'jpeg')
  assert_equal(MIME::Type.new('application/x-msword').sub_type, 'msword')
  assert_equal(MIME::Type.new('text/vCard').sub_type, 'vcard')
  assert_equal(MIME::Type.new('application/pkcs7-mime').sub_type, 'pkcs7-mime')
  assert_equal(@zip.sub_type, 'zip')
end

#test_system_ehObject



285
286
287
288
289
290
291
292
293
# File 'lib/mime-types-1.16/test/test_mime_type.rb', line 285

def test_system_eh
  assert_nothing_raised do
    @yaml = MIME::Type.from_array('text/x-yaml', %w(yaml yml), '8bit',
                                'linux')
  end
  assert(@yaml.system?)
  assert_nothing_raised { @yaml.system = nil }
  assert(!@yaml.system?)
end

#test_system_equalsObject



273
274
275
276
277
278
279
280
281
282
283
# File 'lib/mime-types-1.16/test/test_mime_type.rb', line 273

def test_system_equals
  assert_nothing_raised do
    @yaml = MIME::Type.from_array('text/x-yaml', %w(yaml yml), '8bit',
                                'linux')
  end
  assert_equal(@yaml.system, %r{linux})
  assert_nothing_raised { @yaml.system = /win32/ }
  assert_equal(@yaml.system, %r{win32})
  assert_nothing_raised { @yaml.system = nil }
  assert_nil(@yaml.system)
end

#test_to_aObject



295
296
297
298
299
300
301
302
# File 'lib/mime-types-1.16/test/test_mime_type.rb', line 295

def test_to_a
  assert_nothing_raised do
    @yaml = MIME::Type.from_array('text/x-yaml', %w(yaml yml), '8bit',
                                'linux')
  end
  assert_equal(@yaml.to_a, ['text/x-yaml', %w(yaml yml), '8bit',
               /linux/, nil, nil, nil, false])
end

#test_to_hashObject



304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
# File 'lib/mime-types-1.16/test/test_mime_type.rb', line 304

def test_to_hash
  assert_nothing_raised do
    @yaml = MIME::Type.from_array('text/x-yaml', %w(yaml yml), '8bit',
                                'linux')
  end
  assert_equal(@yaml.to_hash,
               { 'Content-Type' => 'text/x-yaml',
                'Content-Transfer-Encoding' => '8bit',
                'Extensions' => %w(yaml yml),
                'System' => /linux/,
                'Registered' => false,
                'URL' => nil,
                'Obsolete' => nil,
                'Docs' => nil })
end

#test_to_sObject



320
321
322
# File 'lib/mime-types-1.16/test/test_mime_type.rb', line 320

def test_to_s
  assert_equal("#{MIME::Type.new('text/plain')}", 'text/plain')
end