Chris@0
|
1 # Redmine - project management software
|
Chris@0
|
2 # Copyright (C) 2006-2008 Jean-Philippe Lang
|
Chris@0
|
3 #
|
Chris@0
|
4 # This program is free software; you can redistribute it and/or
|
Chris@0
|
5 # modify it under the terms of the GNU General Public License
|
Chris@0
|
6 # as published by the Free Software Foundation; either version 2
|
Chris@0
|
7 # of the License, or (at your option) any later version.
|
Chris@0
|
8 #
|
Chris@0
|
9 # This program is distributed in the hope that it will be useful,
|
Chris@0
|
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
Chris@0
|
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
Chris@0
|
12 # GNU General Public License for more details.
|
Chris@0
|
13 #
|
Chris@0
|
14 # You should have received a copy of the GNU General Public License
|
Chris@0
|
15 # along with this program; if not, write to the Free Software
|
Chris@0
|
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
Chris@0
|
17
|
Chris@0
|
18 require File.dirname(__FILE__) + '/../../../test_helper'
|
Chris@0
|
19
|
Chris@0
|
20 class Redmine::UnifiedDiffTest < ActiveSupport::TestCase
|
Chris@0
|
21
|
Chris@0
|
22 def setup
|
Chris@0
|
23 end
|
Chris@0
|
24
|
Chris@0
|
25 def test_subversion_diff
|
Chris@0
|
26 diff = Redmine::UnifiedDiff.new(read_diff_fixture('subversion.diff'))
|
Chris@0
|
27 # number of files
|
Chris@0
|
28 assert_equal 4, diff.size
|
Chris@0
|
29 assert diff.detect {|file| file.file_name =~ %r{^config/settings.yml}}
|
Chris@0
|
30 end
|
Chris@0
|
31
|
Chris@0
|
32 def test_truncate_diff
|
Chris@0
|
33 diff = Redmine::UnifiedDiff.new(read_diff_fixture('subversion.diff'), :max_lines => 20)
|
Chris@0
|
34 assert_equal 2, diff.size
|
Chris@0
|
35 end
|
Chris@0
|
36
|
Chris@0
|
37 def test_line_starting_with_dashes
|
Chris@0
|
38 diff = Redmine::UnifiedDiff.new(<<-DIFF
|
Chris@0
|
39 --- old.txt Wed Nov 11 14:24:58 2009
|
Chris@0
|
40 +++ new.txt Wed Nov 11 14:25:02 2009
|
Chris@0
|
41 @@ -1,8 +1,4 @@
|
Chris@0
|
42 -Lines that starts with dashes:
|
Chris@0
|
43 -
|
Chris@0
|
44 -------------------------
|
Chris@0
|
45 --- file.c
|
Chris@0
|
46 -------------------------
|
Chris@0
|
47 +A line that starts with dashes:
|
Chris@0
|
48
|
Chris@0
|
49 and removed.
|
Chris@0
|
50
|
Chris@0
|
51 @@ -23,4 +19,4 @@
|
Chris@0
|
52
|
Chris@0
|
53
|
Chris@0
|
54
|
Chris@0
|
55 -Another chunk of change
|
Chris@0
|
56 +Another chunk of changes
|
Chris@0
|
57
|
Chris@0
|
58 DIFF
|
Chris@0
|
59 )
|
Chris@0
|
60 assert_equal 1, diff.size
|
Chris@0
|
61 end
|
Chris@0
|
62
|
Chris@0
|
63 private
|
Chris@0
|
64
|
Chris@0
|
65 def read_diff_fixture(filename)
|
Chris@0
|
66 File.new(File.join(File.dirname(__FILE__), '/../../../fixtures/diffs', filename)).read
|
Chris@0
|
67 end
|
Chris@0
|
68 end
|