Commit f0933d8f by Jérémie Gaidamour

### [dev] Renamed expand_angle_bracket -> expand_square_bracket

parent 2e2827e9
 ... ... @@ -33,13 +33,14 @@ class ::Hash # * If only a is omited, a == 1. # * If b is omited, only existing keys are modified (no keys are created). Otherwise, PREFIX-[a] to PREFIX-[b] entries are created (if missing). # Example: # {"foo-1": {a: 0}, "foo-2": {a: 0}, "foo-3": {a: 0}, "foo-[2-]": {b: 1}}.expand_angle_brackets() # {"foo-1": {a: 0}, "foo-2": {a: 0}, "foo-3": {a: 0}, "foo-[2-]": {b: 1}}.expand_square_brackets() # -> {"foo-1": {a: 0}, "foo-2": {a: 0, b:1}, "foo-3": {a: 0, b: 0}} def expand_angle_brackets() def expand_square_brackets() dup = self.clone # because can't add a new key into hash during iteration # Looking up for PREFIX-[a-b] keys dup.each { |key_ab, value_ab| prefix, a, b = key_ab.to_s.scan(/^(.*)-\[(\d*)-(\d*)\]\$/).first next if not a and not b # not found a != "" ? a = a.to_i : a = 1 ... ... @@ -76,7 +77,7 @@ class ::Hash # Do it recursivly self.each { |key, value| if value.is_a?(Hash) value.expand_angle_brackets() value.expand_square_brackets() end } end ... ...
 ... ... @@ -30,7 +30,7 @@ def load_yaml_file_hierarchy(directory) # Expand the hash. Done at each iteration for enforcing priorities between duplicate entries: # ie. keys to be expanded have lowest priority on existing entries but higher priority on the entries found in the next files global_hash.expand_angle_brackets() global_hash.expand_square_brackets() } ... ...
 ... ... @@ -12,8 +12,8 @@ end # Helper test routine. Test if the hashes are equal after having been expanded. def assert_equal_expanded_hash(hash1, hash2) expanded_hash1 = hash1.clone.expand_angle_brackets() expanded_hash2 = hash2.clone.expand_angle_brackets() expanded_hash1 = hash1.clone.expand_square_brackets() expanded_hash2 = hash2.clone.expand_square_brackets() assert_equal_hash(expanded_hash1, expanded_hash2) end ... ... @@ -53,7 +53,7 @@ class TestInputLoader < Test::Unit::TestCase end # Test the example given in documentation def test__expand_angle_brackets__doc_example def test__expand_square_brackets__doc_example hash = { "foo-1": {a: 0}, "foo-2": {a: 0}, ... ... @@ -71,12 +71,12 @@ class TestInputLoader < Test::Unit::TestCase end # The 'a' parameter def test__expand_angle_brackets__a_values def test__expand_square_brackets__a_values assert_equal_expanded_hash({"foo-[-3]": 0}, {"foo-1": 0, "foo-2": 0, "foo-3": 0}) # Default 'a' value is 1 assert_equal_expanded_hash({"foo-[2-3]": 0}, {"foo-2": 0, "foo-3": 0}) # Simply check if the value of 'a' is taken into account end def test__expand_angle_brackets__create_keys def test__expand_square_brackets__create_keys # # If 'b' is given, create missing keys. Also, the keys must be of the same type (Symbol or String). # ... ... @@ -105,7 +105,7 @@ class TestInputLoader < Test::Unit::TestCase end def test__expand_angle_brackets__keep_existing_keys def test__expand_square_brackets__keep_existing_keys # # Do not modify existing keys # ... ... @@ -117,7 +117,7 @@ class TestInputLoader < Test::Unit::TestCase end # Some tests with nil values (=> nil values are created, existing nil values are overriden) def test__expand_angle_brackets__nil def test__expand_square_brackets__nil assert_equal_expanded_hash({"foo-[2-3]": nil}, {"foo-2": nil, "foo-3": nil}) # PREFIX-[a-b] is nil assert_equal_expanded_hash({"foo-[2-3]": 0, "foo-2": nil}, {"foo-2": 0, "foo-3": 0}) # PREFIX-x is nil assert_equal_expanded_hash({"foo-[2-]": nil, "foo-3": 0}, {"foo-3": 0}) # PREFIX-[a-] is nil ... ...
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!