Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 23 additions & 7 deletions lib/net/imap/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -408,9 +408,9 @@ def defaults_hash

@global = default.new

version_defaults[0.4] = Config[default.send(:defaults_hash)]
version_defaults[:default] = Config[default.send(:defaults_hash)]

version_defaults[0] = Config[0.4].dup.update(
version_defaults[0] = Config[:default].dup.update(
sasl_ir: false,
parser_use_deprecated_uidplus_data: true,
parser_max_deprecated_uidplus_data_size: 10_000,
Expand All @@ -420,24 +420,40 @@ def defaults_hash
version_defaults[0.2] = Config[0]
version_defaults[0.3] = Config[0]

version_defaults[0.4] = Config[0.3].dup.update(
sasl_ir: true,
parser_max_deprecated_uidplus_data_size: 1000,
).freeze

version_defaults[0.5] = Config[0.4].dup.update(
responses_without_block: :warn,
parser_use_deprecated_uidplus_data: :up_to_max_size,
parser_max_deprecated_uidplus_data_size: 100,
).freeze

version_defaults[:default] = Config[0.4]
version_defaults[:current] = Config[0.4]
version_defaults[:next] = Config[0.5]

version_defaults[0.6] = Config[0.5].dup.update(
responses_without_block: :frozen_dup,
parser_use_deprecated_uidplus_data: false,
parser_max_deprecated_uidplus_data_size: 0,
).freeze
version_defaults[:future] = Config[0.6]

version_defaults[0.7] = Config[0.6].dup.update(
).freeze

current = VERSION.to_f
version_defaults[:original] = Config[0]
version_defaults[:current] = Config[current]
version_defaults[:next] = Config[current + 0.1]
version_defaults[:future] = Config[0.7]

version_defaults.freeze

if ($VERBOSE || $DEBUG) && self[:current].to_h != self[:default].to_h
warn "Misconfigured Net::IMAP::Config[:current] => %p,\n" \
" not equal to Net::IMAP::Config[:default] => %p" % [
self[:current].to_h, self[:default].to_h
]
end
end
end
end
36 changes: 28 additions & 8 deletions test/net/imap/test_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

class ConfigTest < Test::Unit::TestCase
Config = Net::IMAP::Config
THIS_VERSION = Net::IMAP::VERSION.to_f
NEXT_VERSION = THIS_VERSION + 0.1
FUTURE_VERSION = 0.7

setup do
Config.global.reset
Expand Down Expand Up @@ -141,19 +144,36 @@ class ConfigTest < Test::Unit::TestCase
assert_kind_of Config, config
assert config.frozen?, "#{name} isn't frozen"
assert config.inherited?(:debug), "#{name} doesn't inherit debug"
keys = config.to_h.keys - [:debug]
keys.each do |key|
refute config.inherited?(key)
end
assert_same Config.global, config.parent
end
end

test "Config[:default] and Config[:current] both hold default config" do
defaults = Config.default.to_h
assert_equal(defaults, Config[:default].to_h)
assert_equal(defaults, Config[:current].to_h)
end

test ".[] for all version_defaults" do
Config.version_defaults.each do |version, config|
assert_same Config[version], config
end
end

test ".[] for all x.y versions" do
original = Config[0]
assert_kind_of Config, original
assert_same original, Config[0.0]
assert_same original, Config[0.1]
assert_same original, Config[0.2]
assert_same original, Config[0.3]
assert_kind_of Config, Config[0.4]
assert_kind_of Config, Config[0.5]
((0.4r..FUTURE_VERSION.to_r) % 0.1r).each do |version|
assert_kind_of Config, Config[version.to_f]
end
end

test ".[] range errors" do
Expand All @@ -169,10 +189,10 @@ class ConfigTest < Test::Unit::TestCase
end

test ".[] with symbol names" do
assert_same Config[0.4], Config[:current]
assert_same Config[0.4], Config[:default]
assert_same Config[0.5], Config[:next]
assert_kind_of Config, Config[:future]
assert_equal Config[THIS_VERSION].to_h, Config[:default].to_h
assert_same Config[THIS_VERSION], Config[:current]
assert_same Config[NEXT_VERSION], Config[:next]
assert_same Config[FUTURE_VERSION], Config[:future]
end

test ".[] with a hash" do
Expand All @@ -190,8 +210,8 @@ class ConfigTest < Test::Unit::TestCase
assert_same Config.default, Config.new(Config.default).parent
assert_same Config.global, Config.new(Config.global).parent
assert_same Config[0.4], Config.new(0.4).parent
assert_same Config[0.5], Config.new(:next).parent
assert_same Config[0.6], Config.new(:future).parent
assert_same Config[NEXT_VERSION], Config.new(:next).parent
assert_same Config[FUTURE_VERSION], Config.new(:future).parent
assert_equal true, Config.new({debug: true}, debug: false).parent.debug?
assert_equal true, Config.new({debug: true}, debug: false).parent.frozen?
end
Expand Down
Loading