Browse files

be sure to dup the default container on copy

  • Loading branch information...
1 parent 58cff25 commit 3e8c6d78cafcf233a233804b8d8b0cd4ae3b3840 @josh josh committed Jun 24, 2009
Showing with 32 additions and 0 deletions.
  1. +1 −0 lib/multimap.rb
  2. +31 −0 spec/fuzzy_nested_multimap_spec.rb
View
1 lib/multimap.rb
@@ -77,6 +77,7 @@ def initialize_copy(original) #:nodoc:
super
clear
original.each_pair { |key, container| self[key] = container }
+ self.default = original.default.dup
end
#--
View
31 spec/fuzzy_nested_multimap_spec.rb
@@ -57,6 +57,37 @@
@map["c"].should == ["c"]
end
+ it "nested regexps are properly copied" do
+ @map = FuzzyNestedMultimap.new
+ @map[/.+/, /.+/, "z"] = "???z"
+ @map["a"] = "a"
+ @map["b"] = "b"
+
+ @map["a"].should == ["a"]
+ @map["b"].should == ["b"]
+ @map["a", "b", "z"].should == ["???z", "a"]
+ @map["x", "y", "z"].should == ["???z"]
+ end
+
+ it "does not lose deeply nested wild cards" do
+ @map = FuzzyNestedMultimap.new
+ @map["a"] = "a"
+ @map[/.+/, /.+/, /.+/, "z"] = "???z"
+ @map["b", "c"] = "bc"
+ @map["a", /.+/, "b"] = "a?b"
+ @map["a", /.+/, "c"] = "a?c"
+ @map["c", "d"] = "cd"
+
+ @map["a"].should == ["a"]
+ @map["w", "x", "y", "z"].should == ["???z"]
+ @map["b", "c"].should == ["bc"]
+ @map["a", "a", "b"].should == ["a", "a?b"]
+ @map["a", "b", "b"].should == ["a", "a?b"]
+ @map["a", "a", "c"].should == ["a", "a?c"]
+ @map["a", "b", "c"].should == ["a", "a?c"]
+ @map["c", "d"].should == ["cd"]
+ end
+
it "should support any key that responds to =~" do
@map[true] = "TrueClass"
@map[false] = "FalseClass"

0 comments on commit 3e8c6d7

Please sign in to comment.