comparison test/unit/lib/redmine/unified_diff_test.rb @ 1298:4f746d8966dd redmine_2.3_integration

Merge from redmine-2.3 branch to create new branch redmine-2.3-integration
author Chris Cannam
date Fri, 14 Jun 2013 09:28:30 +0100
parents 622f24f53b42
children
comparison
equal deleted inserted replaced
1297:0a574315af3e 1298:4f746d8966dd
1 # Redmine - project management software 1 # Redmine - project management software
2 # Copyright (C) 2006-2012 Jean-Philippe Lang 2 # Copyright (C) 2006-2013 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.
219 ) 219 )
220 assert_equal 1, diff.size 220 assert_equal 1, diff.size
221 assert_equal "test02.txt", diff[0].file_name 221 assert_equal "test02.txt", diff[0].file_name
222 end 222 end
223 223
224 def test_utf8_ja
225 ja = " text_tip_issue_end_day: "
226 ja += "\xe3\x81\x93\xe3\x81\xae\xe6\x97\xa5\xe3\x81\xab\xe7\xb5\x82\xe4\xba\x86\xe3\x81\x99\xe3\x82\x8b<span>\xe3\x82\xbf\xe3\x82\xb9\xe3\x82\xaf</span>"
227 ja.force_encoding('UTF-8') if ja.respond_to?(:force_encoding)
228 with_settings :repositories_encodings => '' do
229 diff = Redmine::UnifiedDiff.new(read_diff_fixture('issue-12641-ja.diff'), :type => 'inline')
230 assert_equal 1, diff.size
231 assert_equal 12, diff.first.size
232 assert_equal ja, diff.first[4].html_line_left
233 end
234 end
235
236 def test_utf8_ru
237 ru = " other: &quot;\xd0\xbe\xd0\xba\xd0\xbe\xd0\xbb\xd0\xbe %{count} \xd1\x87\xd0\xb0\xd1\x81<span>\xd0\xb0</span>&quot;"
238 ru.force_encoding('UTF-8') if ru.respond_to?(:force_encoding)
239 with_settings :repositories_encodings => '' do
240 diff = Redmine::UnifiedDiff.new(read_diff_fixture('issue-12641-ru.diff'), :type => 'inline')
241 assert_equal 1, diff.size
242 assert_equal 8, diff.first.size
243 assert_equal ru, diff.first[3].html_line_left
244 end
245 end
246
247 def test_offset_range_ascii_1
248 raw = <<-DIFF
249 --- a.txt 2013-04-05 14:19:39.000000000 +0900
250 +++ b.txt 2013-04-05 14:19:51.000000000 +0900
251 @@ -1,3 +1,3 @@
252 aaaa
253 -abc
254 +abcd
255 bbbb
256 DIFF
257 diff = Redmine::UnifiedDiff.new(raw, :type => 'sbs')
258 assert_equal 1, diff.size
259 assert_equal 3, diff.first.size
260 assert_equal "abc<span></span>", diff.first[1].html_line_left
261 assert_equal "abc<span>d</span>", diff.first[1].html_line_right
262 end
263
264 def test_offset_range_ascii_2
265 raw = <<-DIFF
266 --- a.txt 2013-04-05 14:19:39.000000000 +0900
267 +++ b.txt 2013-04-05 14:19:51.000000000 +0900
268 @@ -1,3 +1,3 @@
269 aaaa
270 -abc
271 +zabc
272 bbbb
273 DIFF
274 diff = Redmine::UnifiedDiff.new(raw, :type => 'sbs')
275 assert_equal 1, diff.size
276 assert_equal 3, diff.first.size
277 assert_equal "<span></span>abc", diff.first[1].html_line_left
278 assert_equal "<span>z</span>abc", diff.first[1].html_line_right
279 end
280
281 def test_offset_range_japanese_1
282 ja1 = "\xe6\x97\xa5\xe6\x9c\xac<span></span>"
283 ja1.force_encoding('UTF-8') if ja1.respond_to?(:force_encoding)
284 ja2 = "\xe6\x97\xa5\xe6\x9c\xac<span>\xe8\xaa\x9e</span>"
285 ja2.force_encoding('UTF-8') if ja2.respond_to?(:force_encoding)
286 with_settings :repositories_encodings => '' do
287 diff = Redmine::UnifiedDiff.new(
288 read_diff_fixture('issue-13644-1.diff'), :type => 'sbs')
289 assert_equal 1, diff.size
290 assert_equal 3, diff.first.size
291 assert_equal ja1, diff.first[1].html_line_left
292 assert_equal ja2, diff.first[1].html_line_right
293 end
294 end
295
296 def test_offset_range_japanese_2
297 ja1 = "<span></span>\xe6\x97\xa5\xe6\x9c\xac"
298 ja1.force_encoding('UTF-8') if ja1.respond_to?(:force_encoding)
299 ja2 = "<span>\xe3\x81\xab\xe3\x81\xa3\xe3\x81\xbd\xe3\x82\x93</span>\xe6\x97\xa5\xe6\x9c\xac"
300 ja2.force_encoding('UTF-8') if ja2.respond_to?(:force_encoding)
301 with_settings :repositories_encodings => '' do
302 diff = Redmine::UnifiedDiff.new(
303 read_diff_fixture('issue-13644-2.diff'), :type => 'sbs')
304 assert_equal 1, diff.size
305 assert_equal 3, diff.first.size
306 assert_equal ja1, diff.first[1].html_line_left
307 assert_equal ja2, diff.first[1].html_line_right
308 end
309 end
310
224 private 311 private
225 312
226 def read_diff_fixture(filename) 313 def read_diff_fixture(filename)
227 File.new(File.join(File.dirname(__FILE__), '/../../../fixtures/diffs', filename)).read 314 File.new(File.join(File.dirname(__FILE__), '/../../../fixtures/diffs', filename)).read
228 end 315 end