##// END OF EJS Templates
Merged r8876 from trunk....
Jean-Philippe Lang -
r8990:90c6a8579bb4
parent child
Show More
@@ -1,258 +1,259
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2011 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.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
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 module Redmine
18 module Redmine
19 # Class used to parse unified diffs
19 # Class used to parse unified diffs
20 class UnifiedDiff < Array
20 class UnifiedDiff < Array
21 attr_reader :diff_type
21 attr_reader :diff_type
22
22
23 def initialize(diff, options={})
23 def initialize(diff, options={})
24 options.assert_valid_keys(:type, :max_lines)
24 options.assert_valid_keys(:type, :max_lines)
25 diff = diff.split("\n") if diff.is_a?(String)
25 diff = diff.split("\n") if diff.is_a?(String)
26 @diff_type = options[:type] || 'inline'
26 @diff_type = options[:type] || 'inline'
27 lines = 0
27 lines = 0
28 @truncated = false
28 @truncated = false
29 diff_table = DiffTable.new(@diff_type)
29 diff_table = DiffTable.new(@diff_type)
30 diff.each do |line|
30 diff.each do |line|
31 line_encoding = nil
31 line_encoding = nil
32 if line.respond_to?(:force_encoding)
32 if line.respond_to?(:force_encoding)
33 line_encoding = line.encoding
33 line_encoding = line.encoding
34 # TODO: UTF-16 and Japanese CP932 which is imcompatible with ASCII
34 # TODO: UTF-16 and Japanese CP932 which is imcompatible with ASCII
35 # In Japan, diffrence between file path encoding
35 # In Japan, diffrence between file path encoding
36 # and file contents encoding is popular.
36 # and file contents encoding is popular.
37 line.force_encoding('ASCII-8BIT')
37 line.force_encoding('ASCII-8BIT')
38 end
38 end
39 unless diff_table.add_line line
39 unless diff_table.add_line line
40 line.force_encoding(line_encoding) if line_encoding
40 line.force_encoding(line_encoding) if line_encoding
41 self << diff_table if diff_table.length > 0
41 self << diff_table if diff_table.length > 0
42 diff_table = DiffTable.new(diff_type)
42 diff_table = DiffTable.new(diff_type)
43 end
43 end
44 lines += 1
44 lines += 1
45 if options[:max_lines] && lines > options[:max_lines]
45 if options[:max_lines] && lines > options[:max_lines]
46 @truncated = true
46 @truncated = true
47 break
47 break
48 end
48 end
49 end
49 end
50 self << diff_table unless diff_table.empty?
50 self << diff_table unless diff_table.empty?
51 self
51 self
52 end
52 end
53
53
54 def truncated?; @truncated; end
54 def truncated?; @truncated; end
55 end
55 end
56
56
57 # Class that represents a file diff
57 # Class that represents a file diff
58 class DiffTable < Array
58 class DiffTable < Array
59 attr_reader :file_name
59 attr_reader :file_name
60
60
61 # Initialize with a Diff file and the type of Diff View
61 # Initialize with a Diff file and the type of Diff View
62 # The type view must be inline or sbs (side_by_side)
62 # The type view must be inline or sbs (side_by_side)
63 def initialize(type="inline")
63 def initialize(type="inline")
64 @parsing = false
64 @parsing = false
65 @added = 0
65 @added = 0
66 @removed = 0
66 @removed = 0
67 @type = type
67 @type = type
68 end
68 end
69
69
70 # Function for add a line of this Diff
70 # Function for add a line of this Diff
71 # Returns false when the diff ends
71 # Returns false when the diff ends
72 def add_line(line)
72 def add_line(line)
73 unless @parsing
73 unless @parsing
74 if line =~ /^(---|\+\+\+) (.*)$/
74 if line =~ /^(---|\+\+\+) (.*)$/
75 @file_name = $2
75 @file_name = $2
76 elsif line =~ /^@@ (\+|\-)(\d+)(,\d+)? (\+|\-)(\d+)(,\d+)? @@/
76 elsif line =~ /^@@ (\+|\-)(\d+)(,\d+)? (\+|\-)(\d+)(,\d+)? @@/
77 @line_num_l = $2.to_i
77 @line_num_l = $2.to_i
78 @line_num_r = $5.to_i
78 @line_num_r = $5.to_i
79 @parsing = true
79 @parsing = true
80 end
80 end
81 else
81 else
82 if line =~ /^[^\+\-\s@\\]/
82 if line =~ /^[^\+\-\s@\\]/
83 @parsing = false
83 @parsing = false
84 return false
84 return false
85 elsif line =~ /^@@ (\+|\-)(\d+)(,\d+)? (\+|\-)(\d+)(,\d+)? @@/
85 elsif line =~ /^@@ (\+|\-)(\d+)(,\d+)? (\+|\-)(\d+)(,\d+)? @@/
86 @line_num_l = $2.to_i
86 @line_num_l = $2.to_i
87 @line_num_r = $5.to_i
87 @line_num_r = $5.to_i
88 else
88 else
89 parse_line(line, @type)
89 parse_line(line, @type)
90 end
90 end
91 end
91 end
92 return true
92 return true
93 end
93 end
94
94
95 def each_line
95 def each_line
96 prev_line_left, prev_line_right = nil, nil
96 prev_line_left, prev_line_right = nil, nil
97 each do |line|
97 each do |line|
98 spacing = prev_line_left && prev_line_right && (line.nb_line_left != prev_line_left+1) && (line.nb_line_right != prev_line_right+1)
98 spacing = prev_line_left && prev_line_right && (line.nb_line_left != prev_line_left+1) && (line.nb_line_right != prev_line_right+1)
99 yield spacing, line
99 yield spacing, line
100 prev_line_left = line.nb_line_left.to_i if line.nb_line_left.to_i > 0
100 prev_line_left = line.nb_line_left.to_i if line.nb_line_left.to_i > 0
101 prev_line_right = line.nb_line_right.to_i if line.nb_line_right.to_i > 0
101 prev_line_right = line.nb_line_right.to_i if line.nb_line_right.to_i > 0
102 end
102 end
103 end
103 end
104
104
105 def inspect
105 def inspect
106 puts '### DIFF TABLE ###'
106 puts '### DIFF TABLE ###'
107 puts "file : #{file_name}"
107 puts "file : #{file_name}"
108 self.each do |d|
108 self.each do |d|
109 d.inspect
109 d.inspect
110 end
110 end
111 end
111 end
112
112
113 private
113 private
114
114
115 # Escape the HTML for the diff
116 def escapeHTML(line)
117 CGI.escapeHTML(line)
118 end
119
120 def diff_for_added_line
115 def diff_for_added_line
121 if @type == 'sbs' && @removed > 0 && @added < @removed
116 if @type == 'sbs' && @removed > 0 && @added < @removed
122 self[-(@removed - @added)]
117 self[-(@removed - @added)]
123 else
118 else
124 diff = Diff.new
119 diff = Diff.new
125 self << diff
120 self << diff
126 diff
121 diff
127 end
122 end
128 end
123 end
129
124
130 def parse_line(line, type="inline")
125 def parse_line(line, type="inline")
131 if line[0, 1] == "+"
126 if line[0, 1] == "+"
132 diff = diff_for_added_line
127 diff = diff_for_added_line
133 diff.line_right = escapeHTML line[1..-1]
128 diff.line_right = line[1..-1]
134 diff.nb_line_right = @line_num_r
129 diff.nb_line_right = @line_num_r
135 diff.type_diff_right = 'diff_in'
130 diff.type_diff_right = 'diff_in'
136 @line_num_r += 1
131 @line_num_r += 1
137 @added += 1
132 @added += 1
138 true
133 true
139 elsif line[0, 1] == "-"
134 elsif line[0, 1] == "-"
140 diff = Diff.new
135 diff = Diff.new
141 diff.line_left = escapeHTML line[1..-1]
136 diff.line_left = line[1..-1]
142 diff.nb_line_left = @line_num_l
137 diff.nb_line_left = @line_num_l
143 diff.type_diff_left = 'diff_out'
138 diff.type_diff_left = 'diff_out'
144 self << diff
139 self << diff
145 @line_num_l += 1
140 @line_num_l += 1
146 @removed += 1
141 @removed += 1
147 true
142 true
148 else
143 else
149 write_offsets
144 write_offsets
150 if line[0, 1] =~ /\s/
145 if line[0, 1] =~ /\s/
151 diff = Diff.new
146 diff = Diff.new
152 diff.line_right = escapeHTML line[1..-1]
147 diff.line_right = line[1..-1]
153 diff.nb_line_right = @line_num_r
148 diff.nb_line_right = @line_num_r
154 diff.line_left = escapeHTML line[1..-1]
149 diff.line_left = line[1..-1]
155 diff.nb_line_left = @line_num_l
150 diff.nb_line_left = @line_num_l
156 self << diff
151 self << diff
157 @line_num_l += 1
152 @line_num_l += 1
158 @line_num_r += 1
153 @line_num_r += 1
159 true
154 true
160 elsif line[0, 1] = "\\"
155 elsif line[0, 1] = "\\"
161 true
156 true
162 else
157 else
163 false
158 false
164 end
159 end
165 end
160 end
166 end
161 end
167
162
168 def write_offsets
163 def write_offsets
169 if @added > 0 && @added == @removed
164 if @added > 0 && @added == @removed
170 @added.times do |i|
165 @added.times do |i|
171 line = self[-(1 + i)]
166 line = self[-(1 + i)]
172 removed = (@type == 'sbs') ? line : self[-(1 + @added + i)]
167 removed = (@type == 'sbs') ? line : self[-(1 + @added + i)]
173 offsets = offsets(removed.line_left, line.line_right)
168 offsets = offsets(removed.line_left, line.line_right)
174 removed.offsets = line.offsets = offsets
169 removed.offsets = line.offsets = offsets
175 end
170 end
176 end
171 end
177 @added = 0
172 @added = 0
178 @removed = 0
173 @removed = 0
179 end
174 end
180
175
181 def offsets(line_left, line_right)
176 def offsets(line_left, line_right)
182 if line_left.present? && line_right.present? && line_left != line_right
177 if line_left.present? && line_right.present? && line_left != line_right
183 max = [line_left.size, line_right.size].min
178 max = [line_left.size, line_right.size].min
184 starting = 0
179 starting = 0
185 while starting < max && line_left[starting] == line_right[starting]
180 while starting < max && line_left[starting] == line_right[starting]
186 starting += 1
181 starting += 1
187 end
182 end
188 ending = -1
183 ending = -1
189 while ending >= -(max - starting) && line_left[ending] == line_right[ending]
184 while ending >= -(max - starting) && line_left[ending] == line_right[ending]
190 ending -= 1
185 ending -= 1
191 end
186 end
192 unless starting == 0 && ending == -1
187 unless starting == 0 && ending == -1
193 [starting, ending]
188 [starting, ending]
194 end
189 end
195 end
190 end
196 end
191 end
197 end
192 end
198
193
199 # A line of diff
194 # A line of diff
200 class Diff
195 class Diff
201 attr_accessor :nb_line_left
196 attr_accessor :nb_line_left
202 attr_accessor :line_left
197 attr_accessor :line_left
203 attr_accessor :nb_line_right
198 attr_accessor :nb_line_right
204 attr_accessor :line_right
199 attr_accessor :line_right
205 attr_accessor :type_diff_right
200 attr_accessor :type_diff_right
206 attr_accessor :type_diff_left
201 attr_accessor :type_diff_left
207 attr_accessor :offsets
202 attr_accessor :offsets
208
203
209 def initialize()
204 def initialize()
210 self.nb_line_left = ''
205 self.nb_line_left = ''
211 self.nb_line_right = ''
206 self.nb_line_right = ''
212 self.line_left = ''
207 self.line_left = ''
213 self.line_right = ''
208 self.line_right = ''
214 self.type_diff_right = ''
209 self.type_diff_right = ''
215 self.type_diff_left = ''
210 self.type_diff_left = ''
216 end
211 end
217
212
218 def type_diff
213 def type_diff
219 type_diff_right == 'diff_in' ? type_diff_right : type_diff_left
214 type_diff_right == 'diff_in' ? type_diff_right : type_diff_left
220 end
215 end
221
216
222 def line
217 def line
223 type_diff_right == 'diff_in' ? line_right : line_left
218 type_diff_right == 'diff_in' ? line_right : line_left
224 end
219 end
225
220
226 def html_line_left
221 def html_line_left
227 if offsets
222 line_to_html(line_left, offsets)
228 line_left.dup.insert(offsets.first, '<span>').insert(offsets.last, '</span>')
229 else
230 line_left
231 end
232 end
223 end
233
224
234 def html_line_right
225 def html_line_right
235 if offsets
226 line_to_html(line_right, offsets)
236 line_right.dup.insert(offsets.first, '<span>').insert(offsets.last, '</span>')
237 else
238 line_right
239 end
240 end
227 end
241
228
242 def html_line
229 def html_line
243 if offsets
230 line_to_html(line, offsets)
244 line.dup.insert(offsets.first, '<span>').insert(offsets.last, '</span>')
245 else
246 line
247 end
248 end
231 end
249
232
250 def inspect
233 def inspect
251 puts '### Start Line Diff ###'
234 puts '### Start Line Diff ###'
252 puts self.nb_line_left
235 puts self.nb_line_left
253 puts self.line_left
236 puts self.line_left
254 puts self.nb_line_right
237 puts self.nb_line_right
255 puts self.line_right
238 puts self.line_right
256 end
239 end
240
241 private
242
243 def line_to_html(line, offsets)
244 if offsets
245 s = ''
246 unless offsets.first == 0
247 s << CGI.escapeHTML(line[0..offsets.first-1])
248 end
249 s << '<span>' + CGI.escapeHTML(line[offsets.first..offsets.last]) + '</span>'
250 unless offsets.last == -1
251 s << CGI.escapeHTML(line[offsets.last+1..-1])
252 end
253 s
254 else
255 CGI.escapeHTML(line)
256 end
257 end
257 end
258 end
258 end
259 end
@@ -1,156 +1,179
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2011 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.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
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.expand_path('../../../../test_helper', __FILE__)
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
24
24
25 def test_subversion_diff
25 def test_subversion_diff
26 diff = Redmine::UnifiedDiff.new(read_diff_fixture('subversion.diff'))
26 diff = Redmine::UnifiedDiff.new(read_diff_fixture('subversion.diff'))
27 # number of files
27 # number of files
28 assert_equal 4, diff.size
28 assert_equal 4, diff.size
29 assert diff.detect {|file| file.file_name =~ %r{^config/settings.yml}}
29 assert diff.detect {|file| file.file_name =~ %r{^config/settings.yml}}
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
35 end
36
36
37 def test_inline_partials
37 def test_inline_partials
38 diff = Redmine::UnifiedDiff.new(read_diff_fixture('partials.diff'))
38 diff = Redmine::UnifiedDiff.new(read_diff_fixture('partials.diff'))
39 assert_equal 1, diff.size
39 assert_equal 1, diff.size
40 diff = diff.first
40 diff = diff.first
41 assert_equal 43, diff.size
41 assert_equal 43, diff.size
42
42
43 assert_equal [51, -1], diff[0].offsets
43 assert_equal [51, -1], diff[0].offsets
44 assert_equal [51, -1], diff[1].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
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
46 assert_equal 'Lorem ipsum dolor sit amet, consectetur adipiscing <span>xx</span>', diff[1].html_line
47
47
48 assert_nil diff[2].offsets
48 assert_nil diff[2].offsets
49 assert_equal 'Praesent et sagittis dui. Vivamus ac diam diam', diff[2].html_line
49 assert_equal 'Praesent et sagittis dui. Vivamus ac diam diam', diff[2].html_line
50
50
51 assert_equal [0, -14], diff[3].offsets
51 assert_equal [0, -14], diff[3].offsets
52 assert_equal [0, -14], diff[4].offsets
52 assert_equal [0, -14], diff[4].offsets
53 assert_equal '<span>Ut sed</span> auctor justo', diff[3].html_line
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
54 assert_equal '<span>xxx</span> auctor justo', diff[4].html_line
55
55
56 assert_equal [13, -19], diff[6].offsets
56 assert_equal [13, -19], diff[6].offsets
57 assert_equal [13, -19], diff[7].offsets
57 assert_equal [13, -19], diff[7].offsets
58
58
59 assert_equal [24, -8], diff[9].offsets
59 assert_equal [24, -8], diff[9].offsets
60 assert_equal [24, -8], diff[10].offsets
60 assert_equal [24, -8], diff[10].offsets
61
61
62 assert_equal [37, -1], diff[12].offsets
62 assert_equal [37, -1], diff[12].offsets
63 assert_equal [37, -1], diff[13].offsets
63 assert_equal [37, -1], diff[13].offsets
64
64
65 assert_equal [0, -38], diff[15].offsets
65 assert_equal [0, -38], diff[15].offsets
66 assert_equal [0, -38], diff[16].offsets
66 assert_equal [0, -38], diff[16].offsets
67 end
67 end
68
68
69 def test_side_by_side_partials
69 def test_side_by_side_partials
70 diff = Redmine::UnifiedDiff.new(read_diff_fixture('partials.diff'), :type => 'sbs')
70 diff = Redmine::UnifiedDiff.new(read_diff_fixture('partials.diff'), :type => 'sbs')
71 assert_equal 1, diff.size
71 assert_equal 1, diff.size
72 diff = diff.first
72 diff = diff.first
73 assert_equal 32, diff.size
73 assert_equal 32, diff.size
74
74
75 assert_equal [51, -1], diff[0].offsets
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
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
77 assert_equal 'Lorem ipsum dolor sit amet, consectetur adipiscing <span>xx</span>', diff[0].html_line_right
78
78
79 assert_nil diff[1].offsets
79 assert_nil diff[1].offsets
80 assert_equal 'Praesent et sagittis dui. Vivamus ac diam diam', diff[1].html_line_left
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
81 assert_equal 'Praesent et sagittis dui. Vivamus ac diam diam', diff[1].html_line_right
82
82
83 assert_equal [0, -14], diff[2].offsets
83 assert_equal [0, -14], diff[2].offsets
84 assert_equal '<span>Ut sed</span> auctor justo', diff[2].html_line_left
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
85 assert_equal '<span>xxx</span> auctor justo', diff[2].html_line_right
86
86
87 assert_equal [13, -19], diff[4].offsets
87 assert_equal [13, -19], diff[4].offsets
88 assert_equal [24, -8], diff[6].offsets
88 assert_equal [24, -8], diff[6].offsets
89 assert_equal [37, -1], diff[8].offsets
89 assert_equal [37, -1], diff[8].offsets
90 assert_equal [0, -38], diff[10].offsets
90 assert_equal [0, -38], diff[10].offsets
91
91
92 end
92 end
93
93
94 def test_partials_with_html_entities
95 raw = <<-DIFF
96 --- test.orig.txt Wed Feb 15 16:10:39 2012
97 +++ test.new.txt Wed Feb 15 16:11:25 2012
98 @@ -1,5 +1,5 @@
99 Semicolons were mysteriously appearing in code diffs in the repository
100
101 -void DoSomething(std::auto_ptr<MyClass> myObj)
102 +void DoSomething(const MyClass& myObj)
103
104 DIFF
105
106 diff = Redmine::UnifiedDiff.new(raw, :type => 'sbs')
107 assert_equal 1, diff.size
108 assert_equal 'void DoSomething(<span>std::auto_ptr&lt;MyClass&gt;</span> myObj)', diff.first[2].html_line_left
109 assert_equal 'void DoSomething(<span>const MyClass&amp;</span> myObj)', diff.first[2].html_line_right
110
111 diff = Redmine::UnifiedDiff.new(raw, :type => 'inline')
112 assert_equal 1, diff.size
113 assert_equal 'void DoSomething(<span>std::auto_ptr&lt;MyClass&gt;</span> myObj)', diff.first[2].html_line
114 assert_equal 'void DoSomething(<span>const MyClass&amp;</span> myObj)', diff.first[3].html_line
115 end
116
94 def test_line_starting_with_dashes
117 def test_line_starting_with_dashes
95 diff = Redmine::UnifiedDiff.new(<<-DIFF
118 diff = Redmine::UnifiedDiff.new(<<-DIFF
96 --- old.txt Wed Nov 11 14:24:58 2009
119 --- old.txt Wed Nov 11 14:24:58 2009
97 +++ new.txt Wed Nov 11 14:25:02 2009
120 +++ new.txt Wed Nov 11 14:25:02 2009
98 @@ -1,8 +1,4 @@
121 @@ -1,8 +1,4 @@
99 -Lines that starts with dashes:
122 -Lines that starts with dashes:
100 -
123 -
101 -------------------------
124 -------------------------
102 --- file.c
125 --- file.c
103 -------------------------
126 -------------------------
104 +A line that starts with dashes:
127 +A line that starts with dashes:
105
128
106 and removed.
129 and removed.
107
130
108 @@ -23,4 +19,4 @@
131 @@ -23,4 +19,4 @@
109
132
110
133
111
134
112 -Another chunk of change
135 -Another chunk of change
113 +Another chunk of changes
136 +Another chunk of changes
114
137
115 DIFF
138 DIFF
116 )
139 )
117 assert_equal 1, diff.size
140 assert_equal 1, diff.size
118 end
141 end
119
142
120 def test_one_line_new_files
143 def test_one_line_new_files
121 diff = Redmine::UnifiedDiff.new(<<-DIFF
144 diff = Redmine::UnifiedDiff.new(<<-DIFF
122 diff -r 000000000000 -r ea98b14f75f0 README1
145 diff -r 000000000000 -r ea98b14f75f0 README1
123 --- /dev/null
146 --- /dev/null
124 +++ b/README1
147 +++ b/README1
125 @@ -0,0 +1,1 @@
148 @@ -0,0 +1,1 @@
126 +test1
149 +test1
127 diff -r 000000000000 -r ea98b14f75f0 README2
150 diff -r 000000000000 -r ea98b14f75f0 README2
128 --- /dev/null
151 --- /dev/null
129 +++ b/README2
152 +++ b/README2
130 @@ -0,0 +1,1 @@
153 @@ -0,0 +1,1 @@
131 +test2
154 +test2
132 diff -r 000000000000 -r ea98b14f75f0 README3
155 diff -r 000000000000 -r ea98b14f75f0 README3
133 --- /dev/null
156 --- /dev/null
134 +++ b/README3
157 +++ b/README3
135 @@ -0,0 +1,3 @@
158 @@ -0,0 +1,3 @@
136 +test4
159 +test4
137 +test5
160 +test5
138 +test6
161 +test6
139 diff -r 000000000000 -r ea98b14f75f0 README4
162 diff -r 000000000000 -r ea98b14f75f0 README4
140 --- /dev/null
163 --- /dev/null
141 +++ b/README4
164 +++ b/README4
142 @@ -0,0 +1,3 @@
165 @@ -0,0 +1,3 @@
143 +test4
166 +test4
144 +test5
167 +test5
145 +test6
168 +test6
146 DIFF
169 DIFF
147 )
170 )
148 assert_equal 4, diff.size
171 assert_equal 4, diff.size
149 end
172 end
150
173
151 private
174 private
152
175
153 def read_diff_fixture(filename)
176 def read_diff_fixture(filename)
154 File.new(File.join(File.dirname(__FILE__), '/../../../fixtures/diffs', filename)).read
177 File.new(File.join(File.dirname(__FILE__), '/../../../fixtures/diffs', filename)).read
155 end
178 end
156 end
179 end
General Comments 0
You need to be logged in to leave comments. Login now