To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / test / unit / lib / redmine / .svn / text-base / unified_diff_test.rb.svn-base @ 442:753f1380d6bc

History | View | Annotate | Download (4.64 KB)

1 0:513646585e45 Chris
# Redmine - project management software
2 441:cbce1fd3b1b7 Chris
# Copyright (C) 2006-2011  Jean-Philippe Lang
3 0:513646585e45 Chris
#
4
# This program is free software; you can redistribute it and/or
5
# modify it under the terms of the GNU General Public License
6
# as published by the Free Software Foundation; either version 2
7
# of the License, or (at your option) any later version.
8
#
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU General Public License for more details.
13
#
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
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17
18 119:8661b858af72 Chris
require File.expand_path('../../../../test_helper', __FILE__)
19 0:513646585e45 Chris
20
class Redmine::UnifiedDiffTest < ActiveSupport::TestCase
21
22
  def setup
23
  end
24
25
  def test_subversion_diff
26
    diff = Redmine::UnifiedDiff.new(read_diff_fixture('subversion.diff'))
27
    # number of files
28
    assert_equal 4, diff.size
29
    assert diff.detect {|file| file.file_name =~ %r{^config/settings.yml}}
30
  end
31
32
  def test_truncate_diff
33
    diff = Redmine::UnifiedDiff.new(read_diff_fixture('subversion.diff'), :max_lines => 20)
34
    assert_equal 2, diff.size
35
  end
36
37 441:cbce1fd3b1b7 Chris
  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
92
  end
93
94 0:513646585e45 Chris
  def test_line_starting_with_dashes
95
    diff = Redmine::UnifiedDiff.new(<<-DIFF
96
--- old.txt Wed Nov 11 14:24:58 2009
97
+++ new.txt Wed Nov 11 14:25:02 2009
98
@@ -1,8 +1,4 @@
99
-Lines that starts with dashes:
100
-
101
-------------------------
102
--- file.c
103
-------------------------
104
+A line that starts with dashes:
105
106
 and removed.
107
108
@@ -23,4 +19,4 @@
109
110
111
112
-Another chunk of change
113
+Another chunk of changes
114
115
DIFF
116
    )
117
    assert_equal 1, diff.size
118
  end
119
120 245:051f544170fe Chris
  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
151 0:513646585e45 Chris
  private
152 245:051f544170fe Chris
153 0:513646585e45 Chris
  def read_diff_fixture(filename)
154
    File.new(File.join(File.dirname(__FILE__), '/../../../fixtures/diffs', filename)).read
155
  end
156
end