README.md in diff_matcher-2.1.1 vs README.md in diff_matcher-2.2.0

- old
+ new

@@ -103,42 +103,74 @@ # => ] # => Where, + 1 additional ``` -When `expected` can take multiple forms use a `Matcher` +When `expected` is a `Hash` with optional keys use a `Matcher`. ``` ruby -puts DiffMatcher::difference(DiffMatcher::Matcher[Fixnum,Float], "3") +puts DiffMatcher::difference( + DiffMatcher::Matcher.new({:name=>String, :age=>Fixnum}, :optional_keys=>[:age]), + {:name=>0} +) +{ + :name=>- String+ 0 +} +Where, - 1 missing, + 1 additional +``` + + +When `expected` can take multiple forms use some `Matcher`s `||`ed together. + +``` ruby +puts DiffMatcher::difference(DiffMatcher::Matcher.new(Fixnum) || DiffMatcher.new(Float), "3") - Float+ "3" Where, - 1 missing, + 1 additional ``` +(NB. `DiffMatcher::Matcher[Fixnum, Float]` can be used as a shortcut for + `DiffMatcher::Matcher.new(Fixnum) || DiffMatcher.new(Float)` +) -When `actual` is an array of unknown size use an `AllMatcher` to match +When `actual` is an array of *unknown* size use an `AllMatcher` to match against *all* the elements in the array. ``` ruby -puts DiffMatcher::difference(DiffMatcher::AllMatcher[Fixnum], [1, 2, "3"]) +puts DiffMatcher::difference(DiffMatcher::AllMatcher.new(Fixnum), [1, 2, "3"]) [ : 1, : 2, - Fixnum+ "3" ] Where, - 1 missing, + 1 additional, : 2 match_class ``` +When `actual` is an array with a *limited* size use an `AllMatcher` to match +against *all* the elements in the array adhering to the limits of `:min` +and or `:max`. + +``` ruby +puts DiffMatcher::difference(DiffMatcher::AllMatcher.new(Fixnum, :min=>3), [1, 2]) +[ + : 1, + : 2, + - Fixnum +] +Where, - 1 missing, : 2 match_class +``` + + When `actual` is an array of unknown size *and* `expected` can take multiple forms use a `Matcher` inside of an `AllMatcher` to match against *all* the elements in the array in any of the forms. ``` ruby puts DiffMatcher::difference( - DiffMatcher::AllMatcher[ + DiffMatcher::AllMatcher.new( DiffMatcher::Matcher[Fixnum, Float] - ], + ), [1, 2.00, "3"] ) [ | 1, | 2.0, @@ -173,10 +205,12 @@ missing => "- " additional => "+ " match value => match regexp => "~ " match class => ": " + match matcher => "| " + match proc => ". " match proc => "{ " #### Colours @@ -187,9 +221,11 @@ missing => red additional => yellow match value => match regexp => green match class => blue + match matcher => blue + match range => cyan match proc => cyan Other colour schemes, eg. `:color_scheme=>:white_background` will use different colour mappings.