activeldap 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGES +10 -0
- data/README +3 -2
- data/data/locale/en/LC_MESSAGES/active-ldap.mo +0 -0
- data/data/locale/ja/LC_MESSAGES/active-ldap.mo +0 -0
- data/examples/al-admin/po/en/al-admin.po +1 -1
- data/examples/al-admin/po/ja/al-admin.po +1 -1
- data/examples/al-admin/po/nl/al-admin.po +1 -1
- data/examples/al-admin/vendor/plugins/exception_notification/lib/exception_notifier.rb +7 -8
- data/examples/al-admin/vendor/plugins/exception_notification/lib/exception_notifier_helper.rb +2 -1
- data/examples/al-admin/vendor/plugins/exception_notification/views/exception_notifier/_environment.rhtml +1 -1
- data/examples/al-admin/vendor/plugins/exception_notification/views/exception_notifier/_request.rhtml +2 -1
- data/lib/active_ldap.rb +9 -3
- data/lib/active_ldap/action_controller/ldap_benchmarking.rb +36 -0
- data/lib/active_ldap/adapter/jndi.rb +1 -1
- data/lib/active_ldap/adapter/jndi_connection.rb +2 -1
- data/lib/active_ldap/association/belongs_to_many.rb +10 -2
- data/lib/active_ldap/association/collection.rb +10 -0
- data/lib/active_ldap/association/has_many_utils.rb +13 -9
- data/lib/active_ldap/association/has_many_wrap.rb +10 -2
- data/lib/active_ldap/associations.rb +3 -3
- data/lib/active_ldap/base.rb +95 -32
- data/lib/active_ldap/connection.rb +1 -1
- data/lib/active_ldap/distinguished_name.rb +3 -0
- data/lib/active_ldap/entry_attribute.rb +2 -2
- data/lib/active_ldap/ldif.rb +2 -2
- data/lib/active_ldap/operations.rb +7 -3
- data/lib/active_ldap/user_password.rb +0 -1
- data/lib/active_ldap/validations.rb +2 -0
- data/po/en/active-ldap.po +1 -1
- data/po/ja/active-ldap.po +1 -1
- data/rails/plugin/active_ldap/init.rb +3 -34
- data/test-unit/History.txt +32 -0
- data/test-unit/Manifest.txt +70 -0
- data/test-unit/README.txt +32 -0
- data/test-unit/Rakefile +22 -0
- data/test-unit/bin/testrb +5 -0
- data/test-unit/lib/test/unit.rb +280 -0
- data/test-unit/lib/test/unit/assertionfailederror.rb +14 -0
- data/test-unit/lib/test/unit/assertions.rb +722 -0
- data/test-unit/lib/test/unit/attribute.rb +125 -0
- data/test-unit/lib/test/unit/autorunner.rb +250 -0
- data/test-unit/lib/test/unit/collector.rb +43 -0
- data/test-unit/lib/test/unit/collector/descendant.rb +23 -0
- data/test-unit/lib/test/unit/collector/dir.rb +108 -0
- data/test-unit/lib/test/unit/collector/load.rb +135 -0
- data/test-unit/lib/test/unit/collector/objectspace.rb +34 -0
- data/test-unit/lib/test/unit/color.rb +61 -0
- data/test-unit/lib/test/unit/diff.rb +524 -0
- data/test-unit/lib/test/unit/error.rb +124 -0
- data/test-unit/lib/test/unit/exceptionhandler.rb +39 -0
- data/test-unit/lib/test/unit/failure.rb +110 -0
- data/test-unit/lib/test/unit/fixture.rb +185 -0
- data/test-unit/lib/test/unit/notification.rb +116 -0
- data/test-unit/lib/test/unit/omission.rb +129 -0
- data/test-unit/lib/test/unit/pending.rb +130 -0
- data/test-unit/lib/test/unit/priority.rb +146 -0
- data/test-unit/lib/test/unit/runner/console.rb +46 -0
- data/test-unit/lib/test/unit/runner/emacs.rb +8 -0
- data/test-unit/lib/test/unit/testcase.rb +174 -0
- data/test-unit/lib/test/unit/testresult.rb +89 -0
- data/test-unit/lib/test/unit/testsuite.rb +110 -0
- data/test-unit/lib/test/unit/ui/console/outputlevel.rb +14 -0
- data/test-unit/lib/test/unit/ui/console/testrunner.rb +195 -0
- data/test-unit/lib/test/unit/ui/emacs/testrunner.rb +49 -0
- data/test-unit/lib/test/unit/ui/testrunner.rb +20 -0
- data/test-unit/lib/test/unit/ui/testrunnermediator.rb +77 -0
- data/test-unit/lib/test/unit/ui/testrunnerutilities.rb +41 -0
- data/test-unit/lib/test/unit/util/backtracefilter.rb +41 -0
- data/test-unit/lib/test/unit/util/observable.rb +90 -0
- data/test-unit/lib/test/unit/util/procwrapper.rb +48 -0
- data/test-unit/lib/test/unit/version.rb +7 -0
- data/test-unit/sample/adder.rb +13 -0
- data/test-unit/sample/subtracter.rb +12 -0
- data/test-unit/sample/tc_adder.rb +18 -0
- data/test-unit/sample/tc_subtracter.rb +18 -0
- data/test-unit/sample/ts_examples.rb +7 -0
- data/test-unit/test/collector/test_descendant.rb +135 -0
- data/test-unit/test/collector/test_dir.rb +406 -0
- data/test-unit/test/collector/test_load.rb +333 -0
- data/test-unit/test/collector/test_objectspace.rb +98 -0
- data/test-unit/test/run-test.rb +13 -0
- data/test-unit/test/test_assertions.rb +693 -0
- data/test-unit/test/test_attribute.rb +86 -0
- data/{test-unit-ext → test-unit}/test/test_color.rb +3 -5
- data/{test-unit-ext → test-unit}/test/test_diff.rb +18 -16
- data/test-unit/test/test_emacs_runner.rb +60 -0
- data/test-unit/test/test_error.rb +26 -0
- data/test-unit/test/test_failure.rb +33 -0
- data/test-unit/test/test_fixture.rb +275 -0
- data/{test-unit-ext → test-unit}/test/test_notification.rb +7 -6
- data/test-unit/test/test_omission.rb +81 -0
- data/{test-unit-ext → test-unit}/test/test_pending.rb +15 -15
- data/{test-unit-ext → test-unit}/test/test_priority.rb +4 -3
- data/test-unit/test/test_testcase.rb +411 -0
- data/test-unit/test/test_testresult.rb +113 -0
- data/test-unit/test/test_testsuite.rb +129 -0
- data/test-unit/test/testunit_test_util.rb +12 -0
- data/test-unit/test/ui/test_testrunmediator.rb +20 -0
- data/test-unit/test/util/test_backtracefilter.rb +41 -0
- data/test-unit/test/util/test_observable.rb +102 -0
- data/test-unit/test/util/test_procwrapper.rb +36 -0
- data/test/al-test-utils.rb +4 -4
- data/test/command.rb +1 -1
- data/test/run-test.rb +5 -4
- data/test/test_associations.rb +143 -9
- data/test/test_base.rb +25 -1
- data/test/test_dn.rb +2 -0
- data/test/test_find.rb +8 -1
- data/test/test_ldif.rb +51 -114
- data/test/test_reflection.rb +4 -8
- data/test/test_usermod-lang-add.rb +2 -1
- data/test/test_validation.rb +4 -3
- metadata +76 -31
- data/test-unit-ext/NEWS.en +0 -28
- data/test-unit-ext/NEWS.ja +0 -28
- data/test-unit-ext/README.en +0 -247
- data/test-unit-ext/README.ja +0 -246
- data/test-unit-ext/Rakefile +0 -111
- data/test-unit-ext/lib/test-unit-ext.rb +0 -16
- data/test-unit-ext/lib/test-unit-ext/always-show-result.rb +0 -28
- data/test-unit-ext/lib/test-unit-ext/assertions.rb +0 -40
- data/test-unit-ext/lib/test-unit-ext/attributes.rb +0 -129
- data/test-unit-ext/lib/test-unit-ext/backtrace-filter.rb +0 -17
- data/test-unit-ext/lib/test-unit-ext/color.rb +0 -59
- data/test-unit-ext/lib/test-unit-ext/colorized-runner.rb +0 -111
- data/test-unit-ext/lib/test-unit-ext/diff.rb +0 -516
- data/test-unit-ext/lib/test-unit-ext/long-display-for-emacs.rb +0 -25
- data/test-unit-ext/lib/test-unit-ext/notification.rb +0 -79
- data/test-unit-ext/lib/test-unit-ext/omission.rb +0 -96
- data/test-unit-ext/lib/test-unit-ext/pending.rb +0 -97
- data/test-unit-ext/lib/test-unit-ext/priority.rb +0 -158
- data/test-unit-ext/lib/test-unit-ext/version.rb +0 -3
- data/test-unit-ext/lib/test-unit-ext/xml-report.rb +0 -224
- data/test-unit-ext/test/run-test.rb +0 -14
- data/test-unit-ext/test/test_attributes.rb +0 -139
- data/test-unit-ext/test/test_omission.rb +0 -64
- data/test-unit-ext/test/test_xml_report.rb +0 -161
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
require 'test/unit/util/backtracefilter'
|
|
2
|
-
|
|
3
|
-
module Test
|
|
4
|
-
module Unit
|
|
5
|
-
module Util
|
|
6
|
-
module BacktraceFilter
|
|
7
|
-
TEST_UNIT_EXT_PREFIX = File.dirname(__FILE__)
|
|
8
|
-
|
|
9
|
-
alias_method :original_filter_backtrace, :filter_backtrace
|
|
10
|
-
def filter_backtrace(backtrace, prefix=nil)
|
|
11
|
-
original_result = original_filter_backtrace(backtrace, prefix)
|
|
12
|
-
original_filter_backtrace(original_result, TEST_UNIT_EXT_PREFIX)
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
end
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
module Test
|
|
2
|
-
class Color
|
|
3
|
-
NAMES = ["black", "red", "green", "yellow",
|
|
4
|
-
"blue", "magenta", "cyan", "white"]
|
|
5
|
-
def initialize(name, options={})
|
|
6
|
-
@name = name
|
|
7
|
-
@foreground = options[:foreground]
|
|
8
|
-
@foreground = true if @foreground.nil?
|
|
9
|
-
@intensity = options[:intensity]
|
|
10
|
-
@bold = options[:bold]
|
|
11
|
-
@italic = options[:italic]
|
|
12
|
-
@underline = options[:underline]
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
def sequence
|
|
16
|
-
sequence = []
|
|
17
|
-
if @name == "none"
|
|
18
|
-
elsif @name == "reset"
|
|
19
|
-
sequence << "0"
|
|
20
|
-
else
|
|
21
|
-
foreground_parameter = @foreground ? 3 : 4
|
|
22
|
-
foreground_parameter += 6 if @intensity
|
|
23
|
-
sequence << "#{foreground_parameter}#{NAMES.index(@name)}"
|
|
24
|
-
end
|
|
25
|
-
sequence << "1" if @bold
|
|
26
|
-
sequence << "3" if @italic
|
|
27
|
-
sequence << "4" if @underline
|
|
28
|
-
sequence
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
def escape_sequence
|
|
32
|
-
"\e[#{sequence.join(';')}m"
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
def +(other)
|
|
36
|
-
MixColor.new([self, other])
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
class MixColor
|
|
41
|
-
def initialize(colors)
|
|
42
|
-
@colors = colors
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
def sequence
|
|
46
|
-
@colors.inject([]) do |result, color|
|
|
47
|
-
result + color.sequence
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
def escape_sequence
|
|
52
|
-
"\e[#{sequence.join(';')}m"
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
def +(other)
|
|
56
|
-
self.class.new([self, other])
|
|
57
|
-
end
|
|
58
|
-
end
|
|
59
|
-
end
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
require "test/unit/ui/console/testrunner"
|
|
2
|
-
|
|
3
|
-
module Test
|
|
4
|
-
module Unit
|
|
5
|
-
module UI
|
|
6
|
-
module Console
|
|
7
|
-
class ColorizedTestRunner < TestRunner
|
|
8
|
-
extend TestRunnerUtilities
|
|
9
|
-
|
|
10
|
-
SCHEMES = {
|
|
11
|
-
:default => {
|
|
12
|
-
"success" => Color.new("green", :bold => true),
|
|
13
|
-
"failure" => Color.new("red", :bold => true),
|
|
14
|
-
"pending" => Color.new("magenta", :bold => true),
|
|
15
|
-
"omission" => Color.new("blue", :bold => true),
|
|
16
|
-
"notification" => Color.new("cyan", :bold => true),
|
|
17
|
-
"error" => Color.new("yellow", :bold => true),
|
|
18
|
-
},
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
def initialize(suite, output_level=NORMAL, io=STDOUT)
|
|
22
|
-
super
|
|
23
|
-
@use_color = guess_color_availability
|
|
24
|
-
@color_scheme = SCHEMES[:default]
|
|
25
|
-
@reset_color = Color.new("reset")
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
private
|
|
29
|
-
def add_fault(fault)
|
|
30
|
-
@faults << fault
|
|
31
|
-
output_single_with_color(fault.single_character_display,
|
|
32
|
-
fault_color(fault),
|
|
33
|
-
PROGRESS_ONLY)
|
|
34
|
-
@already_outputted = true
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
def test_finished(name)
|
|
38
|
-
unless @already_outputted
|
|
39
|
-
output_single_with_color(".",
|
|
40
|
-
@color_scheme["success"],
|
|
41
|
-
PROGRESS_ONLY)
|
|
42
|
-
end
|
|
43
|
-
nl(VERBOSE)
|
|
44
|
-
@already_outputted = false
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
def finished(elapsed_time)
|
|
48
|
-
nl
|
|
49
|
-
output("Finished in #{elapsed_time} seconds.")
|
|
50
|
-
@faults.each_with_index do |fault, index|
|
|
51
|
-
nl
|
|
52
|
-
output_single("%3d) " % (index + 1))
|
|
53
|
-
output_with_color(fault.long_display, fault_color(fault))
|
|
54
|
-
end
|
|
55
|
-
nl
|
|
56
|
-
output_with_color(@result.to_s, result_color)
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
def fault_color(fault)
|
|
60
|
-
@color_scheme[fault.class.name.split(/::/).last.downcase]
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
def result_color
|
|
64
|
-
if @result.passed?
|
|
65
|
-
if @result.pending_count > 0
|
|
66
|
-
@color_scheme["pending"]
|
|
67
|
-
elsif @result.notification_count > 0
|
|
68
|
-
@color_scheme["notification"]
|
|
69
|
-
else
|
|
70
|
-
@color_scheme["success"]
|
|
71
|
-
end
|
|
72
|
-
elsif @result.error_count > 0
|
|
73
|
-
@color_scheme["error"]
|
|
74
|
-
elsif @result.failure_count > 0
|
|
75
|
-
@color_scheme["failure"]
|
|
76
|
-
end
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
def output_with_color(message, color=nil, level=NORMAL)
|
|
80
|
-
return unless output?(level)
|
|
81
|
-
output_single_with_color(message, color, level)
|
|
82
|
-
@io.puts
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
def output_single_with_color(message, color=nil, level=NORMAL)
|
|
86
|
-
return unless output?(level)
|
|
87
|
-
if @use_color and color
|
|
88
|
-
message = "%s%s%s" % [color.escape_sequence,
|
|
89
|
-
message,
|
|
90
|
-
@reset_color.escape_sequence]
|
|
91
|
-
end
|
|
92
|
-
@io.write(message)
|
|
93
|
-
@io.flush
|
|
94
|
-
end
|
|
95
|
-
|
|
96
|
-
def guess_color_availability
|
|
97
|
-
return false unless @io.tty?
|
|
98
|
-
term = ENV["TERM"]
|
|
99
|
-
return true if term and (/term\z/ =~ term or term == "screen")
|
|
100
|
-
return true if ENV["EMACS"] == "t"
|
|
101
|
-
false
|
|
102
|
-
end
|
|
103
|
-
end
|
|
104
|
-
end
|
|
105
|
-
end
|
|
106
|
-
|
|
107
|
-
AutoRunner::RUNNERS[:console] = Proc.new do
|
|
108
|
-
Test::Unit::UI::Console::ColorizedTestRunner
|
|
109
|
-
end
|
|
110
|
-
end
|
|
111
|
-
end
|
|
@@ -1,516 +0,0 @@
|
|
|
1
|
-
# port of Python's difflib.
|
|
2
|
-
|
|
3
|
-
module Test
|
|
4
|
-
module Diff
|
|
5
|
-
class SequenceMatcher
|
|
6
|
-
def initialize(from, to, &junk_predicate)
|
|
7
|
-
@from = from
|
|
8
|
-
@to = to
|
|
9
|
-
@junk_predicate = junk_predicate
|
|
10
|
-
update_to_indexes
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def longest_match(from_start, from_end, to_start, to_end)
|
|
14
|
-
best_info = find_best_match_position(from_start, from_end,
|
|
15
|
-
to_start, to_end)
|
|
16
|
-
unless @junks.empty?
|
|
17
|
-
args = [from_start, from_end, to_start, to_end]
|
|
18
|
-
best_info = adjust_best_info_with_junk_predicate(false, best_info,
|
|
19
|
-
*args)
|
|
20
|
-
best_info = adjust_best_info_with_junk_predicate(true, best_info,
|
|
21
|
-
*args)
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
best_info
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
def blocks
|
|
28
|
-
@blocks ||= compute_blocks
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
def operations
|
|
32
|
-
@operations ||= compute_operations
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
def grouped_operations(context_size=nil)
|
|
36
|
-
context_size ||= 3
|
|
37
|
-
_operations = operations
|
|
38
|
-
_operations = [[:equal, 0, 0, 0, 0]] if _operations.empty?
|
|
39
|
-
expand_edge_equal_operations!(_operations, context_size)
|
|
40
|
-
|
|
41
|
-
group_window = context_size * 2
|
|
42
|
-
groups = []
|
|
43
|
-
group = []
|
|
44
|
-
_operations.each do |tag, from_start, from_end, to_start, to_end|
|
|
45
|
-
if tag == :equal and from_end - from_start > group_window
|
|
46
|
-
group << [tag,
|
|
47
|
-
from_start,
|
|
48
|
-
[from_end, from_start + context_size].min,
|
|
49
|
-
to_start,
|
|
50
|
-
[to_end, to_start + context_size].min]
|
|
51
|
-
groups << group
|
|
52
|
-
group = []
|
|
53
|
-
from_start = [from_start, from_end - context_size].max
|
|
54
|
-
to_start = [to_start, to_end - context_size].max
|
|
55
|
-
end
|
|
56
|
-
group << [tag, from_start, from_end, to_start, to_end]
|
|
57
|
-
end
|
|
58
|
-
groups << group unless group.empty?
|
|
59
|
-
groups
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
def ratio
|
|
63
|
-
@ratio ||= compute_ratio
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
private
|
|
67
|
-
def update_to_indexes
|
|
68
|
-
@to_indexes = {}
|
|
69
|
-
@junks = {}
|
|
70
|
-
each = @to.is_a?(String) ? :each_byte : :each
|
|
71
|
-
i = 0
|
|
72
|
-
@to.send(each) do |item|
|
|
73
|
-
@to_indexes[item] ||= []
|
|
74
|
-
@to_indexes[item] << i
|
|
75
|
-
i += 1
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
return if @junk_predicate.nil?
|
|
79
|
-
@to_indexes = @to_indexes.reject do |key, value|
|
|
80
|
-
junk = @junk_predicate.call(key)
|
|
81
|
-
@junks[key] = true if junk
|
|
82
|
-
junk
|
|
83
|
-
end
|
|
84
|
-
end
|
|
85
|
-
|
|
86
|
-
def find_best_match_position(from_start, from_end, to_start, to_end)
|
|
87
|
-
best_from, best_to, best_size = from_start, to_start, 0
|
|
88
|
-
sizes = {}
|
|
89
|
-
from_start.upto(from_end) do |from_index|
|
|
90
|
-
_sizes = {}
|
|
91
|
-
(@to_indexes[@from[from_index]] || []).each do |to_index|
|
|
92
|
-
next if to_index < to_start
|
|
93
|
-
break if to_index > to_end
|
|
94
|
-
size = _sizes[to_index] = (sizes[to_index - 1] || 0) + 1
|
|
95
|
-
if size > best_size
|
|
96
|
-
best_from = from_index - size + 1
|
|
97
|
-
best_to = to_index - size + 1
|
|
98
|
-
best_size = size
|
|
99
|
-
end
|
|
100
|
-
end
|
|
101
|
-
sizes = _sizes
|
|
102
|
-
end
|
|
103
|
-
[best_from, best_to, best_size]
|
|
104
|
-
end
|
|
105
|
-
|
|
106
|
-
def adjust_best_info_with_junk_predicate(should_junk, best_info,
|
|
107
|
-
from_start, from_end,
|
|
108
|
-
to_start, to_end)
|
|
109
|
-
best_from, best_to, best_size = best_info
|
|
110
|
-
while best_from > from_start and best_to > to_start and
|
|
111
|
-
(should_junk ?
|
|
112
|
-
@junks.has_key?(@to[best_to - 1]) :
|
|
113
|
-
!@junks.has_key?(@to[best_to - 1])) and
|
|
114
|
-
@from[best_from - 1] == @to[best_to - 1]
|
|
115
|
-
best_from -= 1
|
|
116
|
-
best_to -= 1
|
|
117
|
-
best_size += 1
|
|
118
|
-
end
|
|
119
|
-
|
|
120
|
-
while best_from + best_size < from_end and
|
|
121
|
-
best_to + best_size < to_end and
|
|
122
|
-
(should_junk ?
|
|
123
|
-
@junks.has_key?(@to[best_to + best_size]) :
|
|
124
|
-
!@junks.has_key?(@to[best_to + best_size])) and
|
|
125
|
-
@from[best_from + best_size] == @to[best_to + best_size]
|
|
126
|
-
best_size += 1
|
|
127
|
-
end
|
|
128
|
-
|
|
129
|
-
[best_from, best_to, best_size]
|
|
130
|
-
end
|
|
131
|
-
|
|
132
|
-
def matches
|
|
133
|
-
@matches ||= compute_matches
|
|
134
|
-
end
|
|
135
|
-
|
|
136
|
-
def compute_matches
|
|
137
|
-
matches = []
|
|
138
|
-
queue = [[0, @from.size, 0, @to.size]]
|
|
139
|
-
until queue.empty?
|
|
140
|
-
from_start, from_end, to_start, to_end = queue.pop
|
|
141
|
-
match = longest_match(from_start, from_end - 1, to_start, to_end - 1)
|
|
142
|
-
match_from_index, match_to_index, size = match
|
|
143
|
-
unless size.zero?
|
|
144
|
-
if from_start < match_from_index and
|
|
145
|
-
to_start < match_to_index
|
|
146
|
-
queue.push([from_start, match_from_index,
|
|
147
|
-
to_start, match_to_index])
|
|
148
|
-
end
|
|
149
|
-
matches << match
|
|
150
|
-
if match_from_index + size < from_end and
|
|
151
|
-
match_to_index + size < to_end
|
|
152
|
-
queue.push([match_from_index + size, from_end,
|
|
153
|
-
match_to_index + size, to_end])
|
|
154
|
-
end
|
|
155
|
-
end
|
|
156
|
-
end
|
|
157
|
-
matches.sort_by do |(from_index, to_index, match_size)|
|
|
158
|
-
from_index
|
|
159
|
-
end
|
|
160
|
-
end
|
|
161
|
-
|
|
162
|
-
def compute_blocks
|
|
163
|
-
blocks = []
|
|
164
|
-
current_from_index = current_to_index = current_size = 0
|
|
165
|
-
matches.each do |from_index, to_index, size|
|
|
166
|
-
if current_from_index + current_size == from_index and
|
|
167
|
-
current_to_index + current_size == to_index
|
|
168
|
-
current_size += size
|
|
169
|
-
else
|
|
170
|
-
unless current_size.zero?
|
|
171
|
-
blocks << [current_from_index, current_to_index, current_size]
|
|
172
|
-
end
|
|
173
|
-
current_from_index = from_index
|
|
174
|
-
current_to_index = to_index
|
|
175
|
-
current_size = size
|
|
176
|
-
end
|
|
177
|
-
end
|
|
178
|
-
unless current_size.zero?
|
|
179
|
-
blocks << [current_from_index, current_to_index, current_size]
|
|
180
|
-
end
|
|
181
|
-
|
|
182
|
-
blocks << [@from.size, @to.size, 0]
|
|
183
|
-
blocks
|
|
184
|
-
end
|
|
185
|
-
|
|
186
|
-
def compute_operations
|
|
187
|
-
from_index = to_index = 0
|
|
188
|
-
operations = []
|
|
189
|
-
blocks.each do |match_from_index, match_to_index, size|
|
|
190
|
-
tag = determine_tag(from_index, to_index,
|
|
191
|
-
match_from_index, match_to_index)
|
|
192
|
-
if tag != :equal
|
|
193
|
-
operations << [tag,
|
|
194
|
-
from_index, match_from_index,
|
|
195
|
-
to_index, match_to_index]
|
|
196
|
-
end
|
|
197
|
-
|
|
198
|
-
from_index, to_index = match_from_index + size, match_to_index + size
|
|
199
|
-
if size > 0
|
|
200
|
-
operations << [:equal,
|
|
201
|
-
match_from_index, from_index,
|
|
202
|
-
match_to_index, to_index]
|
|
203
|
-
end
|
|
204
|
-
end
|
|
205
|
-
operations
|
|
206
|
-
end
|
|
207
|
-
|
|
208
|
-
def compute_ratio
|
|
209
|
-
matches = blocks.inject(0) {|result, block| result + block[-1]}
|
|
210
|
-
length = @from.length + @to.length
|
|
211
|
-
if length.zero?
|
|
212
|
-
1.0
|
|
213
|
-
else
|
|
214
|
-
2.0 * matches / length
|
|
215
|
-
end
|
|
216
|
-
end
|
|
217
|
-
|
|
218
|
-
def determine_tag(from_index, to_index,
|
|
219
|
-
match_from_index, match_to_index)
|
|
220
|
-
if from_index < match_from_index and to_index < match_to_index
|
|
221
|
-
:replace
|
|
222
|
-
elsif from_index < match_from_index
|
|
223
|
-
:delete
|
|
224
|
-
elsif to_index < match_to_index
|
|
225
|
-
:insert
|
|
226
|
-
else
|
|
227
|
-
:equal
|
|
228
|
-
end
|
|
229
|
-
end
|
|
230
|
-
|
|
231
|
-
def expand_edge_equal_operations!(_operations, context_size)
|
|
232
|
-
tag, from_start, from_end, to_start, to_end = _operations[0]
|
|
233
|
-
if tag == :equal
|
|
234
|
-
_operations[0] = [tag,
|
|
235
|
-
[from_start, from_end - context_size].max,
|
|
236
|
-
from_end,
|
|
237
|
-
[to_start, to_end - context_size].max,
|
|
238
|
-
to_end]
|
|
239
|
-
end
|
|
240
|
-
|
|
241
|
-
tag, from_start, from_end, to_start, to_end = _operations[-1]
|
|
242
|
-
if tag == :equal
|
|
243
|
-
_operations[-1] = [tag,
|
|
244
|
-
from_start,
|
|
245
|
-
[from_end, from_start + context_size].min,
|
|
246
|
-
to_start,
|
|
247
|
-
[to_end, to_start + context_size].min]
|
|
248
|
-
end
|
|
249
|
-
end
|
|
250
|
-
end
|
|
251
|
-
|
|
252
|
-
class Differ
|
|
253
|
-
def initialize(from, to)
|
|
254
|
-
@from = from
|
|
255
|
-
@to = to
|
|
256
|
-
end
|
|
257
|
-
|
|
258
|
-
private
|
|
259
|
-
def tag(mark, contents)
|
|
260
|
-
contents.collect {|content| "#{mark}#{content}"}
|
|
261
|
-
end
|
|
262
|
-
end
|
|
263
|
-
|
|
264
|
-
class ReadableDiffer < Differ
|
|
265
|
-
def diff(options={})
|
|
266
|
-
result = []
|
|
267
|
-
matcher = SequenceMatcher.new(@from, @to)
|
|
268
|
-
matcher.operations.each do |args|
|
|
269
|
-
tag, from_start, from_end, to_start, to_end = args
|
|
270
|
-
case tag
|
|
271
|
-
when :replace
|
|
272
|
-
result.concat(diff_lines(from_start, from_end, to_start, to_end))
|
|
273
|
-
when :delete
|
|
274
|
-
result.concat(tag_deleted(@from[from_start...from_end]))
|
|
275
|
-
when :insert
|
|
276
|
-
result.concat(tag_inserted(@to[to_start...to_end]))
|
|
277
|
-
when :equal
|
|
278
|
-
result.concat(tag_equal(@from[from_start...from_end]))
|
|
279
|
-
else
|
|
280
|
-
raise "unknown tag: #{tag}"
|
|
281
|
-
end
|
|
282
|
-
end
|
|
283
|
-
result
|
|
284
|
-
end
|
|
285
|
-
|
|
286
|
-
private
|
|
287
|
-
def tag_deleted(contents)
|
|
288
|
-
tag("- ", contents)
|
|
289
|
-
end
|
|
290
|
-
|
|
291
|
-
def tag_inserted(contents)
|
|
292
|
-
tag("+ ", contents)
|
|
293
|
-
end
|
|
294
|
-
|
|
295
|
-
def tag_equal(contents)
|
|
296
|
-
tag(" ", contents)
|
|
297
|
-
end
|
|
298
|
-
|
|
299
|
-
def tag_difference(contents)
|
|
300
|
-
tag("? ", contents)
|
|
301
|
-
end
|
|
302
|
-
|
|
303
|
-
def find_diff_line_info(from_start, from_end, to_start, to_end)
|
|
304
|
-
best_ratio = 0.74
|
|
305
|
-
from_equal_index = to_equal_index = nil
|
|
306
|
-
from_best_index = to_best_index = nil
|
|
307
|
-
|
|
308
|
-
to_start.upto(to_end - 1) do |to_index|
|
|
309
|
-
from_start.upto(from_end - 1) do |from_index|
|
|
310
|
-
if @from[from_index] == @to[to_index]
|
|
311
|
-
from_equal_index ||= from_index
|
|
312
|
-
to_equal_index ||= to_index
|
|
313
|
-
next
|
|
314
|
-
end
|
|
315
|
-
|
|
316
|
-
matcher = SequenceMatcher.new(@from[from_index], @to[to_index],
|
|
317
|
-
&method(:space_character?))
|
|
318
|
-
if matcher.ratio > best_ratio
|
|
319
|
-
best_ratio = matcher.ratio
|
|
320
|
-
from_best_index = from_index
|
|
321
|
-
to_best_index = to_index
|
|
322
|
-
end
|
|
323
|
-
end
|
|
324
|
-
end
|
|
325
|
-
|
|
326
|
-
[best_ratio,
|
|
327
|
-
from_equal_index, to_equal_index,
|
|
328
|
-
from_best_index, to_best_index]
|
|
329
|
-
end
|
|
330
|
-
|
|
331
|
-
def diff_lines(from_start, from_end, to_start, to_end)
|
|
332
|
-
cut_off = 0.75
|
|
333
|
-
|
|
334
|
-
info = find_diff_line_info(from_start, from_end, to_start, to_end)
|
|
335
|
-
best_ratio, from_equal_index, to_equal_index, *info = info
|
|
336
|
-
from_best_index, to_best_index = info
|
|
337
|
-
|
|
338
|
-
if best_ratio < cut_off
|
|
339
|
-
if from_equal_index.nil?
|
|
340
|
-
tagged_from = tag_deleted(@from[from_start...from_end])
|
|
341
|
-
tagged_to = tag_inserted(@to[to_start...to_end])
|
|
342
|
-
if to_end - to_start < from_end - from_start
|
|
343
|
-
return tagged_to + tagged_from
|
|
344
|
-
else
|
|
345
|
-
return tagged_from + tagged_to
|
|
346
|
-
end
|
|
347
|
-
end
|
|
348
|
-
from_best_index = from_equal_index
|
|
349
|
-
to_best_index = to_equal_index
|
|
350
|
-
best_ratio = 1.0
|
|
351
|
-
end
|
|
352
|
-
|
|
353
|
-
_diff_lines(from_start, from_best_index, to_start, to_best_index) +
|
|
354
|
-
diff_line(@from[from_best_index], @to[to_best_index]) +
|
|
355
|
-
_diff_lines(from_best_index + 1, from_end, to_best_index + 1, to_end)
|
|
356
|
-
end
|
|
357
|
-
|
|
358
|
-
def _diff_lines(from_start, from_end, to_start, to_end)
|
|
359
|
-
if from_start < from_end
|
|
360
|
-
if to_start < to_end
|
|
361
|
-
diff_lines(from_start, from_end, to_start, to_end)
|
|
362
|
-
else
|
|
363
|
-
tag_deleted(@from[from_start...from_end])
|
|
364
|
-
end
|
|
365
|
-
else
|
|
366
|
-
tag_inserted(@to[to_start...to_end])
|
|
367
|
-
end
|
|
368
|
-
end
|
|
369
|
-
|
|
370
|
-
def diff_line(from_line, to_line)
|
|
371
|
-
from_tags = ""
|
|
372
|
-
to_tags = ""
|
|
373
|
-
matcher = SequenceMatcher.new(from_line, to_line,
|
|
374
|
-
&method(:space_character?))
|
|
375
|
-
matcher.operations.each do |tag, from_start, from_end, to_start, to_end|
|
|
376
|
-
from_length = from_end - from_start
|
|
377
|
-
to_length = to_end - to_start
|
|
378
|
-
case tag
|
|
379
|
-
when :replace
|
|
380
|
-
from_tags << "^" * from_length
|
|
381
|
-
to_tags << "^" * to_length
|
|
382
|
-
when :delete
|
|
383
|
-
from_tags << "-" * from_length
|
|
384
|
-
when :insert
|
|
385
|
-
to_tags << "+" * to_length
|
|
386
|
-
when :equal
|
|
387
|
-
from_tags << " " * from_length
|
|
388
|
-
to_tags << " " * to_length
|
|
389
|
-
else
|
|
390
|
-
raise "unknown tag: #{tag}"
|
|
391
|
-
end
|
|
392
|
-
end
|
|
393
|
-
format_diff_point(from_line, to_line, from_tags, to_tags)
|
|
394
|
-
end
|
|
395
|
-
|
|
396
|
-
def format_diff_point(from_line, to_line, from_tags, to_tags)
|
|
397
|
-
common = [n_leading_characters(from_line, ?\t),
|
|
398
|
-
n_leading_characters(to_line, ?\t)].min
|
|
399
|
-
common = [common, n_leading_characters(from_tags[0, common], " "[0])].min
|
|
400
|
-
from_tags = from_tags[common..-1].rstrip
|
|
401
|
-
to_tags = to_tags[common..-1].rstrip
|
|
402
|
-
|
|
403
|
-
result = tag_deleted([from_line])
|
|
404
|
-
unless from_tags.empty?
|
|
405
|
-
result.concat(tag_difference(["#{"\t" * common}#{from_tags}"]))
|
|
406
|
-
end
|
|
407
|
-
result.concat(tag_inserted([to_line]))
|
|
408
|
-
unless to_tags.empty?
|
|
409
|
-
result.concat(tag_difference(["#{"\t" * common}#{to_tags}"]))
|
|
410
|
-
end
|
|
411
|
-
result
|
|
412
|
-
end
|
|
413
|
-
|
|
414
|
-
def n_leading_characters(string, character)
|
|
415
|
-
n = 0
|
|
416
|
-
while string[n] == character
|
|
417
|
-
n += 1
|
|
418
|
-
end
|
|
419
|
-
n
|
|
420
|
-
end
|
|
421
|
-
|
|
422
|
-
def space_character?(character)
|
|
423
|
-
[" "[0], "\t"[0]].include?(character)
|
|
424
|
-
end
|
|
425
|
-
end
|
|
426
|
-
|
|
427
|
-
class UnifiedDiffer < Differ
|
|
428
|
-
def diff(options={})
|
|
429
|
-
groups = SequenceMatcher.new(@from, @to).grouped_operations
|
|
430
|
-
return [] if groups.empty?
|
|
431
|
-
return [] if same_content?(groups)
|
|
432
|
-
|
|
433
|
-
show_context = options[:show_context]
|
|
434
|
-
show_context = true if show_context.nil?
|
|
435
|
-
result = ["--- #{options[:from_label]}".rstrip,
|
|
436
|
-
"+++ #{options[:to_label]}".rstrip]
|
|
437
|
-
groups.each do |operations|
|
|
438
|
-
result << format_summary(operations, show_context)
|
|
439
|
-
operations.each do |args|
|
|
440
|
-
operation_tag, from_start, from_end, to_start, to_end = args
|
|
441
|
-
case operation_tag
|
|
442
|
-
when :replace
|
|
443
|
-
result.concat(tag("-", @from[from_start...from_end]))
|
|
444
|
-
result.concat(tag("+", @to[to_start...to_end]))
|
|
445
|
-
when :delete
|
|
446
|
-
result.concat(tag("-", @from[from_start...from_end]))
|
|
447
|
-
when :insert
|
|
448
|
-
result.concat(tag("+", @to[to_start...to_end]))
|
|
449
|
-
when :equal
|
|
450
|
-
result.concat(tag(" ", @from[from_start...from_end]))
|
|
451
|
-
end
|
|
452
|
-
end
|
|
453
|
-
end
|
|
454
|
-
result
|
|
455
|
-
end
|
|
456
|
-
|
|
457
|
-
private
|
|
458
|
-
def same_content?(groups)
|
|
459
|
-
return false if groups.size != 1
|
|
460
|
-
group = groups[0]
|
|
461
|
-
return false if group.size != 1
|
|
462
|
-
tag, from_start, from_end, to_start, to_end = group[0]
|
|
463
|
-
|
|
464
|
-
tag == :equal and [from_start, from_end] == [to_start, to_end]
|
|
465
|
-
end
|
|
466
|
-
|
|
467
|
-
def format_summary(operations, show_context)
|
|
468
|
-
_, first_from_start, _, first_to_start, _ = operations[0]
|
|
469
|
-
_, _, last_from_end, _, last_to_end = operations[-1]
|
|
470
|
-
summary = "@@ -%d,%d +%d,%d @@" % [first_from_start + 1,
|
|
471
|
-
last_from_end - first_from_start,
|
|
472
|
-
first_to_start + 1,
|
|
473
|
-
last_to_end - first_to_start,]
|
|
474
|
-
if show_context
|
|
475
|
-
interesting_line = find_interesting_line(first_from_start,
|
|
476
|
-
first_to_start,
|
|
477
|
-
:define_line?)
|
|
478
|
-
summary << " #{interesting_line}" if interesting_line
|
|
479
|
-
end
|
|
480
|
-
summary
|
|
481
|
-
end
|
|
482
|
-
|
|
483
|
-
def find_interesting_line(from_start, to_start, predicate)
|
|
484
|
-
from_index = from_start
|
|
485
|
-
to_index = to_start
|
|
486
|
-
while from_index >= 0 or to_index >= 0
|
|
487
|
-
[@from[from_index], @to[to_index]].each do |line|
|
|
488
|
-
return line if line and send(predicate, line)
|
|
489
|
-
end
|
|
490
|
-
|
|
491
|
-
from_index -= 1
|
|
492
|
-
to_index -= 1
|
|
493
|
-
end
|
|
494
|
-
nil
|
|
495
|
-
end
|
|
496
|
-
|
|
497
|
-
def define_line?(line)
|
|
498
|
-
/\A(?:[_a-zA-Z$]|\s*(?:class|module|def)\b)/ =~ line
|
|
499
|
-
end
|
|
500
|
-
end
|
|
501
|
-
|
|
502
|
-
module_function
|
|
503
|
-
def readable(from, to, options={})
|
|
504
|
-
diff(ReadableDiffer, from, to, options)
|
|
505
|
-
end
|
|
506
|
-
|
|
507
|
-
def unified(from, to, options={})
|
|
508
|
-
diff(UnifiedDiffer, from, to, options)
|
|
509
|
-
end
|
|
510
|
-
|
|
511
|
-
def diff(differ_class, from, to, options={})
|
|
512
|
-
differ = differ_class.new(from.split(/\r?\n/), to.split(/\r?\n/))
|
|
513
|
-
differ.diff(options).join("\n")
|
|
514
|
-
end
|
|
515
|
-
end
|
|
516
|
-
end
|