From 7ab47751068c6480e7e44fc9265a7e690dd4af3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Tue, 20 Dec 2011 18:22:21 +0100 Subject: Initial pass at removing dead 1.8.x code from Active Support. There are a bunch of other implicit branches that adds 1.8.x specific code that still needs to be removed. Pull requests for those cases are welcome. --- activesupport/test/abstract_unit.rb | 34 ++------------ activesupport/test/core_ext/date_ext_test.rb | 10 ---- activesupport/test/core_ext/hash_ext_test.rb | 6 +-- activesupport/test/core_ext/range_ext_test.rb | 13 ++---- activesupport/test/core_ext/string_ext_test.rb | 50 +++----------------- activesupport/test/core_ext/time_with_zone_test.rb | 3 +- activesupport/test/json/encoding_test.rb | 30 ++++++------ activesupport/test/multibyte_chars_test.rb | 11 +---- activesupport/test/multibyte_utils_test.rb | 54 ++++------------------ activesupport/test/ordered_hash_test.rb | 13 ++---- 10 files changed, 45 insertions(+), 179 deletions(-) (limited to 'activesupport/test') diff --git a/activesupport/test/abstract_unit.rb b/activesupport/test/abstract_unit.rb index 0382739871..504ac3e9b9 100644 --- a/activesupport/test/abstract_unit.rb +++ b/activesupport/test/abstract_unit.rb @@ -11,15 +11,11 @@ lib = File.expand_path("#{File.dirname(__FILE__)}/../lib") $:.unshift(lib) unless $:.include?('lib') || $:.include?(lib) require 'active_support/core_ext/kernel/reporting' - require 'active_support/core_ext/string/encoding' -if "ruby".encoding_aware? - # These are the normal settings that will be set up by Railties - # TODO: Have these tests support other combinations of these values - silence_warnings do - Encoding.default_internal = "UTF-8" - Encoding.default_external = "UTF-8" - end + +silence_warnings do + Encoding.default_internal = "UTF-8" + Encoding.default_external = "UTF-8" end require 'test/unit' @@ -30,9 +26,6 @@ silence_warnings { require 'mocha' } ENV['NO_RELOAD'] = '1' require 'active_support' -# Include shims until we get off 1.8.6 -require 'active_support/ruby/shim' if RUBY_VERSION < '1.8.7' - def uses_memcached(test_name) require 'memcache' begin @@ -43,22 +36,5 @@ def uses_memcached(test_name) end end -def with_kcode(code) - if RUBY_VERSION < '1.9' - begin - old_kcode, $KCODE = $KCODE, code - yield - ensure - $KCODE = old_kcode - end - else - yield - end -end - # Show backtraces for deprecated behavior for quicker cleanup. -ActiveSupport::Deprecation.debug = true - -if RUBY_VERSION < '1.9' - $KCODE = 'UTF8' -end +ActiveSupport::Deprecation.debug = true \ No newline at end of file diff --git a/activesupport/test/core_ext/date_ext_test.rb b/activesupport/test/core_ext/date_ext_test.rb index c040d86327..09d4765390 100644 --- a/activesupport/test/core_ext/date_ext_test.rb +++ b/activesupport/test/core_ext/date_ext_test.rb @@ -384,16 +384,6 @@ class DateExtCalculationsTest < ActiveSupport::TestCase end end - if RUBY_VERSION < '1.9' - def test_rfc3339 - assert_equal('1980-02-28', Date.new(1980, 2, 28).rfc3339) - end - - def test_iso8601 - assert_equal('1980-02-28', Date.new(1980, 2, 28).iso8601) - end - end - def test_today Date.stubs(:current).returns(Date.new(2000, 1, 1)) assert_equal false, Date.new(1999, 12, 31).today? diff --git a/activesupport/test/core_ext/hash_ext_test.rb b/activesupport/test/core_ext/hash_ext_test.rb index eb8ed761da..dfa0cdb478 100644 --- a/activesupport/test/core_ext/hash_ext_test.rb +++ b/activesupport/test/core_ext/hash_ext_test.rb @@ -27,11 +27,7 @@ class HashExtTest < Test::Unit::TestCase @symbols = { :a => 1, :b => 2 } @mixed = { :a => 1, 'b' => 2 } @fixnums = { 0 => 1, 1 => 2 } - if RUBY_VERSION < '1.9.0' - @illegal_symbols = { "\0" => 1, "" => 2, [] => 3 } - else - @illegal_symbols = { [] => 3 } - end + @illegal_symbols = { [] => 3 } end def test_methods diff --git a/activesupport/test/core_ext/range_ext_test.rb b/activesupport/test/core_ext/range_ext_test.rb index 1424fa4aca..f4b773e5fb 100644 --- a/activesupport/test/core_ext/range_ext_test.rb +++ b/activesupport/test/core_ext/range_ext_test.rb @@ -63,15 +63,8 @@ class RangeTest < Test::Unit::TestCase assert_equal [1,3,5,7,9], array end - if RUBY_VERSION < '1.9' - def test_cover - assert((1..3).cover?(2)) - assert !(1..3).cover?(4) - end - else - def test_cover_is_not_override - range = (1..3) - assert range.method(:include?) != range.method(:cover?) - end + def test_cover_is_not_override + range = (1..3) + assert range.method(:include?) != range.method(:cover?) end end diff --git a/activesupport/test/core_ext/string_ext_test.rb b/activesupport/test/core_ext/string_ext_test.rb index 47b9f68ed0..aeae2579b4 100644 --- a/activesupport/test/core_ext/string_ext_test.rb +++ b/activesupport/test/core_ext/string_ext_test.rb @@ -160,14 +160,6 @@ class StringInflectionsTest < Test::Unit::TestCase assert_equal 97, 'abc'.ord end - if RUBY_VERSION < '1.9' - def test_getbyte - assert_equal 97, 'a'.getbyte(0) - assert_equal 99, 'abc'.getbyte(2) - assert_nil 'abc'.getbyte(3) - end - end - def test_string_to_time assert_equal Time.utc(2005, 2, 27, 23, 50), "2005-02-27 23:50".to_time assert_equal Time.local(2005, 2, 27, 23, 50), "2005-02-27 23:50".to_time(:local) @@ -287,21 +279,9 @@ class StringInflectionsTest < Test::Unit::TestCase assert_equal "Hello Big[...]", "Hello Big World!".truncate(15, :omission => "[...]", :separator => ' ') end - if RUBY_VERSION < '1.9.0' - def test_truncate_multibyte - with_kcode 'none' do - assert_equal "\354\225\210\353\205\225\355...", "\354\225\210\353\205\225\355\225\230\354\204\270\354\232\224".truncate(10) - end - with_kcode 'u' do - assert_equal "\354\225\204\353\246\254\353\236\221 \354\225\204\353\246\254 ...", - "\354\225\204\353\246\254\353\236\221 \354\225\204\353\246\254 \354\225\204\353\235\274\353\246\254\354\230\244".truncate(10) - end - end - else - def test_truncate_multibyte - assert_equal "\354\225\204\353\246\254\353\236\221 \354\225\204\353\246\254 ...".force_encoding('UTF-8'), - "\354\225\204\353\246\254\353\236\221 \354\225\204\353\246\254 \354\225\204\353\235\274\353\246\254\354\230\244".force_encoding('UTF-8').truncate(10) - end + def test_truncate_multibyte + assert_equal "\354\225\204\353\246\254\353\236\221 \354\225\204\353\246\254 ...".force_encoding('UTF-8'), + "\354\225\204\353\246\254\353\236\221 \354\225\204\353\246\254 \354\225\204\353\235\274\353\246\254\354\230\244".force_encoding('UTF-8').truncate(10) end def test_constantize @@ -338,22 +318,8 @@ class CoreExtStringMultibyteTest < ActiveSupport::TestCase assert !BYTE_STRING.is_utf8? end - if RUBY_VERSION < '1.9' - def test_mb_chars_returns_self_when_kcode_not_set - with_kcode('none') do - assert_kind_of String, UNICODE_STRING.mb_chars - end - end - - def test_mb_chars_returns_an_instance_of_the_chars_proxy_when_kcode_utf8 - with_kcode('UTF8') do - assert_kind_of ActiveSupport::Multibyte.proxy_class, UNICODE_STRING.mb_chars - end - end - else - def test_mb_chars_returns_instance_of_proxy_class - assert_kind_of ActiveSupport::Multibyte.proxy_class, UNICODE_STRING.mb_chars - end + def test_mb_chars_returns_instance_of_proxy_class + assert_kind_of ActiveSupport::Multibyte.proxy_class, UNICODE_STRING.mb_chars end end @@ -479,11 +445,7 @@ class OutputSafetyTest < ActiveSupport::TestCase end test 'knows whether it is encoding aware' do - if RUBY_VERSION >= "1.9" - assert 'ruby'.encoding_aware? - else - assert !'ruby'.encoding_aware? - end + assert 'ruby'.encoding_aware? end test "call to_param returns a normal string" do diff --git a/activesupport/test/core_ext/time_with_zone_test.rb b/activesupport/test/core_ext/time_with_zone_test.rb index 9d9e411c28..04f5ea85a8 100644 --- a/activesupport/test/core_ext/time_with_zone_test.rb +++ b/activesupport/test/core_ext/time_with_zone_test.rb @@ -448,9 +448,8 @@ class TimeWithZoneTest < Test::Unit::TestCase end def test_ruby_19_weekday_name_query_methods - ruby_19_or_greater = RUBY_VERSION >= '1.9' %w(sunday? monday? tuesday? wednesday? thursday? friday? saturday?).each do |name| - assert_equal ruby_19_or_greater, @twz.respond_to?(name) + assert_respond_to @twz, name end end diff --git a/activesupport/test/json/encoding_test.rb b/activesupport/test/json/encoding_test.rb index 8cf1a54a99..ad9a497515 100644 --- a/activesupport/test/json/encoding_test.rb +++ b/activesupport/test/json/encoding_test.rb @@ -88,25 +88,21 @@ class TestJSONEncoding < Test::Unit::TestCase assert_equal %({\"a\":\"b\",\"c\":\"d\"}), sorted_json(ActiveSupport::JSON.encode(:a => :b, :c => :d)) end - def test_utf8_string_encoded_properly_when_kcode_is_utf8 - with_kcode 'UTF8' do - result = ActiveSupport::JSON.encode('€2.99') - assert_equal '"\\u20ac2.99"', result - assert_equal(Encoding::UTF_8, result.encoding) if result.respond_to?(:encoding) - - result = ActiveSupport::JSON.encode('✎☺') - assert_equal '"\\u270e\\u263a"', result - assert_equal(Encoding::UTF_8, result.encoding) if result.respond_to?(:encoding) - end + def test_utf8_string_encoded_properly + result = ActiveSupport::JSON.encode('€2.99') + assert_equal '"\\u20ac2.99"', result + assert_equal(Encoding::UTF_8, result.encoding) if result.respond_to?(:encoding) + + result = ActiveSupport::JSON.encode('✎☺') + assert_equal '"\\u270e\\u263a"', result + assert_equal(Encoding::UTF_8, result.encoding) if result.respond_to?(:encoding) end - if '1.9'.respond_to?(:force_encoding) - def test_non_utf8_string_transcodes - s = '二'.encode('Shift_JIS') - result = ActiveSupport::JSON.encode(s) - assert_equal '"\\u4e8c"', result - assert_equal Encoding::UTF_8, result.encoding - end + def test_non_utf8_string_transcodes + s = '二'.encode('Shift_JIS') + result = ActiveSupport::JSON.encode(s) + assert_equal '"\\u4e8c"', result + assert_equal Encoding::UTF_8, result.encoding end def test_exception_raised_when_encoding_circular_reference_in_array diff --git a/activesupport/test/multibyte_chars_test.rb b/activesupport/test/multibyte_chars_test.rb index bfff10fff2..ba04638354 100644 --- a/activesupport/test/multibyte_chars_test.rb +++ b/activesupport/test/multibyte_chars_test.rb @@ -101,15 +101,8 @@ class MultibyteCharsUTF8BehaviourTest < Test::Unit::TestCase def setup @chars = UNICODE_STRING.dup.mb_chars - - if RUBY_VERSION < '1.9' - # Multibyte support all kinds of whitespace (ie. NEWLINE, SPACE, EM SPACE) - @whitespace = "\n\t#{[32, 8195].pack('U*')}" - else - # Ruby 1.9 only supports basic whitespace - @whitespace = "\n\t " - end - + # Ruby 1.9 only supports basic whitespace + @whitespace = "\n\t " @byte_order_mark = [65279].pack('U') end diff --git a/activesupport/test/multibyte_utils_test.rb b/activesupport/test/multibyte_utils_test.rb index 0a2f20d282..9a8f7050fe 100644 --- a/activesupport/test/multibyte_utils_test.rb +++ b/activesupport/test/multibyte_utils_test.rb @@ -56,37 +56,9 @@ class MultibyteUtilsTest < ActiveSupport::TestCase end end - if RUBY_VERSION < '1.9' - test "clean leaves ASCII strings intact" do - with_encoding('None') do - [ - 'word', "\270\236\010\210\245" - ].each do |string| - assert_equal string, ActiveSupport::Multibyte.clean(string) - end - end - end - - test "clean cleans invalid characters from UTF-8 encoded strings" do - with_encoding('UTF8') do - cleaned_utf8 = [8].pack('C*') - assert_equal example('valid UTF-8'), ActiveSupport::Multibyte.clean(example('valid UTF-8')) - assert_equal cleaned_utf8, ActiveSupport::Multibyte.clean(example('invalid UTF-8')) - end - end - - test "clean cleans invalid characters from Shift-JIS encoded strings" do - with_encoding('SJIS') do - cleaned_sjis = [184, 0, 136, 165].pack('C*') - assert_equal example('valid Shift-JIS'), ActiveSupport::Multibyte.clean(example('valid Shift-JIS')) - assert_equal cleaned_sjis, ActiveSupport::Multibyte.clean(example('invalid Shift-JIS')) - end - end - else - test "clean is a no-op" do - with_encoding('UTF8') do - assert_equal example('invalid Shift-JIS'), ActiveSupport::Multibyte.clean(example('invalid Shift-JIS')) - end + test "clean is a no-op" do + with_encoding('UTF8') do + assert_equal example('invalid Shift-JIS'), ActiveSupport::Multibyte.clean(example('invalid Shift-JIS')) end end @@ -119,19 +91,13 @@ class MultibyteUtilsTest < ActiveSupport::TestCase end end - if 'string'.respond_to?(:encoding) - KCODE_TO_ENCODING = Hash.new(Encoding::BINARY). - update('UTF8' => Encoding::UTF_8, 'SJIS' => Encoding::Shift_JIS) - - def with_encoding(enc) - before = Encoding.default_external - silence_warnings { Encoding.default_external = KCODE_TO_ENCODING[enc] } + KCODE_TO_ENCODING = Hash.new(Encoding::BINARY). + update('UTF8' => Encoding::UTF_8, 'SJIS' => Encoding::Shift_JIS) - yield - - silence_warnings { Encoding.default_external = before } - end - else - alias with_encoding with_kcode + def with_encoding(enc) + before = Encoding.default_external + silence_warnings { Encoding.default_external = KCODE_TO_ENCODING[enc] } + yield + silence_warnings { Encoding.default_external = before } end end diff --git a/activesupport/test/ordered_hash_test.rb b/activesupport/test/ordered_hash_test.rb index 0b5f912dc4..8119b36491 100644 --- a/activesupport/test/ordered_hash_test.rb +++ b/activesupport/test/ordered_hash_test.rb @@ -81,24 +81,21 @@ class OrderedHashTest < Test::Unit::TestCase keys = [] assert_equal @ordered_hash, @ordered_hash.each_key { |k| keys << k } assert_equal @keys, keys - expected_class = RUBY_VERSION < '1.9' ? Enumerable::Enumerator : Enumerator - assert_kind_of expected_class, @ordered_hash.each_key + assert_kind_of Enumerator, @ordered_hash.each_key end def test_each_value values = [] assert_equal @ordered_hash, @ordered_hash.each_value { |v| values << v } assert_equal @values, values - expected_class = RUBY_VERSION < '1.9' ? Enumerable::Enumerator : Enumerator - assert_kind_of expected_class, @ordered_hash.each_value + assert_kind_of Enumerator, @ordered_hash.each_value end def test_each values = [] assert_equal @ordered_hash, @ordered_hash.each {|key, value| values << value} assert_equal @values, values - expected_class = RUBY_VERSION < '1.9' ? Enumerable::Enumerator : Enumerator - assert_kind_of expected_class, @ordered_hash.each + assert_kind_of Enumerator, @ordered_hash.each end def test_each_with_index @@ -114,9 +111,7 @@ class OrderedHashTest < Test::Unit::TestCase end assert_equal @values, values assert_equal @keys, keys - - expected_class = RUBY_VERSION < '1.9' ? Enumerable::Enumerator : Enumerator - assert_kind_of expected_class, @ordered_hash.each_pair + assert_kind_of Enumerator, @ordered_hash.each_pair end def test_find_all -- cgit v1.2.3