Module: Diff::LCS::SpecHelper
- Defined in:
- lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/diff-lcs-1.5.0/spec/spec_helper.rb
Defined Under Namespace
Modules: Matchers
Instance Method Summary collapse
- #balanced_callback ⇒ Object
- #balanced_callback_no_change ⇒ Object
- #balanced_reverse(change_result) ⇒ Object
- #balanced_traversal(s1, s2, callback_type) ⇒ Object
- #change_diff(diff) ⇒ Object
- #context_diff(diff) ⇒ Object
- #correct_backward_diff ⇒ Object
- #correct_forward_diff ⇒ Object
- #correct_forward_sdiff ⇒ Object
- #correct_lcs ⇒ Object
- #format_diffs(diffs) ⇒ Object
- #hello ⇒ Object
- #hello_ary ⇒ Object
- #map_diffs(diffs, klass = Diff::LCS::ContextChange) ⇒ Object
- #map_to_no_change(change_result) ⇒ Object
- #reverse_sdiff(forward_sdiff) ⇒ Object
- #seq1 ⇒ Object
- #seq2 ⇒ Object
- #simple_callback ⇒ Object
- #simple_callback_no_finishers ⇒ Object
- #skipped_seq1 ⇒ Object
- #skipped_seq2 ⇒ Object
- #word_sequence ⇒ Object
Instance Method Details
#balanced_callback ⇒ Object
310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/diff-lcs-1.5.0/spec/spec_helper.rb', line 310 def balanced_callback cb = Object.new class << cb attr_reader :result def reset @result = [] end def match(event) @result << ['=', event.old_position, event.new_position] end def discard_a(event) @result << ['<', event.old_position, event.new_position] end def discard_b(event) @result << ['>', event.old_position, event.new_position] end def change(event) @result << ['!', event.old_position, event.new_position] end end cb.reset cb end |
#balanced_callback_no_change ⇒ Object
339 340 341 342 343 344 345 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/diff-lcs-1.5.0/spec/spec_helper.rb', line 339 def balanced_callback_no_change balanced = balanced_callback class << balanced undef :change end balanced end |
#balanced_reverse(change_result) ⇒ Object
222 223 224 225 226 227 228 229 230 231 232 233 234 235 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/diff-lcs-1.5.0/spec/spec_helper.rb', line 222 def balanced_reverse(change_result) new_result = [] change_result.each do |line| line = [line[0], line[2], line[1]] case line[0] when '<' line[0] = '>' when '>' line[0] = '<' end new_result << line end new_result.sort_by { |line| [line[1], line[2]] } end |
#balanced_traversal(s1, s2, callback_type) ⇒ Object
216 217 218 219 220 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/diff-lcs-1.5.0/spec/spec_helper.rb', line 216 def balanced_traversal(s1, s2, callback_type) callback = __send__(callback_type) Diff::LCS.traverse_balanced(s1, s2, callback) callback end |
#change_diff(diff) ⇒ Object
188 189 190 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/diff-lcs-1.5.0/spec/spec_helper.rb', line 188 def change_diff(diff) map_diffs(diff, Diff::LCS::Change) end |
#context_diff(diff) ⇒ Object
192 193 194 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/diff-lcs-1.5.0/spec/spec_helper.rb', line 192 def context_diff(diff) map_diffs(diff, Diff::LCS::ContextChange) end |
#correct_backward_diff ⇒ Object
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/diff-lcs-1.5.0/spec/spec_helper.rb', line 134 def correct_backward_diff [ [ ['+', 0, 'a'] ], [ ['-', 2, 'd'] ], [ ['-', 4, 'f'], ['+', 4, 'h'] ], [ ['-', 6, 'k'] ], [ ['-', 9, 'r'], ['+', 8, 'n'], ['-', 10, 's'], ['+', 9, 'p'], ['-', 11, 't'] ] ] end |
#correct_forward_diff ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/diff-lcs-1.5.0/spec/spec_helper.rb', line 109 def correct_forward_diff [ [ ['-', 0, 'a'] ], [ ['+', 2, 'd'] ], [ ['-', 4, 'h'], ['+', 4, 'f'] ], [ ['+', 6, 'k'] ], [ ['-', 8, 'n'], ['+', 9, 'r'], ['-', 9, 'p'], ['+', 10, 's'], ['+', 11, 't'] ] ] end |
#correct_forward_sdiff ⇒ Object
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/diff-lcs-1.5.0/spec/spec_helper.rb', line 159 def correct_forward_sdiff [ ['-', [0, 'a'], [0, nil]], ['=', [1, 'b'], [0, 'b']], ['=', [2, 'c'], [1, 'c']], ['+', [3, nil], [2, 'd']], ['=', [3, 'e'], [3, 'e']], ['!', [4, 'h'], [4, 'f']], ['=', [5, 'j'], [5, 'j']], ['+', [6, nil], [6, 'k']], ['=', [6, 'l'], [7, 'l']], ['=', [7, 'm'], [8, 'm']], ['!', [8, 'n'], [9, 'r']], ['!', [9, 'p'], [10, 's']], ['+', [10, nil], [11, 't']] ] end |
#correct_lcs ⇒ Object
105 106 107 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/diff-lcs-1.5.0/spec/spec_helper.rb', line 105 def correct_lcs %w(b c e j l m) end |
#format_diffs(diffs) ⇒ Object
196 197 198 199 200 201 202 203 204 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/diff-lcs-1.5.0/spec/spec_helper.rb', line 196 def format_diffs(diffs) diffs.map { |e| if e.kind_of?(Array) e.map { |f| f.to_a.join }.join(', ') else e.to_a.join end }.join("\n") end |
#hello ⇒ Object
77 78 79 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/diff-lcs-1.5.0/spec/spec_helper.rb', line 77 def hello 'hello' end |
#hello_ary ⇒ Object
81 82 83 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/diff-lcs-1.5.0/spec/spec_helper.rb', line 81 def hello_ary %w(h e l l o) end |
#map_diffs(diffs, klass = Diff::LCS::ContextChange) ⇒ Object
206 207 208 209 210 211 212 213 214 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/diff-lcs-1.5.0/spec/spec_helper.rb', line 206 def map_diffs(diffs, klass = Diff::LCS::ContextChange) diffs.map do |chunks| if klass == Diff::LCS::ContextChange klass.from_a(chunks) else chunks.map { |changes| klass.from_a(changes) } end end end |
#map_to_no_change(change_result) ⇒ Object
237 238 239 240 241 242 243 244 245 246 247 248 249 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/diff-lcs-1.5.0/spec/spec_helper.rb', line 237 def map_to_no_change(change_result) new_result = [] change_result.each do |line| case line[0] when '!' new_result << ['<', line[1], line[2]] new_result << ['>', line[1] + 1, line[2]] else new_result << line end end new_result end |
#reverse_sdiff(forward_sdiff) ⇒ Object
177 178 179 180 181 182 183 184 185 186 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/diff-lcs-1.5.0/spec/spec_helper.rb', line 177 def reverse_sdiff(forward_sdiff) forward_sdiff.map { |line| line[1], line[2] = line[2], line[1] case line[0] when '-' then line[0] = '+' when '+' then line[0] = '-' end line } end |
#seq1 ⇒ Object
85 86 87 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/diff-lcs-1.5.0/spec/spec_helper.rb', line 85 def seq1 %w(a b c e h j l m n p) end |
#seq2 ⇒ Object
93 94 95 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/diff-lcs-1.5.0/spec/spec_helper.rb', line 93 def seq2 %w(b c d e f j k l m r s t) end |
#simple_callback ⇒ Object
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/diff-lcs-1.5.0/spec/spec_helper.rb', line 251 def simple_callback callbacks = Object.new class << callbacks attr_reader :matched_a attr_reader :matched_b attr_reader :discards_a attr_reader :discards_b attr_reader :done_a attr_reader :done_b def reset @matched_a = [] @matched_b = [] @discards_a = [] @discards_b = [] @done_a = [] @done_b = [] end def match(event) @matched_a << event.old_element @matched_b << event.new_element end def discard_b(event) @discards_b << event.new_element end def discard_a(event) @discards_a << event.old_element end def finished_a(event) @done_a << [ event.old_element, event.old_position, event.new_element, event.new_position ] end def finished_b(event) @done_b << [ event.old_element, event.old_position, event.new_element, event.new_position ] end end callbacks.reset callbacks end |
#simple_callback_no_finishers ⇒ Object
301 302 303 304 305 306 307 308 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/diff-lcs-1.5.0/spec/spec_helper.rb', line 301 def simple_callback_no_finishers simple = simple_callback class << simple undef :finished_a undef :finished_b end simple end |
#skipped_seq1 ⇒ Object
89 90 91 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/diff-lcs-1.5.0/spec/spec_helper.rb', line 89 def skipped_seq1 %w(a h n p) end |
#skipped_seq2 ⇒ Object
97 98 99 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/diff-lcs-1.5.0/spec/spec_helper.rb', line 97 def skipped_seq2 %w(d f k r s t) end |
#word_sequence ⇒ Object
101 102 103 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/diff-lcs-1.5.0/spec/spec_helper.rb', line 101 def word_sequence %w(abcd efgh ijkl mnopqrstuvwxyz) end |