pretty_diff 0.9.3 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +41 -6
- data/Rakefile +0 -1
- data/VERSION +1 -1
- data/lib/pretty_diff.rb +5 -6
- data/lib/pretty_diff/abstract_generator.rb +51 -0
- data/lib/pretty_diff/basic_generator.rb +72 -0
- data/lib/pretty_diff/chunk.rb +24 -41
- data/lib/pretty_diff/diff.rb +75 -41
- data/lib/pretty_diff/encoding.rb +30 -0
- data/lib/pretty_diff/line.rb +30 -51
- data/lib/pretty_diff/line_numbers.rb +47 -67
- data/pretty_diff.gemspec +33 -18
- data/test/abstract_generator_test.rb +65 -0
- data/test/basic_generator_test.rb +29 -0
- data/test/chunk_test.rb +13 -30
- data/test/diff_test.rb +50 -19
- data/test/encoding_test.rb +35 -0
- data/test/fixtures/blank.diff +0 -0
- data/test/fixtures/blank.diff.html +1 -0
- data/test/fixtures/chinese-gbk-crlf +5 -0
- data/test/fixtures/cp1251.diff +13 -0
- data/test/fixtures/csharp.diff +12 -0
- data/test/fixtures/csharp.diff.html +19 -0
- data/test/{data → fixtures}/first.diff +0 -0
- data/test/fixtures/first.diff.html +85 -0
- data/test/{data → fixtures}/second.diff +0 -0
- data/test/fixtures/single_line.diff +7 -0
- data/test/fixtures/single_line.diff.html +4 -0
- data/test/fixtures/text.diff +8 -0
- data/test/fixtures/text.diff.html +13 -0
- data/test/fixtures/windows-cp1251-lf +6 -0
- data/test/helper.rb +10 -8
- data/test/line_numbers_test.rb +25 -0
- data/test/line_test.rb +26 -37
- metadata +81 -75
- data/lib/pretty_diff/html_generators/chunk_generator.rb +0 -41
- data/lib/pretty_diff/html_generators/diff_generator.rb +0 -13
- data/lib/pretty_diff/html_generators/line_generator.rb +0 -45
- data/lib/pretty_diff/html_generators/line_numbers_generator.rb +0 -36
- data/test/html_generator_test.rb +0 -39
data/test/diff_test.rb
CHANGED
@@ -1,29 +1,60 @@
|
|
1
|
-
require File.dirname(__FILE__)
|
2
|
-
require 'cgi'
|
1
|
+
require File.join(File.dirname(__FILE__), 'helper')
|
3
2
|
|
4
|
-
class DiffTest <
|
5
|
-
|
3
|
+
class DiffTest < MiniTest::Unit::TestCase
|
4
|
+
class SuperGenerator < PrettyDiff::AbstractGenerator; def generate;end; end
|
5
|
+
class UberGenerator < SuperGenerator; end
|
6
6
|
|
7
|
-
|
8
|
-
@small_diff = PrettyDiff::Diff.new read_diff('first.diff')
|
9
|
-
@big_diff = PrettyDiff::Diff.new read_diff('second.diff')
|
10
|
-
end
|
7
|
+
class NotAGenerator; end
|
11
8
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
end
|
9
|
+
def setup
|
10
|
+
@diff = new_diff(fixture('first.diff'))
|
11
|
+
end
|
16
12
|
|
17
|
-
|
18
|
-
|
19
|
-
|
13
|
+
def test_chunks
|
14
|
+
assert_equal 2, @diff.chunks.size
|
15
|
+
@diff.chunks.each do |c|
|
16
|
+
assert c.kind_of?(PrettyDiff::Chunk)
|
20
17
|
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_metadata
|
21
|
+
assert_equal "--- Revision 1945\n+++ Revision 1995\n", @diff.metadata
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_contents
|
25
|
+
assert_equal 32, @diff.contents.lines.size
|
26
|
+
assert_equal "@@ -8,6 +8,10 @@\n", @diff.contents.lines.first
|
27
|
+
assert_equal " }\n", @diff.contents.lines.last
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_default_generator
|
31
|
+
assert_equal 'PrettyDiff::BasicGenerator', new_diff('bla').generator.to_s
|
32
|
+
end
|
21
33
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
34
|
+
def test_custom_generator
|
35
|
+
assert_equal 'DiffTest::SuperGenerator', new_diff('bla', :generator => SuperGenerator).generator.to_s
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_invalid_custom_generator
|
39
|
+
assert_raises PrettyDiff::InvalidGenerator do
|
40
|
+
new_diff('bla', :generator => NotAGenerator)
|
26
41
|
end
|
27
42
|
|
43
|
+
assert new_diff('bla', :generator => UberGenerator)
|
28
44
|
end
|
45
|
+
|
46
|
+
def test_default_encoding
|
47
|
+
assert_equal 'utf-8', new_diff('bla').out_encoding.downcase
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_custom_encoding
|
51
|
+
assert_equal 'cp1251', new_diff('bla', :out_encoding => 'cp1251').out_encoding
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_encoding_cp1251_diff
|
55
|
+
diff = new_diff(fixture('cp1251.diff'))
|
56
|
+
assert_equal 1, diff.chunks.size
|
57
|
+
assert diff.contents.include?('Сенат США')
|
58
|
+
end
|
59
|
+
|
29
60
|
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'helper')
|
2
|
+
|
3
|
+
class EncodingTest < MiniTest::Unit::TestCase
|
4
|
+
|
5
|
+
def test_detect
|
6
|
+
assert_equal 'windows-1251', enc.detect(fixture('windows-cp1251-lf'))
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_convert_cp1251_to_utf8
|
10
|
+
text = enc.convert(fixture('windows-cp1251-lf'), 'windows-1251', 'utf-8')
|
11
|
+
assert text.include?('Сенат США')
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_keep_utf8
|
15
|
+
text = enc.convert('Вася молодец', 'utf-8', 'utf-8')
|
16
|
+
assert_equal 'Вася молодец', text
|
17
|
+
end
|
18
|
+
|
19
|
+
if RUBY_VERSION >= '2.0.0'
|
20
|
+
def test_force_encoding_on_ruby2
|
21
|
+
text = enc.enforce('utf-8', fixture('windows-cp1251-lf'))
|
22
|
+
assert_equal 'utf-8', text.encoding.to_s.downcase
|
23
|
+
|
24
|
+
text = enc.enforce('windows-1251', fixture('windows-cp1251-lf'))
|
25
|
+
assert_equal 'windows-1251', text.encoding.to_s.downcase
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def enc
|
32
|
+
PrettyDiff::Encoding
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
<div class="diff"></div>
|
@@ -0,0 +1,13 @@
|
|
1
|
+
diff --git a/windows-cp1251-lf b/windows-cp1251-lf
|
2
|
+
deleted file mode 100644
|
3
|
+
index 9604f79..0000000
|
4
|
+
--- a/windows-cp1251-lf
|
5
|
+
+++ /dev/null
|
6
|
+
@@ -1,6 +0,0 @@
|
7
|
+
-����� ��� 10 ������ �������� �� ���� �������� ���������� ��� �����������
|
8
|
+
-����� ������, ���������� � ������������ ���������� REI, ������� ����������
|
9
|
+
-�������� ���������� �������. �� ����� �������� ���������� ��� ����� ������
|
10
|
+
-������� ���� ��������, ������� ���������� ������������ � 2009 ����.
|
11
|
+
-
|
12
|
+
-Windows CP1251 LF
|
13
|
+
|
@@ -0,0 +1,12 @@
|
|
1
|
+
diff --git a/src/Data/ServiceMail/ServiceEmailBase.cs b/src/Data/ServiceMail/ServiceEmailBase.cs
|
2
|
+
index a93dedb..5cb1240 100644
|
3
|
+
--- a/src/Data/ServiceMail/ServiceEmailBase.cs
|
4
|
+
+++ b/src/Data/ServiceMail/ServiceEmailBase.cs
|
5
|
+
@@ -21,7 +21,7 @@ namespace PostalService.Data.ServiceMail
|
6
|
+
public abstract string GenerateSubject();
|
7
|
+
public abstract string GenerateTextBody();
|
8
|
+
public abstract string GenerateHtmlBody();
|
9
|
+
- public abstract string GenerateTag();
|
10
|
+
+ public abstract string GenerateTag(); change on line 24
|
11
|
+
|
12
|
+
private readonly SystemSettings _systemSettings;
|
@@ -0,0 +1,19 @@
|
|
1
|
+
<div class="diff"><div class="diff-chunk"><div class="diff-line-nums"><pre>21
|
2
|
+
22
|
3
|
+
23
|
4
|
+
24
|
5
|
+
|
6
|
+
25
|
7
|
+
26</pre></div><div class="diff-line-nums"><pre>21
|
8
|
+
22
|
9
|
+
23
|
10
|
+
|
11
|
+
24
|
12
|
+
25
|
13
|
+
26</pre></div><div class="diff-code"><pre> public abstract string GenerateSubject();
|
14
|
+
public abstract string GenerateTextBody();
|
15
|
+
public abstract string GenerateHtmlBody();
|
16
|
+
<span class="diff-line-del">- public abstract string GenerateTag();</span>
|
17
|
+
<span class="diff-line-add">+ public abstract string GenerateTag(); change on line 24</span>
|
18
|
+
|
19
|
+
private readonly SystemSettings _systemSettings;</pre></div></div></div>
|
File without changes
|
@@ -0,0 +1,85 @@
|
|
1
|
+
<div class="diff"><div class="diff-chunk"><div class="diff-line-nums"><pre>8
|
2
|
+
9
|
3
|
+
10
|
4
|
+
|
5
|
+
|
6
|
+
|
7
|
+
|
8
|
+
11
|
9
|
+
12
|
10
|
+
13</pre></div><div class="diff-line-nums"><pre>8
|
11
|
+
9
|
12
|
+
10
|
13
|
+
11
|
14
|
+
12
|
15
|
+
13
|
16
|
+
14
|
17
|
+
15
|
18
|
+
16
|
19
|
+
17</pre></div><div class="diff-code"><pre> border: 0;
|
20
|
+
}
|
21
|
+
|
22
|
+
<span class="diff-line-add">+.sep {</span>
|
23
|
+
<span class="diff-line-add">+ color: #AAA;</span>
|
24
|
+
<span class="diff-line-add">+}</span>
|
25
|
+
<span class="diff-line-add">+</span>
|
26
|
+
/* Short statistic */
|
27
|
+
|
28
|
+
.short-stat dl {</pre></div></div><div class="diff-chunk"><div class="diff-line-nums"><pre>59
|
29
|
+
60
|
30
|
+
61
|
31
|
+
62
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
|
38
|
+
63
|
39
|
+
64
|
40
|
+
65
|
41
|
+
66
|
42
|
+
67
|
43
|
+
|
44
|
+
|
45
|
+
68
|
46
|
+
69
|
47
|
+
70</pre></div><div class="diff-line-nums"><pre>63
|
48
|
+
64
|
49
|
+
65
|
50
|
+
|
51
|
+
66
|
52
|
+
67
|
53
|
+
68
|
54
|
+
69
|
55
|
+
70
|
56
|
+
71
|
57
|
+
72
|
58
|
+
73
|
59
|
+
74
|
60
|
+
75
|
61
|
+
|
62
|
+
76
|
63
|
+
77
|
64
|
+
78
|
65
|
+
79
|
66
|
+
80</pre></div><div class="diff-code"><pre> color: #999;
|
67
|
+
}
|
68
|
+
|
69
|
+
<span class="diff-line-del">- table.account-overview td .status {</span>
|
70
|
+
<span class="diff-line-add">+ table.account-overview td.label.top {</span>
|
71
|
+
<span class="diff-line-add">+ vertical-align: top;</span>
|
72
|
+
<span class="diff-line-add">+ }</span>
|
73
|
+
<span class="diff-line-add">+ </span>
|
74
|
+
<span class="diff-line-add">+ table.account-overview td .status,</span>
|
75
|
+
<span class="diff-line-add">+ table.repos-table td .status {</span>
|
76
|
+
padding-left: 1.75em;
|
77
|
+
background: url(../images/i_error_light.gif) 0 0 no-repeat;
|
78
|
+
}
|
79
|
+
|
80
|
+
<span class="diff-line-del">- table.account-overview td .status.active {</span>
|
81
|
+
<span class="diff-line-add">+ table.account-overview td .status.active,</span>
|
82
|
+
<span class="diff-line-add">+ table.repos-table td .status.success {</span>
|
83
|
+
padding-left: 1.75em;
|
84
|
+
background: url(../images/i-yes.gif) 0 0 no-repeat;
|
85
|
+
}</pre></div></div></div>
|
File without changes
|
@@ -0,0 +1,4 @@
|
|
1
|
+
<div class="diff"><div class="diff-chunk"><div class="diff-line-nums"><pre>1
|
2
|
+
</pre></div><div class="diff-line-nums"><pre>
|
3
|
+
1</pre></div><div class="diff-code"><pre><span class="diff-line-del">-assome example text</span>
|
4
|
+
<span class="diff-line-add">+asassome example text</span></pre></div></div></div>
|
@@ -0,0 +1,13 @@
|
|
1
|
+
<div class="diff"><div class="diff-chunk"><div class="diff-line-nums"><pre>3
|
2
|
+
4
|
3
|
+
5
|
4
|
+
6
|
5
|
+
</pre></div><div class="diff-line-nums"><pre>3
|
6
|
+
4
|
7
|
+
5
|
8
|
+
|
9
|
+
6</pre></div><div class="diff-code"><pre> line3
|
10
|
+
line4 new
|
11
|
+
line5
|
12
|
+
<span class="diff-line-del">-line6 change seleniunm</span>
|
13
|
+
<span class="diff-line-add">+line6 change</span></pre></div></div></div>
|
@@ -0,0 +1,6 @@
|
|
1
|
+
����� ��� 10 ������ �������� �� ���� �������� ���������� ��� �����������
|
2
|
+
����� ������, ���������� � ������������ ���������� REI, ������� ����������
|
3
|
+
�������� ���������� �������. �� ����� �������� ���������� ��� ����� ������
|
4
|
+
������� ���� ��������, ������� ���������� ������������ � 2009 ����.
|
5
|
+
|
6
|
+
Windows CP1251 LF
|
data/test/helper.rb
CHANGED
@@ -1,15 +1,17 @@
|
|
1
1
|
require 'rubygems'
|
2
|
-
require '
|
3
|
-
require '
|
2
|
+
require 'bundler/setup'
|
3
|
+
require 'minitest/autorun'
|
4
4
|
|
5
|
-
|
6
|
-
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
7
|
-
require 'pretty_diff'
|
5
|
+
require File.join(File.dirname(__FILE__), '..', 'lib', 'pretty_diff')
|
8
6
|
|
9
|
-
class
|
7
|
+
class MiniTest::Unit::TestCase
|
10
8
|
|
11
|
-
def
|
12
|
-
|
9
|
+
def new_diff(*args)
|
10
|
+
PrettyDiff::Diff.new(*args)
|
11
|
+
end
|
12
|
+
|
13
|
+
def fixture(name)
|
14
|
+
File.read(File.join(File.dirname(__FILE__), "fixtures", name))
|
13
15
|
end
|
14
16
|
|
15
17
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class LineNumbersTest < MiniTest::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
@diff = new_diff(fixture('first.diff'))
|
7
|
+
@numbers = @diff.chunks.last.line_numbers
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_left_column
|
11
|
+
assert_equal [59, 60, 61, 62, nil, nil, nil, nil, nil, nil, 63, 64, 65, 66, 67, nil, nil, 68, 69, 70],
|
12
|
+
@numbers.left_column
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_right_column
|
16
|
+
assert_equal [63, 64, 65, nil, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, nil, 76, 77, 78, 79, 80],
|
17
|
+
@numbers.right_column
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_line_numbers
|
21
|
+
@diff = new_diff fixture('single_line.diff')
|
22
|
+
assert_equal [1, nil], @diff.chunks.last.line_numbers.left_column
|
23
|
+
assert_equal [nil, 1], @diff.chunks.last.line_numbers.right_column
|
24
|
+
end
|
25
|
+
end
|
data/test/line_test.rb
CHANGED
@@ -1,45 +1,34 @@
|
|
1
|
-
require File.dirname(__FILE__)
|
2
|
-
|
3
|
-
class LineTest < Test::Unit::TestCase
|
4
|
-
context "PrettyDiff's Line" do
|
5
|
-
|
6
|
-
should "indicate :added status correctly" do
|
7
|
-
added_line = new_diff("+package chiro.methods.new.ones;")
|
8
|
-
assert_equal :added, added_line.status
|
9
|
-
end
|
10
|
-
|
11
|
-
should "indicate :deleted status correctly" do
|
12
|
-
deleted_line = new_diff('-browser.setTimeout("50000");')
|
13
|
-
assert_equal :deleted, deleted_line.status
|
14
|
-
end
|
15
|
-
|
16
|
-
should "indicate :not_modified status correctly" do
|
17
|
-
not_modified_line = new_diff("class User < ActiveRecord::Base")
|
18
|
-
assert_equal :not_modified, not_modified_line.status
|
19
|
-
end
|
20
|
-
|
21
|
-
should "ignore trailing 'no newline' text" do
|
22
|
-
text = ''
|
23
|
-
line = new_diff(text)
|
24
|
-
assert line.ignore?
|
25
|
-
end
|
26
|
-
|
27
|
-
should "replace tabs with spaces" do
|
28
|
-
text = " hello eptut {1, 2, 3}"
|
29
|
-
expected_output = " hello eptut {1, 2, 3}"
|
30
|
-
line = new_diff(text)
|
31
|
-
assert_equal expected_output, line.rendered
|
32
|
-
end
|
1
|
+
require File.join(File.dirname(__FILE__), 'helper')
|
33
2
|
|
3
|
+
class LineTest < MiniTest::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
@diff = new_diff(fixture('first.diff'))
|
7
|
+
@lines = @diff.chunks.last.lines
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_contents
|
11
|
+
assert_equal " color: #999;", @lines[0].contents
|
12
|
+
assert_equal "- table.account-overview td .status {", @lines[3].contents
|
13
|
+
assert_equal "+ table.account-overview td.label.top {", @lines[4].contents
|
14
|
+
assert_equal " }", @lines.last.contents
|
34
15
|
end
|
35
16
|
|
36
|
-
|
17
|
+
def test_ignored
|
18
|
+
line = PrettyDiff::Line.new(@diff, '')
|
19
|
+
assert line.ignored?
|
20
|
+
end
|
37
21
|
|
38
|
-
def
|
39
|
-
|
22
|
+
def test_status_added
|
23
|
+
assert_equal :added, @lines[4].status
|
40
24
|
end
|
41
25
|
|
42
|
-
def
|
43
|
-
|
26
|
+
def test_status_deleted
|
27
|
+
assert_equal :deleted, @lines[3].status
|
44
28
|
end
|
29
|
+
|
30
|
+
def test_status_not_modified
|
31
|
+
assert_equal :not_modified, @lines[0].status
|
32
|
+
end
|
33
|
+
|
45
34
|
end
|