diff options
Diffstat (limited to 'activesupport/test/ordered_hash_test.rb')
-rw-r--r-- | activesupport/test/ordered_hash_test.rb | 98 |
1 files changed, 50 insertions, 48 deletions
diff --git a/activesupport/test/ordered_hash_test.rb b/activesupport/test/ordered_hash_test.rb index 460a61613e..c70d3b4c37 100644 --- a/activesupport/test/ordered_hash_test.rb +++ b/activesupport/test/ordered_hash_test.rb @@ -1,8 +1,10 @@ -require 'abstract_unit' -require 'active_support/json' -require 'active_support/core_ext/object/json' -require 'active_support/core_ext/hash/indifferent_access' -require 'active_support/core_ext/array/extract_options' +# frozen_string_literal: true + +require "abstract_unit" +require "active_support/json" +require "active_support/core_ext/object/json" +require "active_support/core_ext/hash/indifferent_access" +require "active_support/core_ext/array/extract_options" class OrderedHashTest < ActiveSupport::TestCase def setup @@ -27,7 +29,7 @@ class OrderedHashTest < ActiveSupport::TestCase end def test_assignment - key, value = 'purple', '5422a8' + key, value = "purple", "5422a8" @ordered_hash[key] = value assert_equal @keys.length + 1, @ordered_hash.length @@ -37,8 +39,8 @@ class OrderedHashTest < ActiveSupport::TestCase end def test_delete - key, value = 'white', 'ffffff' - bad_key = 'black' + key, value = "white", "ffffff" + bad_key = "black" @ordered_hash[key] = value assert_equal @keys.length + 1, @ordered_hash.length @@ -60,22 +62,22 @@ class OrderedHashTest < ActiveSupport::TestCase end def test_has_key - assert_equal true, @ordered_hash.has_key?('blue') - assert_equal true, @ordered_hash.key?('blue') - assert_equal true, @ordered_hash.include?('blue') - assert_equal true, @ordered_hash.member?('blue') + assert_equal true, @ordered_hash.has_key?("blue") + assert_equal true, @ordered_hash.key?("blue") + assert_equal true, @ordered_hash.include?("blue") + assert_equal true, @ordered_hash.member?("blue") - assert_equal false, @ordered_hash.has_key?('indigo') - assert_equal false, @ordered_hash.key?('indigo') - assert_equal false, @ordered_hash.include?('indigo') - assert_equal false, @ordered_hash.member?('indigo') + assert_equal false, @ordered_hash.has_key?("indigo") + assert_equal false, @ordered_hash.key?("indigo") + assert_equal false, @ordered_hash.include?("indigo") + assert_equal false, @ordered_hash.member?("indigo") end def test_has_value - assert_equal true, @ordered_hash.has_value?('000099') - assert_equal true, @ordered_hash.value?('000099') - assert_equal false, @ordered_hash.has_value?('ABCABC') - assert_equal false, @ordered_hash.value?('ABCABC') + assert_equal true, @ordered_hash.has_value?("000099") + assert_equal true, @ordered_hash.value?("000099") + assert_equal false, @ordered_hash.has_value?("ABCABC") + assert_equal false, @ordered_hash.value?("ABCABC") end def test_each_key @@ -94,13 +96,13 @@ class OrderedHashTest < ActiveSupport::TestCase def test_each values = [] - assert_equal @ordered_hash, @ordered_hash.each {|key, value| values << value} + assert_equal @ordered_hash, @ordered_hash.each { |key, value| values << value } assert_equal @values, values assert_kind_of Enumerator, @ordered_hash.each end def test_each_with_index - @ordered_hash.each_with_index { |pair, index| assert_equal [@keys[index], @values[index]], pair} + @ordered_hash.each_with_index { |pair, index| assert_equal [@keys[index], @values[index]], pair } end def test_each_pair @@ -127,24 +129,24 @@ class OrderedHashTest < ActiveSupport::TestCase def test_delete_if copy = @ordered_hash.dup - copy.delete('pink') - assert_equal copy, @ordered_hash.delete_if { |k, _| k == 'pink' } - assert !@ordered_hash.keys.include?('pink') + copy.delete("pink") + assert_equal copy, @ordered_hash.delete_if { |k, _| k == "pink" } + assert_not_includes @ordered_hash.keys, "pink" end def test_reject! - (copy = @ordered_hash.dup).delete('pink') - @ordered_hash.reject! { |k, _| k == 'pink' } + (copy = @ordered_hash.dup).delete("pink") + @ordered_hash.reject! { |k, _| k == "pink" } assert_equal copy, @ordered_hash - assert !@ordered_hash.keys.include?('pink') + assert_not_includes @ordered_hash.keys, "pink" end def test_reject copy = @ordered_hash.dup - new_ordered_hash = @ordered_hash.reject { |k, _| k == 'pink' } + new_ordered_hash = @ordered_hash.reject { |k, _| k == "pink" } assert_equal copy, @ordered_hash - assert !new_ordered_hash.keys.include?('pink') - assert @ordered_hash.keys.include?('pink') + assert_not_includes new_ordered_hash.keys, "pink" + assert_includes @ordered_hash.keys, "pink" assert_instance_of ActiveSupport::OrderedHash, new_ordered_hash end @@ -154,19 +156,19 @@ class OrderedHashTest < ActiveSupport::TestCase end def test_merge - other_hash = ActiveSupport::OrderedHash.new - other_hash['purple'] = '800080' - other_hash['violet'] = 'ee82ee' + other_hash = ActiveSupport::OrderedHash.new + other_hash["purple"] = "800080" + other_hash["violet"] = "ee82ee" merged = @ordered_hash.merge other_hash assert_equal merged.length, @ordered_hash.length + other_hash.length - assert_equal @keys + ['purple', 'violet'], merged.keys + assert_equal @keys + ["purple", "violet"], merged.keys end def test_merge_with_block hash = ActiveSupport::OrderedHash.new hash[:a] = 0 hash[:b] = 0 - merged = hash.merge(:b => 2, :c => 7) do |key, old_value, new_value| + merged = hash.merge(b: 2, c: 7) do |key, old_value, new_value| new_value + 1 end @@ -179,7 +181,7 @@ class OrderedHashTest < ActiveSupport::TestCase hash = ActiveSupport::OrderedHash.new hash[:a] = 0 hash[:b] = 0 - hash.merge!(:a => 1, :c => 7) do |key, old_value, new_value| + hash.merge!(a: 1, c: 7) do |key, old_value, new_value| new_value + 3 end @@ -191,7 +193,7 @@ class OrderedHashTest < ActiveSupport::TestCase def test_shift pair = @ordered_hash.shift assert_equal [@keys.first, @values.first], pair - assert !@ordered_hash.keys.include?(pair.first) + assert_not_includes @ordered_hash.keys, pair.first end def test_keys @@ -201,7 +203,7 @@ class OrderedHashTest < ActiveSupport::TestCase end def test_inspect - assert @ordered_hash.inspect.include?(@hash.inspect) + assert_includes @ordered_hash.inspect, @hash.inspect end def test_json @@ -211,7 +213,7 @@ class OrderedHashTest < ActiveSupport::TestCase end def test_alternate_initialization_with_splat - alternate = ActiveSupport::OrderedHash[1,2,3,4] + alternate = ActiveSupport::OrderedHash[1, 2, 3, 4] assert_kind_of ActiveSupport::OrderedHash, alternate assert_equal [1, 3], alternate.keys end @@ -220,29 +222,29 @@ class OrderedHashTest < ActiveSupport::TestCase alternate = ActiveSupport::OrderedHash[ [ [1, 2], [3, 4], - [ 'missing value' ] + [ "missing value" ] ]] assert_kind_of ActiveSupport::OrderedHash, alternate - assert_equal [1, 3, 'missing value'], alternate.keys + assert_equal [1, 3, "missing value"], alternate.keys assert_equal [2, 4, nil ], alternate.values end def test_alternate_initialization_raises_exception_on_odd_length_args assert_raises ArgumentError do - ActiveSupport::OrderedHash[1,2,3,4,5] + ActiveSupport::OrderedHash[1, 2, 3, 4, 5] end end def test_replace_updates_keys - @other_ordered_hash = ActiveSupport::OrderedHash[:black, '000000', :white, '000000'] + @other_ordered_hash = ActiveSupport::OrderedHash[:black, "000000", :white, "000000"] original = @ordered_hash.replace(@other_ordered_hash) assert_same original, @ordered_hash assert_equal @other_ordered_hash.keys, @ordered_hash.keys end def test_nested_under_indifferent_access - flash = {:a => ActiveSupport::OrderedHash[:b, 1, :c, 2]}.with_indifferent_access + flash = { a: ActiveSupport::OrderedHash[:b, 1, :c, 2] }.with_indifferent_access assert_kind_of ActiveSupport::OrderedHash, flash[:a] end @@ -295,17 +297,17 @@ class OrderedHashTest < ActiveSupport::TestCase def test_psych_serialize_tag yaml = Psych.dump(@ordered_hash) - assert_match '!omap', yaml + assert_match "!omap", yaml end def test_has_yaml_tag @ordered_hash[:array] = %w(a b c) - assert_match '!omap', YAML.dump(@ordered_hash) + assert_match "!omap", YAML.dump(@ordered_hash) end def test_update_sets_keys @updated_ordered_hash = ActiveSupport::OrderedHash.new - @updated_ordered_hash.update(:name => "Bob") + @updated_ordered_hash.update(name: "Bob") assert_equal [:name], @updated_ordered_hash.keys end |