Mercurial > hg > soundsoftware-site
comparison .svn/pristine/00/009460d580c5e7ab7c5519f32165ee2250a363d7.svn-base @ 1296:038ba2d95de8 redmine-2.2
Fix redmine-2.2 branch update (add missing svn files)
author | Chris Cannam |
---|---|
date | Fri, 14 Jun 2013 09:05:06 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
1294:3e4c3460b6ca | 1296:038ba2d95de8 |
---|---|
1 # Redmine - project management software | |
2 # Copyright (C) 2006-2012 Jean-Philippe Lang | |
3 # | |
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 require File.expand_path('../../../../test_helper', __FILE__) | |
19 | |
20 class Redmine::UnifiedDiffTest < ActiveSupport::TestCase | |
21 def test_subversion_diff | |
22 diff = Redmine::UnifiedDiff.new(read_diff_fixture('subversion.diff')) | |
23 # number of files | |
24 assert_equal 4, diff.size | |
25 assert diff.detect {|file| file.file_name =~ %r{^config/settings.yml}} | |
26 end | |
27 | |
28 def test_truncate_diff | |
29 diff = Redmine::UnifiedDiff.new(read_diff_fixture('subversion.diff'), :max_lines => 20) | |
30 assert_equal 2, diff.size | |
31 end | |
32 | |
33 def test_inline_partials | |
34 diff = Redmine::UnifiedDiff.new(read_diff_fixture('partials.diff')) | |
35 assert_equal 1, diff.size | |
36 diff = diff.first | |
37 assert_equal 43, diff.size | |
38 | |
39 assert_equal [51, -1], diff[0].offsets | |
40 assert_equal [51, -1], diff[1].offsets | |
41 assert_equal 'Lorem ipsum dolor sit amet, consectetur adipiscing <span>elit</span>', diff[0].html_line | |
42 assert_equal 'Lorem ipsum dolor sit amet, consectetur adipiscing <span>xx</span>', diff[1].html_line | |
43 | |
44 assert_nil diff[2].offsets | |
45 assert_equal 'Praesent et sagittis dui. Vivamus ac diam diam', diff[2].html_line | |
46 | |
47 assert_equal [0, -14], diff[3].offsets | |
48 assert_equal [0, -14], diff[4].offsets | |
49 assert_equal '<span>Ut sed</span> auctor justo', diff[3].html_line | |
50 assert_equal '<span>xxx</span> auctor justo', diff[4].html_line | |
51 | |
52 assert_equal [13, -19], diff[6].offsets | |
53 assert_equal [13, -19], diff[7].offsets | |
54 | |
55 assert_equal [24, -8], diff[9].offsets | |
56 assert_equal [24, -8], diff[10].offsets | |
57 | |
58 assert_equal [37, -1], diff[12].offsets | |
59 assert_equal [37, -1], diff[13].offsets | |
60 | |
61 assert_equal [0, -38], diff[15].offsets | |
62 assert_equal [0, -38], diff[16].offsets | |
63 end | |
64 | |
65 def test_side_by_side_partials | |
66 diff = Redmine::UnifiedDiff.new(read_diff_fixture('partials.diff'), :type => 'sbs') | |
67 assert_equal 1, diff.size | |
68 diff = diff.first | |
69 assert_equal 32, diff.size | |
70 | |
71 assert_equal [51, -1], diff[0].offsets | |
72 assert_equal 'Lorem ipsum dolor sit amet, consectetur adipiscing <span>elit</span>', diff[0].html_line_left | |
73 assert_equal 'Lorem ipsum dolor sit amet, consectetur adipiscing <span>xx</span>', diff[0].html_line_right | |
74 | |
75 assert_nil diff[1].offsets | |
76 assert_equal 'Praesent et sagittis dui. Vivamus ac diam diam', diff[1].html_line_left | |
77 assert_equal 'Praesent et sagittis dui. Vivamus ac diam diam', diff[1].html_line_right | |
78 | |
79 assert_equal [0, -14], diff[2].offsets | |
80 assert_equal '<span>Ut sed</span> auctor justo', diff[2].html_line_left | |
81 assert_equal '<span>xxx</span> auctor justo', diff[2].html_line_right | |
82 | |
83 assert_equal [13, -19], diff[4].offsets | |
84 assert_equal [24, -8], diff[6].offsets | |
85 assert_equal [37, -1], diff[8].offsets | |
86 assert_equal [0, -38], diff[10].offsets | |
87 | |
88 end | |
89 | |
90 def test_partials_with_html_entities | |
91 raw = <<-DIFF | |
92 --- test.orig.txt Wed Feb 15 16:10:39 2012 | |
93 +++ test.new.txt Wed Feb 15 16:11:25 2012 | |
94 @@ -1,5 +1,5 @@ | |
95 Semicolons were mysteriously appearing in code diffs in the repository | |
96 | |
97 -void DoSomething(std::auto_ptr<MyClass> myObj) | |
98 +void DoSomething(const MyClass& myObj) | |
99 | |
100 DIFF | |
101 | |
102 diff = Redmine::UnifiedDiff.new(raw, :type => 'sbs') | |
103 assert_equal 1, diff.size | |
104 assert_equal 'void DoSomething(<span>std::auto_ptr<MyClass></span> myObj)', diff.first[2].html_line_left | |
105 assert_equal 'void DoSomething(<span>const MyClass&</span> myObj)', diff.first[2].html_line_right | |
106 | |
107 diff = Redmine::UnifiedDiff.new(raw, :type => 'inline') | |
108 assert_equal 1, diff.size | |
109 assert_equal 'void DoSomething(<span>std::auto_ptr<MyClass></span> myObj)', diff.first[2].html_line | |
110 assert_equal 'void DoSomething(<span>const MyClass&</span> myObj)', diff.first[3].html_line | |
111 end | |
112 | |
113 def test_line_starting_with_dashes | |
114 diff = Redmine::UnifiedDiff.new(<<-DIFF | |
115 --- old.txt Wed Nov 11 14:24:58 2009 | |
116 +++ new.txt Wed Nov 11 14:25:02 2009 | |
117 @@ -1,8 +1,4 @@ | |
118 -Lines that starts with dashes: | |
119 - | |
120 ------------------------- | |
121 --- file.c | |
122 ------------------------- | |
123 +A line that starts with dashes: | |
124 | |
125 and removed. | |
126 | |
127 @@ -23,4 +19,4 @@ | |
128 | |
129 | |
130 | |
131 -Another chunk of change | |
132 +Another chunk of changes | |
133 | |
134 DIFF | |
135 ) | |
136 assert_equal 1, diff.size | |
137 end | |
138 | |
139 def test_one_line_new_files | |
140 diff = Redmine::UnifiedDiff.new(<<-DIFF | |
141 diff -r 000000000000 -r ea98b14f75f0 README1 | |
142 --- /dev/null | |
143 +++ b/README1 | |
144 @@ -0,0 +1,1 @@ | |
145 +test1 | |
146 diff -r 000000000000 -r ea98b14f75f0 README2 | |
147 --- /dev/null | |
148 +++ b/README2 | |
149 @@ -0,0 +1,1 @@ | |
150 +test2 | |
151 diff -r 000000000000 -r ea98b14f75f0 README3 | |
152 --- /dev/null | |
153 +++ b/README3 | |
154 @@ -0,0 +1,3 @@ | |
155 +test4 | |
156 +test5 | |
157 +test6 | |
158 diff -r 000000000000 -r ea98b14f75f0 README4 | |
159 --- /dev/null | |
160 +++ b/README4 | |
161 @@ -0,0 +1,3 @@ | |
162 +test4 | |
163 +test5 | |
164 +test6 | |
165 DIFF | |
166 ) | |
167 assert_equal 4, diff.size | |
168 assert_equal "README1", diff[0].file_name | |
169 end | |
170 | |
171 def test_both_git_diff | |
172 diff = Redmine::UnifiedDiff.new(<<-DIFF | |
173 # HG changeset patch | |
174 # User test | |
175 # Date 1348014182 -32400 | |
176 # Node ID d1c871b8ef113df7f1c56d41e6e3bfbaff976e1f | |
177 # Parent 180b6605936cdc7909c5f08b59746ec1a7c99b3e | |
178 modify test1.txt | |
179 | |
180 diff -r 180b6605936c -r d1c871b8ef11 test1.txt | |
181 --- a/test1.txt | |
182 +++ b/test1.txt | |
183 @@ -1,1 +1,1 @@ | |
184 -test1 | |
185 +modify test1 | |
186 DIFF | |
187 ) | |
188 assert_equal 1, diff.size | |
189 assert_equal "test1.txt", diff[0].file_name | |
190 end | |
191 | |
192 def test_include_a_b_slash | |
193 diff = Redmine::UnifiedDiff.new(<<-DIFF | |
194 --- test1.txt | |
195 +++ b/test02.txt | |
196 @@ -1 +0,0 @@ | |
197 -modify test1 | |
198 DIFF | |
199 ) | |
200 assert_equal 1, diff.size | |
201 assert_equal "b/test02.txt", diff[0].file_name | |
202 | |
203 diff = Redmine::UnifiedDiff.new(<<-DIFF | |
204 --- a/test1.txt | |
205 +++ a/test02.txt | |
206 @@ -1 +0,0 @@ | |
207 -modify test1 | |
208 DIFF | |
209 ) | |
210 assert_equal 1, diff.size | |
211 assert_equal "a/test02.txt", diff[0].file_name | |
212 | |
213 diff = Redmine::UnifiedDiff.new(<<-DIFF | |
214 --- a/test1.txt | |
215 +++ test02.txt | |
216 @@ -1 +0,0 @@ | |
217 -modify test1 | |
218 DIFF | |
219 ) | |
220 assert_equal 1, diff.size | |
221 assert_equal "test02.txt", diff[0].file_name | |
222 end | |
223 | |
224 private | |
225 | |
226 def read_diff_fixture(filename) | |
227 File.new(File.join(File.dirname(__FILE__), '/../../../fixtures/diffs', filename)).read | |
228 end | |
229 end |