mime-types 2.5 → 2.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/Contributing.rdoc +72 -20
- data/History-Types.rdoc +11 -0
- data/History.rdoc +31 -1
- data/Manifest.txt +18 -1
- data/README.rdoc +142 -61
- data/Rakefile +59 -91
- data/data/mime-types.json +1 -1
- data/data/mime.content_type.column +1907 -0
- data/data/mime.docs.column +1907 -0
- data/data/mime.encoding.column +1907 -0
- data/data/mime.friendly.column +1907 -0
- data/data/mime.obsolete.column +1907 -0
- data/data/mime.references.column +1907 -0
- data/data/mime.registered.column +1907 -0
- data/data/mime.signature.column +1907 -0
- data/data/mime.system.column +1907 -0
- data/data/mime.use_instead.column +1907 -0
- data/data/mime.xrefs.column +1907 -0
- data/lib/mime/type.rb +192 -119
- data/lib/mime/type/columnar.rb +112 -0
- data/lib/mime/types.rb +39 -25
- data/lib/mime/types/cache.rb +41 -35
- data/lib/mime/types/columnar.rb +160 -0
- data/lib/mime/types/deprecations.rb +53 -0
- data/lib/mime/types/loader.rb +60 -20
- data/lib/mime/types/loader_path.rb +2 -3
- data/lib/mime/types/logger.rb +35 -0
- data/support/apache_mime_types.rb +8 -1
- data/support/benchmarks/load.rb +17 -8
- data/support/benchmarks/load_allocations.rb +83 -0
- data/support/benchmarks/object_counts.rb +41 -0
- data/support/convert.rb +44 -24
- data/support/convert/columnar.rb +90 -0
- data/support/iana_registry.rb +18 -8
- data/test/fixture/json.json +1 -1
- data/test/fixture/yaml.yaml +3 -6
- data/test/minitest_helper.rb +9 -10
- data/test/test_mime_type.rb +126 -62
- data/test/test_mime_types.rb +15 -11
- data/test/test_mime_types_class.rb +16 -14
- data/test/test_mime_types_lazy.rb +7 -1
- data/test/test_mime_types_loader.rb +17 -8
- metadata +54 -12
- data/lib/mime.rb +0 -51
data/support/convert.rb
CHANGED
@@ -1,8 +1,16 @@
|
|
1
1
|
# -*- ruby encoding: utf-8 -*-
|
2
2
|
|
3
3
|
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
4
|
+
ENV['RUBY_MIME_TYPES_LAZY_LOAD'] = 'true'
|
4
5
|
require 'mime/types'
|
5
6
|
require 'fileutils'
|
7
|
+
require 'json'
|
8
|
+
|
9
|
+
class MIME::Types
|
10
|
+
def self.deprecated(*_args, &_block)
|
11
|
+
# We are an internal tool. Silence deprecation warnings.
|
12
|
+
end
|
13
|
+
end
|
6
14
|
|
7
15
|
class Convert
|
8
16
|
class << self
|
@@ -24,34 +32,37 @@ class Convert
|
|
24
32
|
|
25
33
|
# Converts from YAML to JSON. Defaults to converting to a single file.
|
26
34
|
def from_yaml_to_json(args)
|
27
|
-
mf = args.multiple_files || "single"
|
28
35
|
from_yaml(yaml_path(args.source)).
|
29
|
-
to_json(
|
30
|
-
|
36
|
+
to_json(
|
37
|
+
destination: json_path(args.destination),
|
38
|
+
multiple_files: multiple_files(args.multiple_files || 'single')
|
39
|
+
)
|
31
40
|
end
|
32
41
|
|
33
42
|
# Converts from JSON to YAML. Defaults to converting to multiple files.
|
34
43
|
def from_json_to_yaml(args)
|
35
|
-
mf = args.multiple_files || "multiple"
|
36
44
|
from_json(json_path(args.source)).
|
37
|
-
to_yaml(
|
38
|
-
|
45
|
+
to_yaml(
|
46
|
+
destination: yaml_path(args.destination),
|
47
|
+
multiple_files: multiple_files(args.multiple_files || 'multiple')
|
48
|
+
)
|
39
49
|
end
|
40
50
|
|
41
51
|
private :new
|
42
52
|
|
43
53
|
private
|
54
|
+
|
44
55
|
def yaml_path(path)
|
45
|
-
|
46
|
-
'type-lists'
|
47
|
-
else
|
48
|
-
path
|
49
|
-
end
|
56
|
+
path_or_default(path, 'type-lists'.freeze)
|
50
57
|
end
|
51
58
|
|
52
59
|
def json_path(path)
|
60
|
+
path_or_default(path, 'data'.freeze)
|
61
|
+
end
|
62
|
+
|
63
|
+
def path_or_default(path, default)
|
53
64
|
if path.nil? or path.empty?
|
54
|
-
|
65
|
+
default
|
55
66
|
else
|
56
67
|
path
|
57
68
|
end
|
@@ -59,7 +70,7 @@ class Convert
|
|
59
70
|
|
60
71
|
def multiple_files(flag)
|
61
72
|
case flag.to_s.downcase
|
62
|
-
when
|
73
|
+
when 'true', 'yes', 'multiple'
|
63
74
|
true
|
64
75
|
else
|
65
76
|
false
|
@@ -69,10 +80,9 @@ class Convert
|
|
69
80
|
|
70
81
|
def initialize(options = {})
|
71
82
|
if options[:path].nil? or options[:path].empty?
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
raise ArgumentError, ':from is required'
|
83
|
+
fail ArgumentError, ':path is required'
|
84
|
+
elsif options[:from].nil? or options[:from].empty?
|
85
|
+
fail ArgumentError, ':from is required'
|
76
86
|
end
|
77
87
|
|
78
88
|
@loader = MIME::Types::Loader.new(options[:path])
|
@@ -81,17 +91,18 @@ class Convert
|
|
81
91
|
|
82
92
|
# Convert the data to JSON.
|
83
93
|
def to_json(options = {})
|
84
|
-
|
94
|
+
options[:destination] or require_destination!
|
85
95
|
write_types(options.merge(format: :json))
|
86
96
|
end
|
87
97
|
|
88
98
|
# Convert the data to YAML.
|
89
99
|
def to_yaml(options = {})
|
90
|
-
|
100
|
+
options[:destination] or require_destination!
|
91
101
|
write_types(options.merge(format: :yaml))
|
92
102
|
end
|
93
103
|
|
94
104
|
private
|
105
|
+
|
95
106
|
def load_from(source_type)
|
96
107
|
method = :"load_#{source_type}"
|
97
108
|
@loader.send(method)
|
@@ -116,11 +127,7 @@ class Convert
|
|
116
127
|
|
117
128
|
def write_multiple_files(options)
|
118
129
|
d = options[:destination]
|
119
|
-
|
120
|
-
raise ArgumentError, 'Cannot write multiple files to a file.'
|
121
|
-
end
|
122
|
-
|
123
|
-
FileUtils.mkdir_p d unless File.exist?(d)
|
130
|
+
must_be_directory!(d)
|
124
131
|
|
125
132
|
media_types = MIME::Types.map(&:media_type).uniq
|
126
133
|
media_types.each { |media_type|
|
@@ -135,4 +142,17 @@ class Convert
|
|
135
142
|
def convert(data, format)
|
136
143
|
data.send(:"to_#{format}")
|
137
144
|
end
|
145
|
+
|
146
|
+
def require_destination!
|
147
|
+
fail ArgumentError, 'Destination path is required.'
|
148
|
+
end
|
149
|
+
|
150
|
+
def must_be_directory!(path)
|
151
|
+
if File.exist?(path) and !File.directory?(path)
|
152
|
+
fail ArgumentError, 'Cannot write multiple files to a file.'
|
153
|
+
end
|
154
|
+
|
155
|
+
FileUtils.mkdir_p(path) unless File.exist?(path)
|
156
|
+
path
|
157
|
+
end
|
138
158
|
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
require 'convert'
|
2
|
+
|
3
|
+
class Convert::Columnar < Convert
|
4
|
+
class << self
|
5
|
+
# Converts from YAML to Columnar format. This *always* converts to multiple
|
6
|
+
# files.
|
7
|
+
def from_yaml_to_columnar(args)
|
8
|
+
from_yaml(yaml_path(args.source)).
|
9
|
+
to_columnar(destination: columnar_path(args.destination))
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def columnar_path(path)
|
15
|
+
path_or_default(path, 'data')
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
# Convert the data to multiple text files.
|
20
|
+
def to_columnar(options = {})
|
21
|
+
root = options[:destination] or require_destination!
|
22
|
+
@root = must_be_directory!(root)
|
23
|
+
@data = @loader.container.sort.map(&:to_h)
|
24
|
+
|
25
|
+
column_file('content_type') do |type|
|
26
|
+
[ type['content-type'], Array(type['extensions']).join(' ') ].
|
27
|
+
flatten.join(' ').strip
|
28
|
+
end
|
29
|
+
|
30
|
+
required_file('encoding')
|
31
|
+
optional_file('docs')
|
32
|
+
optional_file('system')
|
33
|
+
bool_file('obsolete')
|
34
|
+
bool_file('registered')
|
35
|
+
bool_file('signature')
|
36
|
+
array_file('references')
|
37
|
+
dict_file('xrefs')
|
38
|
+
dict_file('friendly')
|
39
|
+
optional_file('use_instead', 'use-instead')
|
40
|
+
end
|
41
|
+
|
42
|
+
def column_file(name, &block)
|
43
|
+
File.open(File.join(@root, "mime.#{name}.column"), 'wb') do |f|
|
44
|
+
f.puts @data.map(&block)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def bool_file(name, *fields)
|
49
|
+
fields = [ name ] if fields.empty?
|
50
|
+
column_file(name) do |type|
|
51
|
+
fields.map { |field|
|
52
|
+
type[field] ? 1 : 0
|
53
|
+
}.join(' ')
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def required_file(name, field = name)
|
58
|
+
column_file(name) { |type| type[field] }
|
59
|
+
end
|
60
|
+
|
61
|
+
def optional_file(name, field = name)
|
62
|
+
column_file(name) { |type| opt(type[field]) }
|
63
|
+
end
|
64
|
+
|
65
|
+
def array_file(name, field = name)
|
66
|
+
column_file(name) { |type| arr(type[field]) }
|
67
|
+
end
|
68
|
+
|
69
|
+
def dict_file(name, field = name)
|
70
|
+
column_file(name) { |type| dict(type[field]) }
|
71
|
+
end
|
72
|
+
|
73
|
+
def opt(value)
|
74
|
+
value || '-'
|
75
|
+
end
|
76
|
+
|
77
|
+
def arr(value)
|
78
|
+
Array(opt(value)).join('|')
|
79
|
+
end
|
80
|
+
|
81
|
+
def dict(value)
|
82
|
+
if value
|
83
|
+
value.sort.map { |k, v|
|
84
|
+
[ k, Array(v).compact.join('^') ].join('^')
|
85
|
+
}.join('|')
|
86
|
+
else
|
87
|
+
'-'
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
data/support/iana_registry.rb
CHANGED
@@ -11,6 +11,12 @@ require 'yaml'
|
|
11
11
|
ENV['RUBY_MIME_TYPES_LAZY_LOAD'] = 'yes'
|
12
12
|
require 'mime/types'
|
13
13
|
|
14
|
+
class MIME::Types
|
15
|
+
def self.deprecated(*_args, &_block)
|
16
|
+
# We are an internal tool. Silence deprecation warnings.
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
14
20
|
class IANARegistry
|
15
21
|
DEFAULTS = {
|
16
22
|
url: %q(https://www.iana.org/assignments/media-types/media-types.xml),
|
@@ -21,7 +27,7 @@ class IANARegistry
|
|
21
27
|
dest = Pathname(options[:to] || DEFAULTS[:to]).expand_path
|
22
28
|
url = options.fetch(:url, DEFAULTS[:url])
|
23
29
|
|
24
|
-
puts
|
30
|
+
puts 'Downloading IANA MIME type assignments.'
|
25
31
|
puts "\t#{url}"
|
26
32
|
xml = Nokogiri::XML(open(url) { |f| f.read })
|
27
33
|
|
@@ -48,7 +54,7 @@ class IANARegistry
|
|
48
54
|
yield self if block_given?
|
49
55
|
end
|
50
56
|
|
51
|
-
ASSIGNMENT_FILE_REF =
|
57
|
+
ASSIGNMENT_FILE_REF = '{%s=http://www.iana.org/assignments/media-types/%s}'
|
52
58
|
|
53
59
|
def parse
|
54
60
|
@registry.css('record').each do |record|
|
@@ -63,9 +69,11 @@ class IANARegistry
|
|
63
69
|
|
64
70
|
subtype, notes = subtype.split(/ /, 2)
|
65
71
|
|
66
|
-
refs, xrefs
|
67
|
-
|
68
|
-
|
72
|
+
refs, xrefs = parse_refs_and_files(
|
73
|
+
record.css('xref'),
|
74
|
+
record.css('file'),
|
75
|
+
subtype
|
76
|
+
)
|
69
77
|
|
70
78
|
xrefs['notes'] << notes if notes
|
71
79
|
|
@@ -102,6 +110,7 @@ class IANARegistry
|
|
102
110
|
end
|
103
111
|
|
104
112
|
private
|
113
|
+
|
105
114
|
def mime_types_for(file)
|
106
115
|
if file.exist?
|
107
116
|
MIME::Types::Loader.load_from_yaml(file)
|
@@ -115,7 +124,8 @@ class IANARegistry
|
|
115
124
|
r = []
|
116
125
|
|
117
126
|
refs.each do |xref|
|
118
|
-
type
|
127
|
+
type = xref['type']
|
128
|
+
data = xref['data']
|
119
129
|
|
120
130
|
r << ref_from_type(type, data)
|
121
131
|
|
@@ -129,11 +139,11 @@ class IANARegistry
|
|
129
139
|
file.text
|
130
140
|
end
|
131
141
|
|
132
|
-
if file[
|
142
|
+
if file['type'] == 'template'
|
133
143
|
r << (ASSIGNMENT_FILE_REF % [ file_name, file_name ])
|
134
144
|
end
|
135
145
|
|
136
|
-
xr[file[
|
146
|
+
xr[file['type']] << file_name
|
137
147
|
end
|
138
148
|
|
139
149
|
[ r, xr ]
|
data/test/fixture/json.json
CHANGED
@@ -1 +1 @@
|
|
1
|
-
[{"content-type":"application/smil","encoding":"8bit","extensions":["smi","smil"],"obsolete":true,"use-instead":
|
1
|
+
[{"content-type":"application/smil","encoding":"8bit","extensions":["smi","smil"],"obsolete":true,"use-instead":"application/smil+xml","references":["IANA","RFC4536"],"registered":true},{"content-type":"audio/vnd.qcelp","encoding":"base64","extensions":["qcp"],"obsolete":true,"use-instead":"audio/QCELP","references":["IANA","RFC3625"],"registered":true},{"content-type":"image/bmp","encoding":"base64","extensions":["bmp"],"obsolete":true,"use-instead":"image/x-bmp","registered":false},{"content-type":"application/acad","encoding":"base64","references":["LTSW"],"registered":false},{"content-type":"audio/webm","encoding":"base64","extensions":["webm"],"references":["{WebM=http://www.webmproject.org/code/specs/container/}"],"registered":false},{"content-type":"image/pjpeg","docs":"Fixes a bug with IE6 and progressive JPEGs","encoding":"base64","registered":false},{"content-type":"application/1d-interleaved-parityfec","encoding":"base64","references":["IANA","RFC6015"],"registered":true},{"content-type":"audio/1d-interleaved-parityfec","encoding":"base64","references":["IANA","RFC6015"],"registered":true},{"content-type":"application/x-apple-diskimage","encoding":"base64","extensions":["dmg"],"registered":false,"system":"mac"}]
|
data/test/fixture/yaml.yaml
CHANGED
@@ -6,8 +6,7 @@
|
|
6
6
|
- smi
|
7
7
|
- smil
|
8
8
|
obsolete: true
|
9
|
-
use-instead:
|
10
|
-
- application/smil+xml
|
9
|
+
use-instead: application/smil+xml
|
11
10
|
references:
|
12
11
|
- IANA
|
13
12
|
- RFC4536
|
@@ -18,8 +17,7 @@
|
|
18
17
|
extensions:
|
19
18
|
- qcp
|
20
19
|
obsolete: true
|
21
|
-
use-instead:
|
22
|
-
- audio/QCELP
|
20
|
+
use-instead: audio/QCELP
|
23
21
|
references:
|
24
22
|
- IANA
|
25
23
|
- RFC3625
|
@@ -30,8 +28,7 @@
|
|
30
28
|
extensions:
|
31
29
|
- bmp
|
32
30
|
obsolete: true
|
33
|
-
use-instead:
|
34
|
-
- image/x-bmp
|
31
|
+
use-instead: image/x-bmp
|
35
32
|
registered: false
|
36
33
|
- !ruby/object:MIME::Type
|
37
34
|
content-type: application/acad
|
data/test/minitest_helper.rb
CHANGED
@@ -5,18 +5,17 @@ require 'fileutils'
|
|
5
5
|
|
6
6
|
gem 'minitest'
|
7
7
|
require 'minitest/autorun'
|
8
|
+
require 'minitest/focus'
|
8
9
|
|
9
|
-
module
|
10
|
-
|
10
|
+
module Minitest::MIMEDeprecated
|
11
|
+
def assert_deprecated name, message = 'and will be removed'
|
12
|
+
name = Regexp.escape(name)
|
13
|
+
message = Regexp.escape(message)
|
11
14
|
|
12
|
-
|
13
|
-
|
15
|
+
assert_output nil, /#{name} is deprecated #{message}./ do
|
16
|
+
yield
|
17
|
+
end
|
14
18
|
end
|
15
|
-
end
|
16
19
|
|
17
|
-
|
18
|
-
MIME.__deprecated[name] = false
|
19
|
-
assert_output(nil, /#{Regexp.escape(name)} is deprecated #{Regexp.escape(message)}./) { yield }
|
20
|
-
ensure
|
21
|
-
MIME.__deprecated[name] = true
|
20
|
+
Minitest::Test.send(:include, self)
|
22
21
|
end
|
data/test/test_mime_type.rb
CHANGED
@@ -17,7 +17,9 @@ class TestMIMEType < Minitest::Test
|
|
17
17
|
}
|
18
18
|
js.encoding = '8bit'
|
19
19
|
js.extensions = %w(js sj)
|
20
|
-
|
20
|
+
assert_deprecated('MIME::Type#references=') do
|
21
|
+
js.references = %w(IANA RFC4329 {application/javascript=http://www.iana.org/assignments/media-types/application/javascript})
|
22
|
+
end
|
21
23
|
js.registered = true
|
22
24
|
|
23
25
|
yield js if block_given?
|
@@ -44,24 +46,30 @@ class TestMIMEType < Minitest::Test
|
|
44
46
|
|
45
47
|
def setup
|
46
48
|
@applzip = MIME::Type.new('x-appl/x-zip') { |t|
|
47
|
-
t.extensions =
|
49
|
+
t.extensions = %w(zip zp)
|
48
50
|
}
|
49
51
|
end
|
50
52
|
|
51
53
|
def test_class_from_array
|
52
54
|
yaml = nil
|
53
|
-
assert_deprecated(
|
54
|
-
yaml = MIME::Type.from_array(
|
55
|
-
|
55
|
+
assert_deprecated('MIME::Type.from_array') do
|
56
|
+
yaml = MIME::Type.from_array(
|
57
|
+
'text/x-yaml',
|
58
|
+
%w(yaml yml),
|
59
|
+
'8bit',
|
60
|
+
'd9d172f608'
|
61
|
+
)
|
56
62
|
end
|
57
63
|
assert_instance_of(MIME::Type, yaml)
|
58
64
|
assert_equal('text/yaml', yaml.simplified)
|
59
|
-
|
65
|
+
assert_deprecated('MIME::Type.from_array') do
|
66
|
+
assert_raises(ArgumentError) { MIME::Type.from_array }
|
67
|
+
end
|
60
68
|
end
|
61
69
|
|
62
70
|
def test_class_from_hash
|
63
71
|
yaml = nil
|
64
|
-
assert_deprecated(
|
72
|
+
assert_deprecated('MIME::Type.from_hash') do
|
65
73
|
yaml = MIME::Type.from_hash('Content-Type' => 'text/x-yaml',
|
66
74
|
'Content-Transfer-Encoding' => '8bit',
|
67
75
|
'System' => 'd9d172f608',
|
@@ -73,7 +81,7 @@ class TestMIMEType < Minitest::Test
|
|
73
81
|
|
74
82
|
def test_class_from_mime_type
|
75
83
|
zip2 = nil
|
76
|
-
assert_deprecated(
|
84
|
+
assert_deprecated('MIME::Type.from_mime_type') do
|
77
85
|
zip2 = MIME::Type.from_mime_type(@applzip)
|
78
86
|
end
|
79
87
|
assert_instance_of(MIME::Type, @applzip)
|
@@ -102,7 +110,7 @@ class TestMIMEType < Minitest::Test
|
|
102
110
|
end
|
103
111
|
|
104
112
|
def test_spaceship_compare # '<=>'
|
105
|
-
assert(MIME::Type.new('text/plain') == MIME::Type.new('text/plain'))
|
113
|
+
assert(MIME::Type.new('text/plain') == MIME::Type.new('text/plain')) # rubocop:disable Lint/UselessComparison
|
106
114
|
assert(MIME::Type.new('text/plain') != MIME::Type.new('image/jpeg'))
|
107
115
|
assert(MIME::Type.new('text/plain') == 'text/plain')
|
108
116
|
assert(MIME::Type.new('text/plain') != 'image/jpeg')
|
@@ -148,7 +156,7 @@ class TestMIMEType < Minitest::Test
|
|
148
156
|
assert_equal('text/vCard', MIME::Type.new('text/vCard').content_type)
|
149
157
|
assert_equal('application/pkcs7-mime',
|
150
158
|
MIME::Type.new('application/pkcs7-mime').content_type)
|
151
|
-
assert_equal('x-appl/x-zip', @applzip.content_type)
|
159
|
+
assert_equal('x-appl/x-zip', @applzip.content_type)
|
152
160
|
assert_equal('base64', @applzip.encoding)
|
153
161
|
end
|
154
162
|
|
@@ -188,7 +196,7 @@ class TestMIMEType < Minitest::Test
|
|
188
196
|
|
189
197
|
def test_docs_equals
|
190
198
|
yaml = make_yaml_mime_type
|
191
|
-
|
199
|
+
assert_equal [], yaml.docs
|
192
200
|
yaml.docs = 'YAML docs'
|
193
201
|
assert_equal('YAML docs', yaml.docs)
|
194
202
|
end
|
@@ -267,14 +275,18 @@ class TestMIMEType < Minitest::Test
|
|
267
275
|
|
268
276
|
def test_platform_eh
|
269
277
|
yaml = nil
|
270
|
-
assert_deprecated(
|
278
|
+
assert_deprecated('MIME::Type#platform?') do
|
271
279
|
yaml = make_yaml_mime_type
|
272
280
|
refute(yaml.platform?)
|
273
281
|
end
|
274
282
|
yaml.system = nil
|
275
|
-
|
283
|
+
assert_deprecated('MIME::Type#platform?') do
|
284
|
+
refute(yaml.platform?)
|
285
|
+
end
|
276
286
|
yaml.system = %r{#{RUBY_PLATFORM}}
|
277
|
-
|
287
|
+
assert_deprecated('MIME::Type#platform?') do
|
288
|
+
assert(yaml.platform?)
|
289
|
+
end
|
278
290
|
end
|
279
291
|
|
280
292
|
def assert_priority(l, e, r)
|
@@ -381,7 +393,7 @@ class TestMIMEType < Minitest::Test
|
|
381
393
|
end
|
382
394
|
|
383
395
|
def test_system
|
384
|
-
assert_deprecated(
|
396
|
+
assert_deprecated('MIME::Type#system') do
|
385
397
|
yaml = make_yaml_mime_type
|
386
398
|
assert_equal(%r{d9d172f608}, yaml.system)
|
387
399
|
end
|
@@ -390,31 +402,37 @@ class TestMIMEType < Minitest::Test
|
|
390
402
|
def test_system_equals
|
391
403
|
yaml = make_yaml_mime_type
|
392
404
|
yaml.system = /win32/
|
393
|
-
|
405
|
+
assert_deprecated('MIME::Type#system') do
|
406
|
+
assert_equal(%r{win32}, yaml.system)
|
407
|
+
end
|
394
408
|
yaml.system = nil
|
395
|
-
|
409
|
+
assert_deprecated('MIME::Type#system') do
|
410
|
+
assert_nil(yaml.system)
|
411
|
+
end
|
396
412
|
end
|
397
413
|
|
398
414
|
def test_system_eh
|
399
415
|
yaml = make_yaml_mime_type
|
400
|
-
assert_deprecated(
|
416
|
+
assert_deprecated('MIME::Type#system?') do
|
401
417
|
assert(yaml.system?)
|
402
418
|
end
|
403
419
|
yaml.system = nil
|
404
|
-
|
420
|
+
assert_deprecated('MIME::Type#system?') do
|
421
|
+
refute(yaml.system?)
|
422
|
+
end
|
405
423
|
end
|
406
424
|
|
407
425
|
def test_to_a
|
408
426
|
yaml = make_yaml_mime_type
|
409
|
-
assert_deprecated(
|
427
|
+
assert_deprecated('MIME::Type#to_a') do
|
410
428
|
assert_equal(['text/x-yaml', %w(yaml yml), '8bit', /d9d172f608/,
|
411
|
-
false,
|
429
|
+
false, [], [], false], yaml.to_a)
|
412
430
|
end
|
413
431
|
end
|
414
432
|
|
415
433
|
def test_to_hash
|
416
434
|
yaml = make_yaml_mime_type
|
417
|
-
assert_deprecated(
|
435
|
+
assert_deprecated('MIME::Type#to_hash') do
|
418
436
|
assert_equal(
|
419
437
|
{
|
420
438
|
'Content-Type' => 'text/x-yaml',
|
@@ -424,7 +442,7 @@ class TestMIMEType < Minitest::Test
|
|
424
442
|
'Registered' => false,
|
425
443
|
'URL' => [],
|
426
444
|
'Obsolete' => false,
|
427
|
-
'Docs' =>
|
445
|
+
'Docs' => []
|
428
446
|
},
|
429
447
|
yaml.to_hash)
|
430
448
|
end
|
@@ -432,7 +450,7 @@ class TestMIMEType < Minitest::Test
|
|
432
450
|
|
433
451
|
def assert_type_has_keys(type, *keys)
|
434
452
|
hash = type.to_h
|
435
|
-
keys.flatten.each { |key| assert(hash.
|
453
|
+
keys.flatten.each { |key| assert(hash.key?(key)) }
|
436
454
|
end
|
437
455
|
|
438
456
|
def test_to_h
|
@@ -441,9 +459,13 @@ class TestMIMEType < Minitest::Test
|
|
441
459
|
assert_type_has_keys(make(t) { |v| v.docs = 'Something' }, 'docs')
|
442
460
|
assert_type_has_keys(make(t) { |v| v.extensions = %w(b) }, 'extensions')
|
443
461
|
assert_type_has_keys(make(t) { |v| v.obsolete = true }, 'obsolete')
|
444
|
-
assert_type_has_keys(make(t) { |v|
|
445
|
-
|
446
|
-
|
462
|
+
assert_type_has_keys(make(t) { |v|
|
463
|
+
v.obsolete = true
|
464
|
+
v.use_instead = 'c/d'
|
465
|
+
}, 'obsolete', 'use-instead')
|
466
|
+
assert_type_has_keys(make(t) { |v|
|
467
|
+
assert_deprecated('MIME::Type#references=') { v.references = 'IANA' }
|
468
|
+
}, 'references')
|
447
469
|
assert_type_has_keys(make(t) { |v| v.signature = true }, 'signature')
|
448
470
|
assert_type_has_keys(make(t) { |v| v.system = /xyz/ }, 'system')
|
449
471
|
end
|
@@ -468,7 +490,7 @@ class TestMIMEType < Minitest::Test
|
|
468
490
|
begin
|
469
491
|
MIME::Type.new(nil)
|
470
492
|
rescue MIME::Type::InvalidContentType => ex
|
471
|
-
assert_equal(
|
493
|
+
assert_equal('Invalid Content-Type nil', ex.message)
|
472
494
|
end
|
473
495
|
end
|
474
496
|
|
@@ -477,16 +499,26 @@ class TestMIMEType < Minitest::Test
|
|
477
499
|
end
|
478
500
|
|
479
501
|
def test_references
|
480
|
-
|
502
|
+
assert_deprecated('MIME::Type#references') do
|
503
|
+
assert_empty(make_yaml_mime_type.references)
|
504
|
+
end
|
481
505
|
end
|
482
506
|
|
483
507
|
def test_references_equals
|
484
508
|
yaml = make_yaml_mime_type
|
485
|
-
|
486
|
-
|
509
|
+
assert_deprecated('MIME::Type#references=') do
|
510
|
+
yaml.references = 'IANA'
|
511
|
+
end
|
512
|
+
assert_deprecated('MIME::Type#references') do
|
513
|
+
assert_equal(%w(IANA), yaml.references)
|
514
|
+
end
|
487
515
|
|
488
|
-
|
489
|
-
|
516
|
+
assert_deprecated('MIME::Type#references=') do
|
517
|
+
yaml.references = %w(IANA IANA)
|
518
|
+
end
|
519
|
+
assert_deprecated('MIME::Type#references') do
|
520
|
+
assert_equal(%w(IANA), yaml.references)
|
521
|
+
end
|
490
522
|
end
|
491
523
|
|
492
524
|
def test_xrefs
|
@@ -501,58 +533,90 @@ class TestMIMEType < Minitest::Test
|
|
501
533
|
|
502
534
|
def test_xref_urls
|
503
535
|
js = make_javascript do |j|
|
504
|
-
j.xrefs = j.xrefs.merge(
|
536
|
+
j.xrefs = j.xrefs.merge(
|
505
537
|
'draft' => [ 'RFC-ietf-appsawg-json-merge-patch-07' ],
|
506
538
|
'person' => [ 'David_Singer' ],
|
507
539
|
'rfc-errata' => [ '3245' ],
|
508
540
|
'uri' => [ 'http://exmple.org' ],
|
509
541
|
'text' => [ 'text' ]
|
510
|
-
|
542
|
+
)
|
511
543
|
end
|
512
544
|
assert_equal(
|
513
545
|
[
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
546
|
+
'http://www.iana.org/go/rfc4239',
|
547
|
+
'http://www.iana.org/assignments/media-types/application/javascript',
|
548
|
+
'http://www.iana.org/go/draft-ietf-appsawg-json-merge-patch-07',
|
549
|
+
'http://www.iana.org/assignments/media-types/media-types.xhtml#David_Singer',
|
550
|
+
'http://www.rfc-editor.org/errata_search.php?eid=3245',
|
551
|
+
'http://exmple.org',
|
552
|
+
'text'
|
521
553
|
],
|
522
554
|
js.xref_urls
|
523
555
|
)
|
524
556
|
end
|
525
557
|
|
526
558
|
def test_url
|
527
|
-
assert_deprecated(
|
559
|
+
assert_deprecated('MIME::Type#url') do
|
528
560
|
assert_empty(make_yaml_mime_type.url)
|
529
561
|
end
|
530
562
|
end
|
531
563
|
|
532
564
|
def test_url_equals
|
533
565
|
yaml = make_yaml_mime_type
|
534
|
-
assert_deprecated(
|
535
|
-
yaml.url =
|
566
|
+
assert_deprecated('MIME::Type#url=') do
|
567
|
+
yaml.url = 'IANA'
|
568
|
+
end
|
569
|
+
assert_deprecated('MIME::Type#url') do
|
570
|
+
assert_equal(%w(IANA), yaml.url)
|
536
571
|
end
|
537
|
-
assert_equal(%W(IANA), yaml.url)
|
538
572
|
end
|
539
573
|
|
540
574
|
def test_urls
|
541
575
|
yaml = make_yaml_mime_type
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
576
|
+
assert_deprecated('MIME::Type#urls') do
|
577
|
+
assert_empty(yaml.urls)
|
578
|
+
end
|
579
|
+
|
580
|
+
assert_deprecated('MIME::Type#references=') do
|
581
|
+
yaml.references = %w(IANA RFC123 DRAFT:xyz [abc])
|
582
|
+
end
|
583
|
+
|
584
|
+
assert_deprecated('MIME::Type#urls') do
|
585
|
+
assert_equal(
|
586
|
+
%w(
|
587
|
+
http://www.iana.org/assignments/media-types/text/yaml
|
588
|
+
http://rfc-editor.org/rfc/rfc123.txt
|
589
|
+
http://datatracker.ietf.org/public/idindex.cgi?command=id_details&filename=xyz
|
590
|
+
http://www.iana.org/assignments/contact-people.htm#abc
|
591
|
+
),
|
592
|
+
yaml.urls
|
593
|
+
)
|
594
|
+
end
|
595
|
+
|
596
|
+
assert_deprecated('MIME::Type#references=') do
|
597
|
+
yaml.references = '[def=lax]'
|
598
|
+
end
|
599
|
+
|
600
|
+
assert_deprecated('MIME::Type#urls') do
|
601
|
+
assert_equal([%w(def http://www.iana.org/assignments/contact-people.htm#lax)],
|
602
|
+
yaml.urls)
|
603
|
+
end
|
604
|
+
|
605
|
+
assert_deprecated('MIME::Type#references=') do
|
606
|
+
yaml.references = '{mno=pqr}'
|
607
|
+
end
|
608
|
+
|
609
|
+
assert_deprecated('MIME::Type#urls') do
|
610
|
+
assert_equal([%w(mno pqr)], yaml.urls)
|
611
|
+
end
|
612
|
+
|
613
|
+
assert_deprecated('MIME::Type#references=') do
|
614
|
+
yaml.references = 'hoge'
|
615
|
+
end
|
616
|
+
|
617
|
+
assert_deprecated('MIME::Type#urls') do
|
618
|
+
assert_equal(%w(hoge), yaml.urls)
|
619
|
+
end
|
556
620
|
end
|
557
621
|
|
558
622
|
def test_use_instead
|
@@ -581,7 +645,7 @@ class TestMIMEType < Minitest::Test
|
|
581
645
|
end
|
582
646
|
|
583
647
|
def test_friendly_set
|
584
|
-
assert_equal({ 'en' => 'Zip' }, @applzip.friendly(
|
648
|
+
assert_equal({ 'en' => 'Zip' }, @applzip.friendly(%w(en Zip)))
|
585
649
|
assert_equal({ 'en' => 'Zip Archive' }, @applzip.friendly('en' => 'Zip Archive'))
|
586
650
|
end
|
587
651
|
|
@@ -596,7 +660,7 @@ class TestMIMEType < Minitest::Test
|
|
596
660
|
assert_output(nil, /MIME::InvalidContentType/) do
|
597
661
|
assert_same(MIME::InvalidContentType, MIME::Type::InvalidContentType)
|
598
662
|
end
|
599
|
-
|
663
|
+
assert_output(nil, /MIME::InvalidContentType/) do
|
600
664
|
assert_same(MIME::InvalidContentType, MIME::Type::InvalidContentType)
|
601
665
|
end
|
602
666
|
assert_raises(NameError) { MIME::Foo }
|