comparison test/unit/lib/redmine/unified_diff_test.rb @ 524:1248a47e81b3 feature_36

Merge from branch "luisf"
author luisf <luis.figueira@eecs.qmul.ac.uk>
date Mon, 25 Jul 2011 14:39:38 +0100
parents cbce1fd3b1b7
children cbb26bc654de
comparison
equal deleted inserted replaced
519:3be6bc3c2a17 524:1248a47e81b3
1 # Redmine - project management software 1 # Redmine - project management software
2 # Copyright (C) 2006-2008 Jean-Philippe Lang 2 # Copyright (C) 2006-2011 Jean-Philippe Lang
3 # 3 #
4 # This program is free software; you can redistribute it and/or 4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License 5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2 6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version. 7 # of the License, or (at your option) any later version.
13 # 13 #
14 # You should have received a copy of the GNU General Public License 14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software 15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 require File.dirname(__FILE__) + '/../../../test_helper' 18 require File.expand_path('../../../../test_helper', __FILE__)
19 19
20 class Redmine::UnifiedDiffTest < ActiveSupport::TestCase 20 class Redmine::UnifiedDiffTest < ActiveSupport::TestCase
21 21
22 def setup 22 def setup
23 end 23 end
30 end 30 end
31 31
32 def test_truncate_diff 32 def test_truncate_diff
33 diff = Redmine::UnifiedDiff.new(read_diff_fixture('subversion.diff'), :max_lines => 20) 33 diff = Redmine::UnifiedDiff.new(read_diff_fixture('subversion.diff'), :max_lines => 20)
34 assert_equal 2, diff.size 34 assert_equal 2, diff.size
35 end
36
37 def test_inline_partials
38 diff = Redmine::UnifiedDiff.new(read_diff_fixture('partials.diff'))
39 assert_equal 1, diff.size
40 diff = diff.first
41 assert_equal 43, diff.size
42
43 assert_equal [51, -1], diff[0].offsets
44 assert_equal [51, -1], diff[1].offsets
45 assert_equal 'Lorem ipsum dolor sit amet, consectetur adipiscing <span>elit</span>', diff[0].html_line
46 assert_equal 'Lorem ipsum dolor sit amet, consectetur adipiscing <span>xx</span>', diff[1].html_line
47
48 assert_nil diff[2].offsets
49 assert_equal 'Praesent et sagittis dui. Vivamus ac diam diam', diff[2].html_line
50
51 assert_equal [0, -14], diff[3].offsets
52 assert_equal [0, -14], diff[4].offsets
53 assert_equal '<span>Ut sed</span> auctor justo', diff[3].html_line
54 assert_equal '<span>xxx</span> auctor justo', diff[4].html_line
55
56 assert_equal [13, -19], diff[6].offsets
57 assert_equal [13, -19], diff[7].offsets
58
59 assert_equal [24, -8], diff[9].offsets
60 assert_equal [24, -8], diff[10].offsets
61
62 assert_equal [37, -1], diff[12].offsets
63 assert_equal [37, -1], diff[13].offsets
64
65 assert_equal [0, -38], diff[15].offsets
66 assert_equal [0, -38], diff[16].offsets
67 end
68
69 def test_side_by_side_partials
70 diff = Redmine::UnifiedDiff.new(read_diff_fixture('partials.diff'), :type => 'sbs')
71 assert_equal 1, diff.size
72 diff = diff.first
73 assert_equal 32, diff.size
74
75 assert_equal [51, -1], diff[0].offsets
76 assert_equal 'Lorem ipsum dolor sit amet, consectetur adipiscing <span>elit</span>', diff[0].html_line_left
77 assert_equal 'Lorem ipsum dolor sit amet, consectetur adipiscing <span>xx</span>', diff[0].html_line_right
78
79 assert_nil diff[1].offsets
80 assert_equal 'Praesent et sagittis dui. Vivamus ac diam diam', diff[1].html_line_left
81 assert_equal 'Praesent et sagittis dui. Vivamus ac diam diam', diff[1].html_line_right
82
83 assert_equal [0, -14], diff[2].offsets
84 assert_equal '<span>Ut sed</span> auctor justo', diff[2].html_line_left
85 assert_equal '<span>xxx</span> auctor justo', diff[2].html_line_right
86
87 assert_equal [13, -19], diff[4].offsets
88 assert_equal [24, -8], diff[6].offsets
89 assert_equal [37, -1], diff[8].offsets
90 assert_equal [0, -38], diff[10].offsets
91
35 end 92 end
36 93
37 def test_line_starting_with_dashes 94 def test_line_starting_with_dashes
38 diff = Redmine::UnifiedDiff.new(<<-DIFF 95 diff = Redmine::UnifiedDiff.new(<<-DIFF
39 --- old.txt Wed Nov 11 14:24:58 2009 96 --- old.txt Wed Nov 11 14:24:58 2009
58 DIFF 115 DIFF
59 ) 116 )
60 assert_equal 1, diff.size 117 assert_equal 1, diff.size
61 end 118 end
62 119
120 def test_one_line_new_files
121 diff = Redmine::UnifiedDiff.new(<<-DIFF
122 diff -r 000000000000 -r ea98b14f75f0 README1
123 --- /dev/null
124 +++ b/README1
125 @@ -0,0 +1,1 @@
126 +test1
127 diff -r 000000000000 -r ea98b14f75f0 README2
128 --- /dev/null
129 +++ b/README2
130 @@ -0,0 +1,1 @@
131 +test2
132 diff -r 000000000000 -r ea98b14f75f0 README3
133 --- /dev/null
134 +++ b/README3
135 @@ -0,0 +1,3 @@
136 +test4
137 +test5
138 +test6
139 diff -r 000000000000 -r ea98b14f75f0 README4
140 --- /dev/null
141 +++ b/README4
142 @@ -0,0 +1,3 @@
143 +test4
144 +test5
145 +test6
146 DIFF
147 )
148 assert_equal 4, diff.size
149 end
150
63 private 151 private
64 152
65 def read_diff_fixture(filename) 153 def read_diff_fixture(filename)
66 File.new(File.join(File.dirname(__FILE__), '/../../../fixtures/diffs', filename)).read 154 File.new(File.join(File.dirname(__FILE__), '/../../../fixtures/diffs', filename)).read
67 end 155 end
68 end 156 end