diff-display 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -0
- data/History.txt +4 -0
- data/License.txt +21 -0
- data/Manifest.txt +26 -0
- data/README.txt +58 -0
- data/Rakefile +48 -0
- data/doc/.gitignore +0 -0
- data/lib/diff-display.rb +14 -0
- data/lib/diff/display/data_structure.rb +193 -0
- data/lib/diff/display/unified.rb +15 -0
- data/lib/diff/display/unified/generator.rb +210 -0
- data/lib/diff/display/version.rb +11 -0
- data/lib/diff/renderer/base.rb +90 -0
- data/lib/diff/renderer/diff.rb +29 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/script/txt2html +74 -0
- data/setup.rb +1585 -0
- data/test/fixtures/big.diff +590 -0
- data/test/fixtures/multiple_adds_after_rem.diff +11 -0
- data/test/fixtures/multiple_rems_then_add.diff +14 -0
- data/test/fixtures/only_add.diff +4 -0
- data/test/fixtures/only_rem.diff +4 -0
- data/test/fixtures/pseudo_recursive.diff +21 -0
- data/test/fixtures/simple.diff +12 -0
- data/test/fixtures/simple_oneliner.diff +7 -0
- data/test/fixtures/simple_rewrite.diff +8 -0
- data/test/test_api.rb +12 -0
- data/test/test_base_renderer.rb +101 -0
- data/test/test_datastructure.rb +100 -0
- data/test/test_diff_renderer.rb +14 -0
- data/test/test_generator.rb +148 -0
- data/test/test_helper.rb +25 -0
- data/test/test_unified.rb +22 -0
- metadata +123 -0
@@ -0,0 +1,14 @@
|
|
1
|
+
diff --git a/strokedb-ruby/lib/stores/chainable_storage.rb b/strokedb-ruby/lib/stores/chainable_storage.rb
|
2
|
+
index 5326c92..1e2de8f 100644
|
3
|
+
--- a/strokedb-ruby/lib/stores/chainable_storage.rb
|
4
|
+
+++ b/strokedb-ruby/lib/stores/chainable_storage.rb
|
5
|
+
@@ -44,9 +44,7 @@ module StrokeDB
|
6
|
+
def save_with_chained_storages!(chunk,source=nil)
|
7
|
+
perform_save!(chunk)
|
8
|
+
(@chained_storages||{}).each_pair do |storage,savings|
|
9
|
+
- unless storage == chunk
|
10
|
+
- savings << chunk unless savings.include?(chunk)
|
11
|
+
- end
|
12
|
+
+ savings << chunk unless storage == chunk || savings.include?(chunk)
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
diff --git a/spec/fixtures/multiple_rems_then_add.diff b/spec/fixtures/multiple_rems_then_add.diff
|
2
|
+
new file mode 100644
|
3
|
+
index 0000000..f5fd3f8
|
4
|
+
--- /dev/null
|
5
|
+
+++ b/spec/fixtures/multiple_rems_then_add.diff
|
6
|
+
@@ -0,0 +1,14 @@
|
7
|
+
+diff --git a/strokedb-ruby/lib/stores/chainable_storage.rb b/strokedb-ruby/lib/stores/chainable_storage.rb
|
8
|
+
+index 5326c92..1e2de8f 100644
|
9
|
+
+--- a/strokedb-ruby/lib/stores/chainable_storage.rb
|
10
|
+
++++ b/strokedb-ruby/lib/stores/chainable_storage.rb
|
11
|
+
+@@ -44,9 +44,7 @@ module StrokeDB
|
12
|
+
+ def save_with_chained_storages!(chunk,source=nil)
|
13
|
+
+ perform_save!(chunk)
|
14
|
+
+ (@chained_storages||{}).each_pair do |storage,savings|
|
15
|
+
+- unless storage == chunk
|
16
|
+
+- savings << chunk unless savings.include?(chunk)
|
17
|
+
+- end
|
18
|
+
++ savings << chunk unless storage == chunk || savings.include?(chunk)
|
19
|
+
+ end
|
20
|
+
+ end
|
21
|
+
|
@@ -0,0 +1,12 @@
|
|
1
|
+
diff --git a/History.txt b/History.txt
|
2
|
+
index 0ed7358..622c384 100644
|
3
|
+
--- a/History.txt
|
4
|
+
+++ b/History.txt
|
5
|
+
@@ -1,4 +1,5 @@
|
6
|
+
== 0.0.1 2008-01-28
|
7
|
+
|
8
|
+
-* 1 major enhancement:
|
9
|
+
- * Initial release
|
10
|
+
+* 2 major enhancements:
|
11
|
+
+ * The Initial release
|
12
|
+
+ * stuff added
|
data/test/test_api.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require File.dirname(__FILE__) + "/test_helper"
|
4
|
+
|
5
|
+
class TestApi < Test::Unit::TestCase
|
6
|
+
include DiffFixtureHelper
|
7
|
+
|
8
|
+
def test_it_has_a_simple_API
|
9
|
+
diff = Diff::Display::Unified.new(load_diff("simple"))
|
10
|
+
diff.render(Diff::Renderer::Base.new)
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,101 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require File.dirname(__FILE__) + "/test_helper"
|
4
|
+
|
5
|
+
class TestBaseRenderer < Test::Unit::TestCase
|
6
|
+
include DiffFixtureHelper
|
7
|
+
|
8
|
+
def setup
|
9
|
+
@data = Diff::Display::Unified::Generator.run(load_diff("big"))
|
10
|
+
@base_renderer = Diff::Renderer::Base.new
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_it_classifies_a_classname
|
14
|
+
assert_equal "remblock", @base_renderer.send(:classify, Diff::Display::RemBlock.new)
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_it_calls_the_before_headerblock
|
18
|
+
@base_renderer.expects(:before_headerblock).at_least_once
|
19
|
+
@base_renderer.render(@data)
|
20
|
+
end
|
21
|
+
|
22
|
+
# def test_it_calls_the_before_sepblock
|
23
|
+
# @base_renderer.expects(:before_sepblock).at_least_once
|
24
|
+
# @base_renderer.render(@data)
|
25
|
+
# end
|
26
|
+
|
27
|
+
# def test_it_calls_the_before_modblock
|
28
|
+
# @base_renderer.expects(:before_modblock).at_least_once
|
29
|
+
# @base_renderer.render(@data)
|
30
|
+
# end
|
31
|
+
|
32
|
+
def test_calls_the_before_unmodblock
|
33
|
+
@base_renderer.expects(:before_unmodblock).at_least_once
|
34
|
+
@base_renderer.render(@data)
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_should_calls_the_before_addblock
|
38
|
+
@base_renderer.expects(:before_addblock).at_least_once
|
39
|
+
@base_renderer.render(@data)
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_calls_the_before_remblock
|
43
|
+
@base_renderer.expects(:before_remblock).at_least_once
|
44
|
+
@base_renderer.render(@data)
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_calls_headerline
|
48
|
+
@base_renderer.expects(:headerline).at_least_once
|
49
|
+
@base_renderer.render(@data)
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_calls_unmodline
|
53
|
+
@base_renderer.expects(:unmodline).at_least_once
|
54
|
+
@base_renderer.render(@data)
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_calls_addline
|
58
|
+
@base_renderer.expects(:addline).at_least_once
|
59
|
+
@base_renderer.render(@data)
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_calls_remline
|
63
|
+
@base_renderer.expects(:remline).at_least_once
|
64
|
+
@base_renderer.render(@data)
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_calls_the_after_headerblock
|
68
|
+
@base_renderer.expects(:after_headerblock).at_least_once
|
69
|
+
@base_renderer.render(@data)
|
70
|
+
end
|
71
|
+
|
72
|
+
# def test_calls_the_after_sepblock
|
73
|
+
# @base_renderer.expects(:after_sepblock).at_least_once
|
74
|
+
# @base_renderer.render(@data)
|
75
|
+
# end
|
76
|
+
|
77
|
+
# def test_calls_the_after_modblock
|
78
|
+
# @base_renderer.expects(:after_modblock).at_least_once
|
79
|
+
# @base_renderer.render(@data)
|
80
|
+
# end
|
81
|
+
|
82
|
+
def test_calls_the_after_unmodblock
|
83
|
+
@base_renderer.expects(:after_unmodblock).at_least_once
|
84
|
+
@base_renderer.render(@data)
|
85
|
+
end
|
86
|
+
|
87
|
+
def test_calls_the_after_addblock
|
88
|
+
@base_renderer.expects(:after_addblock).at_least_once
|
89
|
+
@base_renderer.render(@data)
|
90
|
+
end
|
91
|
+
|
92
|
+
def test_calls_the_after_remblock
|
93
|
+
@base_renderer.expects(:after_remblock).at_least_once
|
94
|
+
@base_renderer.render(@data)
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_renders_a_basic_datastructure
|
98
|
+
output = @base_renderer.render(@data)
|
99
|
+
assert_not_equal nil, output
|
100
|
+
end
|
101
|
+
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require File.dirname(__FILE__) + "/test_helper"
|
4
|
+
|
5
|
+
class TestDatastructure < Test::Unit::TestCase
|
6
|
+
include DiffFixtureHelper
|
7
|
+
|
8
|
+
# Data
|
9
|
+
def test_behaves_like_an_array
|
10
|
+
data = Diff::Display::Data.new
|
11
|
+
data << "foo"
|
12
|
+
data.push "bar"
|
13
|
+
assert_equal ["foo", "bar"], data
|
14
|
+
end
|
15
|
+
|
16
|
+
# Line
|
17
|
+
def test_initializes_with_an_old_line_number
|
18
|
+
line = Diff::Display::Line.new("foo", 12)
|
19
|
+
assert_equal 12, line.old_number
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_initializes_with_numbers
|
23
|
+
line = Diff::Display::Line.new("foo", 12, 13)
|
24
|
+
assert_equal 12, line.old_number
|
25
|
+
assert_equal 13, line.new_number
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_has_a_class_method_for_creating_an_addline
|
29
|
+
line = Diff::Display::Line.add("foo", 7)
|
30
|
+
assert_instance_of Diff::Display::AddLine, line
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_has_a_class_method_for_creating_a_remline
|
34
|
+
line = Diff::Display::Line.rem("foo", 7)
|
35
|
+
assert_instance_of Diff::Display::RemLine, line
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_has_a_class_method_for_creating_a_unmodline
|
39
|
+
line = Diff::Display::Line.unmod("foo", 7, 8)
|
40
|
+
assert_instance_of Diff::Display::UnModLine, line
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_has_a_class_method_for_creating_a_header_line
|
44
|
+
line = Diff::Display::Line.header("foo")
|
45
|
+
assert_instance_of Diff::Display::HeaderLine, line
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_has_an_identifier
|
49
|
+
assert_equal :add, Diff::Display::Line.add("foo", 7).identifier
|
50
|
+
assert_equal :rem, Diff::Display::Line.rem("foo", 7).identifier
|
51
|
+
assert_equal :unmod, Diff::Display::Line.unmod("foo", 7, 8).identifier
|
52
|
+
assert_equal :header, Diff::Display::Line.header("foo").identifier
|
53
|
+
assert_equal :nonewline, Diff::Display::Line.nonewline("foo").identifier
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_expands_inline_changes
|
57
|
+
line = Diff::Display::AddLine.new('the \\0quick \\1brown fox', 42, true)
|
58
|
+
expanded = line.expand_inline_changes_with("START", "END")
|
59
|
+
assert_equal "the STARTquick ENDbrown fox", expanded.to_s
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_segments
|
63
|
+
line = Diff::Display::AddLine.new('the \\0quick \\1brown fox', 42, true)
|
64
|
+
assert_equal ["the ", "quick ", "brown fox"], line.segments
|
65
|
+
end
|
66
|
+
|
67
|
+
# Block
|
68
|
+
def test_block_behaves_like_an_array
|
69
|
+
block = Diff::Display::Block.new
|
70
|
+
block.push 1,2,3
|
71
|
+
assert_equal 3, block.size
|
72
|
+
assert_equal [1,2,3], block
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_has_class_method_for_creating_an_addblock
|
76
|
+
block = Diff::Display::Block.add
|
77
|
+
assert_instance_of Diff::Display::AddBlock, block
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_has_class_method_for_creating_an_remblock
|
81
|
+
block = Diff::Display::Block.rem
|
82
|
+
assert_instance_of Diff::Display::RemBlock, block
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_has_class_method_for_creating_an_modblock
|
86
|
+
block = Diff::Display::Block.mod
|
87
|
+
assert_instance_of Diff::Display::ModBlock, block
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_has_class_method_for_creating_an_unmodblock
|
91
|
+
block = Diff::Display::Block.unmod
|
92
|
+
assert_instance_of Diff::Display::UnModBlock, block
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_has_class_method_for_creating_an_headerblock
|
96
|
+
block = Diff::Display::Block.header
|
97
|
+
assert_instance_of Diff::Display::HeaderBlock, block
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require File.dirname(__FILE__) + "/test_helper"
|
4
|
+
|
5
|
+
class TestDiffRenderer < Test::Unit::TestCase
|
6
|
+
include DiffFixtureHelper
|
7
|
+
|
8
|
+
def test_it_renders_a_diff_back_to_its_original_state
|
9
|
+
data = Diff::Display::Unified::Generator.run(load_diff("simple"))
|
10
|
+
base_renderer = Diff::Renderer::Diff.new
|
11
|
+
assert_equal load_diff("simple"), base_renderer.render(data)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
@@ -0,0 +1,148 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require File.dirname(__FILE__) + "/test_helper"
|
4
|
+
|
5
|
+
class TestGenerator < Test::Unit::TestCase
|
6
|
+
include DiffFixtureHelper
|
7
|
+
|
8
|
+
def setup
|
9
|
+
@generator = Diff::Display::Unified::Generator.new
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_generator_run_raises_if_doesnt_get_a_enumerable_object
|
13
|
+
assert_raises(ArgumentError) do
|
14
|
+
Diff::Display::Unified::Generator.run(nil)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_generator_run_processes_each_line_in_the_diff
|
19
|
+
Diff::Display::Unified::Generator.expects(:new).returns(@generator)
|
20
|
+
@generator.expects(:process).with("foo")
|
21
|
+
@generator.expects(:process).with("bar")
|
22
|
+
Diff::Display::Unified::Generator.run("foo\nbar")
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_generator_run_returns_the_data
|
26
|
+
Diff::Display::Unified::Generator.expects(:new).returns(@generator)
|
27
|
+
generated = Diff::Display::Unified::Generator.run("foo\nbar")
|
28
|
+
assert_instance_of Diff::Display::Data, generated
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_the_returned_that_object_is_in_parity_with_the_diff
|
32
|
+
%w[multiple_rems_then_add only_rem simple multiple_adds_after_rem only_add pseudo_recursive simple_oneliner].each do |diff|
|
33
|
+
data = Diff::Display::Unified::Generator.run(load_diff(diff))
|
34
|
+
assert_equal load_diff(diff).chomp, data.to_diff, "failed on #{diff}"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_big
|
39
|
+
diff_data = load_diff("big")
|
40
|
+
data = Diff::Display::Unified::Generator.run(diff_data)
|
41
|
+
assert_equal diff_data.chomp, data.to_diff
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_multiple_rems_and_an_add_is_in_parity
|
45
|
+
diff_data = load_diff("multiple_rems_then_add")
|
46
|
+
data = Diff::Display::Unified::Generator.run(diff_data)
|
47
|
+
assert_equal diff_data.chomp, data.to_diff
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_doesnt_parse_linenumbers_that_isnt_part_if_the_diff
|
51
|
+
range = 1..14
|
52
|
+
expected_lines = range.to_a.map{|l| [nil, l] }
|
53
|
+
assert_equal expected_lines, line_numbers_for(:pseudo_recursive).compact
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_parses_no_newline_at_end_of_file
|
57
|
+
diff_data = load_diff("pseudo_recursive")
|
58
|
+
data = Diff::Display::Unified::Generator.run(diff_data)
|
59
|
+
assert_equal diff_data.chomp, data.to_diff
|
60
|
+
assert_instance_of Diff::Display::NonewlineBlock, data.last
|
61
|
+
assert_equal 1, data.last.size
|
62
|
+
assert_instance_of Diff::Display::NonewlineLine, data.last[0]
|
63
|
+
assert_equal '\', data.last[0]
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_a_changed_string_becomes_a_modblock
|
67
|
+
diff_data = load_diff("simple_oneliner")
|
68
|
+
data = Diff::Display::Unified::Generator.run(diff_data)
|
69
|
+
|
70
|
+
assert_equal diff_data.chomp, data.to_diff
|
71
|
+
assert_equal 6, data.size
|
72
|
+
modblock = data[4]
|
73
|
+
assert_instance_of Diff::Display::ModBlock, modblock
|
74
|
+
assert_equal 2, modblock.size, modblock.inspect
|
75
|
+
|
76
|
+
rem = modblock[0]
|
77
|
+
add = modblock[1]
|
78
|
+
assert_instance_of Diff::Display::RemLine, rem
|
79
|
+
assert_instance_of Diff::Display::AddLine, add
|
80
|
+
assert add.inline_changes?
|
81
|
+
assert rem.inline_changes?
|
82
|
+
end
|
83
|
+
|
84
|
+
# line numbering
|
85
|
+
def test_numbers_correctly_for_multiple_adds_after_rem
|
86
|
+
expected = [
|
87
|
+
[193, 193],
|
88
|
+
[194, nil],
|
89
|
+
[nil, 194],
|
90
|
+
[nil, 195],
|
91
|
+
[nil, 196],
|
92
|
+
[nil, 197],
|
93
|
+
[nil, 198],
|
94
|
+
[195, 199]
|
95
|
+
]
|
96
|
+
assert_equal expected, line_numbers_for(:multiple_adds_after_rem)
|
97
|
+
end
|
98
|
+
|
99
|
+
def test_numbers_correctly_for_simple
|
100
|
+
expected = [
|
101
|
+
[1, 1],
|
102
|
+
[2, 2],
|
103
|
+
[3, nil],
|
104
|
+
[4, nil],
|
105
|
+
[nil, 3],
|
106
|
+
[nil, 4],
|
107
|
+
[nil, 5],
|
108
|
+
]
|
109
|
+
assert_equal expected, line_numbers_for(:simple)
|
110
|
+
end
|
111
|
+
|
112
|
+
def test_rewrite_line_does_not_set_inline_changes
|
113
|
+
diff_data = load_diff("simple_rewrite")
|
114
|
+
data = Diff::Display::Unified::Generator.run(diff_data)
|
115
|
+
|
116
|
+
assert_equal diff_data.chomp, data.to_diff
|
117
|
+
modblock = data[5]
|
118
|
+
assert_instance_of Diff::Display::ModBlock, modblock
|
119
|
+
|
120
|
+
assert_instance_of Diff::Display::RemLine, rem = modblock[0]
|
121
|
+
assert_instance_of Diff::Display::AddLine, add = modblock[1]
|
122
|
+
|
123
|
+
assert !rem.inline_changes?, "rem has inline changes"
|
124
|
+
assert !add.inline_changes?, "add has inline_changes"
|
125
|
+
end
|
126
|
+
|
127
|
+
def test_should_not_explode_on_invalid_byte_sequences
|
128
|
+
diff_data = "+s\x8B\xB5\x13\n"
|
129
|
+
assert_nothing_raised do
|
130
|
+
Diff::Display::Unified::Generator.run(diff_data)
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
protected
|
135
|
+
def line_numbers_for(diff)
|
136
|
+
diff_data = load_diff(diff)
|
137
|
+
data = Diff::Display::Unified::Generator.run(diff_data)
|
138
|
+
linenos = []
|
139
|
+
data.each do |blk|
|
140
|
+
blk.each do |line|
|
141
|
+
next if line.class == Diff::Display::HeaderLine
|
142
|
+
next if line.class == Diff::Display::NonewlineLine
|
143
|
+
linenos << [line.old_number, line.new_number]
|
144
|
+
end
|
145
|
+
end
|
146
|
+
linenos
|
147
|
+
end
|
148
|
+
end
|