diff options
author | Austin Ziegler <austin@halostatue.ca> | 2011-07-31 13:52:14 -0400 |
---|---|---|
committer | Austin Ziegler <austin@halostatue.ca> | 2011-07-31 13:52:14 -0400 |
commit | 340073b761d16d7ec3a0a559e0c8d706b1d2dff9 (patch) | |
tree | d864acc05816669a3788d88d9f79779ecf3351ac /spec/spec_helper.rb | |
parent | 85076475902cc7f5a5eb7d52d8aaf56d1ff43583 (diff) | |
download | diff-lcs-340073b761d16d7ec3a0a559e0c8d706b1d2dff9.tar.gz |
Expanding rspec tests to reflect reality.
There's a lot more testing that was happening in the code than was being
reported. Now many of the special cases that were hidden by the
transforms for balanced traversal (reverse, change/no change) have been
made into individual tests with the use of shared example groups.
Diffstat (limited to 'spec/spec_helper.rb')
-rw-r--r-- | spec/spec_helper.rb | 57 |
1 files changed, 36 insertions, 21 deletions
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 1c934e7..5150b10 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -126,6 +126,42 @@ module Diff::LCS::SpecHelper end end + def balanced_traversal(s1, s2, callback_type) + callback = __send__(callback_type) + Diff::LCS.traverse_balanced(s1, s2, callback) + callback + end + + def balanced_reverse(change_result) + new_result = [] + change_result.each { |line| + line = [ line[0], line[2], line[1] ] + case line[0] + when '<' + line[0] = '>' + when '>' + line[0] = '<' + end + new_result << line + } + new_result.sort_by { |line| line[1] } + end + + def map_to_no_change(change_result) + new_result = [] + change_result.each { |line| + case line[0] + when '!' + new_result << [ '<', line[1], line[2] ] + new_result << [ '>', line[1] + 1, line[2] ] + else + new_result << line + end + } + new_result + end + + def simple_callback callbacks = Object.new class << callbacks @@ -246,25 +282,4 @@ RSpec.configure do |conf| conf.include Diff::LCS::SpecHelper end - -=begin -RSpec::Matchers.define :be_a_multiple_of do |expected| - match do |actual| - actual % expected == 0 - end - - failure_message_for_should do |actual| - "expected that #{actual} would be a multiple of #{expected}" - end - - failure_message_for_should_not do |actual| - "expected that #{actual} would not be a multiple of #{expected}" - end - - description do - "be multiple of #{expected}" - end -end -=end - # vim: ft=ruby |