##// END OF EJS Templates
Merged r11544, r11545, r11546, r11547, r11549 from trunk to 2.3-stable (#12641)...
Toshi MARUYAMA -
r11321:a4b6928a261e
parent child
Show More
@@ -0,0 +1,25
1 # HG changeset patch
2 # User tmaruyama
3 # Date 1362559296 0
4 # Node ID ee54942e0289c30bea1b1973750b698b1ee7c466
5 # Parent 738777832f379f6f099c25251593fc57bc17f586
6 fix some Japanese "issue" translations (#13350)
7
8 Contributed by Go MAEDA.
9
10 diff --git a/config/locales/ja.yml b/config/locales/ja.yml
11 --- a/config/locales/ja.yml
12 +++ b/config/locales/ja.yml
13 @@ -904,9 +904,9 @@ ja:
14 text_journal_set_to: "%{label} を %{value} にセット"
15 text_journal_deleted: "%{label} を削除 (%{old})"
16 text_journal_added: "%{label} %{value} を追加"
17 - text_tip_issue_begin_day: この日に開始するタスク
18 - text_tip_issue_end_day: この日に終了するタスク
19 - text_tip_issue_begin_end_day: この日のうちに開始して終了するタスク
20 + text_tip_issue_begin_day: この日に開始するチケット
21 + text_tip_issue_end_day: この日に終了するチケット
22 + text_tip_issue_begin_end_day: この日に開始・終了するチケット
23 text_caracters_maximum: "最大%{count}文字です。"
24 text_caracters_minimum: "最低%{count}文字の長さが必要です"
25 text_length_between: "長さは%{min}から%{max}文字までです。"
@@ -0,0 +1,19
1 # HG changeset patch
2 # User tmaruyama
3 # Date 1355872765 0
4 # Node ID 8a13ebed1779c2e85fa644ecdd0de81996c969c4
5 # Parent 5c3c5f917ae92f278fe42c6978366996595b0796
6 Russian "about_x_hours" translation changed by Mikhail Velkin (#12640)
7
8 diff --git a/config/locales/ru.yml b/config/locales/ru.yml
9 --- a/config/locales/ru.yml
10 +++ b/config/locales/ru.yml
11 @@ -115,7 +115,7 @@ ru:
12 one: "около %{count} часа"
13 few: "около %{count} часов"
14 many: "около %{count} часов"
15 - other: "около %{count} часа"
16 + other: "около %{count} часов"
17 x_hours:
18 one: "1 час"
19 other: "%{count} часов"
@@ -1,68 +1,68
1 <% diff = Redmine::UnifiedDiff.new(
1 <% diff = Redmine::UnifiedDiff.new(
2 diff, :type => diff_type,
2 diff, :type => diff_type,
3 :max_lines => Setting.diff_max_lines_displayed.to_i,
3 :max_lines => Setting.diff_max_lines_displayed.to_i,
4 :style => diff_style) -%>
4 :style => diff_style) -%>
5
5
6 <% diff.each do |table_file| -%>
6 <% diff.each do |table_file| -%>
7 <div class="autoscroll">
7 <div class="autoscroll">
8 <% if diff.diff_type == 'sbs' -%>
8 <% if diff.diff_type == 'sbs' -%>
9 <table class="filecontent">
9 <table class="filecontent">
10 <thead>
10 <thead>
11 <tr>
11 <tr>
12 <th colspan="4" class="filename">
12 <th colspan="4" class="filename">
13 <%= h(Redmine::CodesetUtil.to_utf8_by_setting(table_file.file_name)) %>
13 <%= table_file.file_name %>
14 </th>
14 </th>
15 </tr>
15 </tr>
16 </thead>
16 </thead>
17 <tbody>
17 <tbody>
18 <% table_file.each_line do |spacing, line| -%>
18 <% table_file.each_line do |spacing, line| -%>
19 <% if spacing -%>
19 <% if spacing -%>
20 <tr class="spacing">
20 <tr class="spacing">
21 <th class="line-num">...</th><td></td><th class="line-num">...</th><td></td>
21 <th class="line-num">...</th><td></td><th class="line-num">...</th><td></td>
22 </tr>
22 </tr>
23 <% end -%>
23 <% end -%>
24 <tr>
24 <tr>
25 <th class="line-num"><%= line.nb_line_left %></th>
25 <th class="line-num"><%= line.nb_line_left %></th>
26 <td class="line-code <%= line.type_diff_left %>">
26 <td class="line-code <%= line.type_diff_left %>">
27 <pre><%= Redmine::CodesetUtil.to_utf8_by_setting(line.html_line_left).html_safe %></pre>
27 <pre><%= line.html_line_left.html_safe %></pre>
28 </td>
28 </td>
29 <th class="line-num"><%= line.nb_line_right %></th>
29 <th class="line-num"><%= line.nb_line_right %></th>
30 <td class="line-code <%= line.type_diff_right %>">
30 <td class="line-code <%= line.type_diff_right %>">
31 <pre><%= Redmine::CodesetUtil.to_utf8_by_setting(line.html_line_right).html_safe %></pre>
31 <pre><%= line.html_line_right.html_safe %></pre>
32 </td>
32 </td>
33 </tr>
33 </tr>
34 <% end -%>
34 <% end -%>
35 </tbody>
35 </tbody>
36 </table>
36 </table>
37
37
38 <% else -%>
38 <% else -%>
39 <table class="filecontent">
39 <table class="filecontent">
40 <thead>
40 <thead>
41 <tr>
41 <tr>
42 <th colspan="3" class="filename">
42 <th colspan="3" class="filename">
43 <%= h(Redmine::CodesetUtil.to_utf8_by_setting(table_file.file_name)) %>
43 <%= table_file.file_name %>
44 </th>
44 </th>
45 </tr>
45 </tr>
46 </thead>
46 </thead>
47 <tbody>
47 <tbody>
48 <% table_file.each_line do |spacing, line| %>
48 <% table_file.each_line do |spacing, line| %>
49 <% if spacing -%>
49 <% if spacing -%>
50 <tr class="spacing">
50 <tr class="spacing">
51 <th class="line-num">...</th><th class="line-num">...</th><td></td>
51 <th class="line-num">...</th><th class="line-num">...</th><td></td>
52 </tr>
52 </tr>
53 <% end -%>
53 <% end -%>
54 <tr>
54 <tr>
55 <th class="line-num"><%= line.nb_line_left %></th>
55 <th class="line-num"><%= line.nb_line_left %></th>
56 <th class="line-num"><%= line.nb_line_right %></th>
56 <th class="line-num"><%= line.nb_line_right %></th>
57 <td class="line-code <%= line.type_diff %>">
57 <td class="line-code <%= line.type_diff %>">
58 <pre><%= Redmine::CodesetUtil.to_utf8_by_setting(line.html_line).html_safe %></pre>
58 <pre><%= line.html_line.html_safe %></pre>
59 </td>
59 </td>
60 </tr>
60 </tr>
61 <% end -%>
61 <% end -%>
62 </tbody>
62 </tbody>
63 </table>
63 </table>
64 <% end -%>
64 <% end -%>
65 </div>
65 </div>
66 <% end -%>
66 <% end -%>
67
67
68 <%= l(:text_diff_truncated) if diff.truncated? %>
68 <%= l(:text_diff_truncated) if diff.truncated? %>
@@ -1,286 +1,290
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2013 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.
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, :diff_style
21 attr_reader :diff_type, :diff_style
22
22
23 def initialize(diff, options={})
23 def initialize(diff, options={})
24 options.assert_valid_keys(:type, :style, :max_lines)
24 options.assert_valid_keys(:type, :style, :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 @diff_style = options[:style]
27 @diff_style = options[:style]
28 lines = 0
28 lines = 0
29 @truncated = false
29 @truncated = false
30 diff_table = DiffTable.new(diff_type, diff_style)
30 diff_table = DiffTable.new(diff_type, diff_style)
31 diff.each do |line|
31 diff.each do |line_raw|
32 line_encoding = nil
32 line = Redmine::CodesetUtil.to_utf8_by_setting(line_raw)
33 if line.respond_to?(:force_encoding)
33 unless diff_table.add_line(line)
34 line_encoding = line.encoding
35 # TODO: UTF-16 and Japanese CP932 which is imcompatible with ASCII
36 # In Japan, diffrence between file path encoding
37 # and file contents encoding is popular.
38 line.force_encoding('ASCII-8BIT')
39 end
40 unless diff_table.add_line line
41 line.force_encoding(line_encoding) if line_encoding
42 self << diff_table if diff_table.length > 0
34 self << diff_table if diff_table.length > 0
43 diff_table = DiffTable.new(diff_type, diff_style)
35 diff_table = DiffTable.new(diff_type, diff_style)
44 end
36 end
45 lines += 1
37 lines += 1
46 if options[:max_lines] && lines > options[:max_lines]
38 if options[:max_lines] && lines > options[:max_lines]
47 @truncated = true
39 @truncated = true
48 break
40 break
49 end
41 end
50 end
42 end
51 self << diff_table unless diff_table.empty?
43 self << diff_table unless diff_table.empty?
52 self
44 self
53 end
45 end
54
46
55 def truncated?; @truncated; end
47 def truncated?; @truncated; end
56 end
48 end
57
49
58 # Class that represents a file diff
50 # Class that represents a file diff
59 class DiffTable < Array
51 class DiffTable < Array
60 attr_reader :file_name
52 attr_reader :file_name
61
53
62 # Initialize with a Diff file and the type of Diff View
54 # Initialize with a Diff file and the type of Diff View
63 # The type view must be inline or sbs (side_by_side)
55 # The type view must be inline or sbs (side_by_side)
64 def initialize(type="inline", style=nil)
56 def initialize(type="inline", style=nil)
65 @parsing = false
57 @parsing = false
66 @added = 0
58 @added = 0
67 @removed = 0
59 @removed = 0
68 @type = type
60 @type = type
69 @style = style
61 @style = style
70 @file_name = nil
62 @file_name = nil
71 @git_diff = false
63 @git_diff = false
72 end
64 end
73
65
74 # Function for add a line of this Diff
66 # Function for add a line of this Diff
75 # Returns false when the diff ends
67 # Returns false when the diff ends
76 def add_line(line)
68 def add_line(line)
77 unless @parsing
69 unless @parsing
78 if line =~ /^(---|\+\+\+) (.*)$/
70 if line =~ /^(---|\+\+\+) (.*)$/
79 self.file_name = $2
71 self.file_name = $2
80 elsif line =~ /^@@ (\+|\-)(\d+)(,\d+)? (\+|\-)(\d+)(,\d+)? @@/
72 elsif line =~ /^@@ (\+|\-)(\d+)(,\d+)? (\+|\-)(\d+)(,\d+)? @@/
81 @line_num_l = $2.to_i
73 @line_num_l = $2.to_i
82 @line_num_r = $5.to_i
74 @line_num_r = $5.to_i
83 @parsing = true
75 @parsing = true
84 end
76 end
85 else
77 else
86 if line =~ %r{^[^\+\-\s@\\]}
78 if line =~ %r{^[^\+\-\s@\\]}
87 @parsing = false
79 @parsing = false
88 return false
80 return false
89 elsif line =~ /^@@ (\+|\-)(\d+)(,\d+)? (\+|\-)(\d+)(,\d+)? @@/
81 elsif line =~ /^@@ (\+|\-)(\d+)(,\d+)? (\+|\-)(\d+)(,\d+)? @@/
90 @line_num_l = $2.to_i
82 @line_num_l = $2.to_i
91 @line_num_r = $5.to_i
83 @line_num_r = $5.to_i
92 else
84 else
93 parse_line(line, @type)
85 parse_line(line, @type)
94 end
86 end
95 end
87 end
96 return true
88 return true
97 end
89 end
98
90
99 def each_line
91 def each_line
100 prev_line_left, prev_line_right = nil, nil
92 prev_line_left, prev_line_right = nil, nil
101 each do |line|
93 each do |line|
102 spacing = prev_line_left && prev_line_right && (line.nb_line_left != prev_line_left+1) && (line.nb_line_right != prev_line_right+1)
94 spacing = prev_line_left && prev_line_right && (line.nb_line_left != prev_line_left+1) && (line.nb_line_right != prev_line_right+1)
103 yield spacing, line
95 yield spacing, line
104 prev_line_left = line.nb_line_left.to_i if line.nb_line_left.to_i > 0
96 prev_line_left = line.nb_line_left.to_i if line.nb_line_left.to_i > 0
105 prev_line_right = line.nb_line_right.to_i if line.nb_line_right.to_i > 0
97 prev_line_right = line.nb_line_right.to_i if line.nb_line_right.to_i > 0
106 end
98 end
107 end
99 end
108
100
109 def inspect
101 def inspect
110 puts '### DIFF TABLE ###'
102 puts '### DIFF TABLE ###'
111 puts "file : #{file_name}"
103 puts "file : #{file_name}"
112 self.each do |d|
104 self.each do |d|
113 d.inspect
105 d.inspect
114 end
106 end
115 end
107 end
116
108
117 private
109 private
118
110
119 def file_name=(arg)
111 def file_name=(arg)
120 both_git_diff = false
112 both_git_diff = false
121 if file_name.nil?
113 if file_name.nil?
122 @git_diff = true if arg =~ %r{^(a/|/dev/null)}
114 @git_diff = true if arg =~ %r{^(a/|/dev/null)}
123 else
115 else
124 both_git_diff = (@git_diff && arg =~ %r{^(b/|/dev/null)})
116 both_git_diff = (@git_diff && arg =~ %r{^(b/|/dev/null)})
125 end
117 end
126 if both_git_diff
118 if both_git_diff
127 if file_name && arg == "/dev/null"
119 if file_name && arg == "/dev/null"
128 # keep the original file name
120 # keep the original file name
129 @file_name = file_name.sub(%r{^a/}, '')
121 @file_name = file_name.sub(%r{^a/}, '')
130 else
122 else
131 # remove leading b/
123 # remove leading b/
132 @file_name = arg.sub(%r{^b/}, '')
124 @file_name = arg.sub(%r{^b/}, '')
133 end
125 end
134 elsif @style == "Subversion"
126 elsif @style == "Subversion"
135 # removing trailing "(revision nn)"
127 # removing trailing "(revision nn)"
136 @file_name = arg.sub(%r{\t+\(.*\)$}, '')
128 @file_name = arg.sub(%r{\t+\(.*\)$}, '')
137 else
129 else
138 @file_name = arg
130 @file_name = arg
139 end
131 end
140 end
132 end
141
133
142 def diff_for_added_line
134 def diff_for_added_line
143 if @type == 'sbs' && @removed > 0 && @added < @removed
135 if @type == 'sbs' && @removed > 0 && @added < @removed
144 self[-(@removed - @added)]
136 self[-(@removed - @added)]
145 else
137 else
146 diff = Diff.new
138 diff = Diff.new
147 self << diff
139 self << diff
148 diff
140 diff
149 end
141 end
150 end
142 end
151
143
152 def parse_line(line, type="inline")
144 def parse_line(line, type="inline")
153 if line[0, 1] == "+"
145 if line[0, 1] == "+"
154 diff = diff_for_added_line
146 diff = diff_for_added_line
155 diff.line_right = line[1..-1]
147 diff.line_right = line[1..-1]
156 diff.nb_line_right = @line_num_r
148 diff.nb_line_right = @line_num_r
157 diff.type_diff_right = 'diff_in'
149 diff.type_diff_right = 'diff_in'
158 @line_num_r += 1
150 @line_num_r += 1
159 @added += 1
151 @added += 1
160 true
152 true
161 elsif line[0, 1] == "-"
153 elsif line[0, 1] == "-"
162 diff = Diff.new
154 diff = Diff.new
163 diff.line_left = line[1..-1]
155 diff.line_left = line[1..-1]
164 diff.nb_line_left = @line_num_l
156 diff.nb_line_left = @line_num_l
165 diff.type_diff_left = 'diff_out'
157 diff.type_diff_left = 'diff_out'
166 self << diff
158 self << diff
167 @line_num_l += 1
159 @line_num_l += 1
168 @removed += 1
160 @removed += 1
169 true
161 true
170 else
162 else
171 write_offsets
163 write_offsets
172 if line[0, 1] =~ /\s/
164 if line[0, 1] =~ /\s/
173 diff = Diff.new
165 diff = Diff.new
174 diff.line_right = line[1..-1]
166 diff.line_right = line[1..-1]
175 diff.nb_line_right = @line_num_r
167 diff.nb_line_right = @line_num_r
176 diff.line_left = line[1..-1]
168 diff.line_left = line[1..-1]
177 diff.nb_line_left = @line_num_l
169 diff.nb_line_left = @line_num_l
178 self << diff
170 self << diff
179 @line_num_l += 1
171 @line_num_l += 1
180 @line_num_r += 1
172 @line_num_r += 1
181 true
173 true
182 elsif line[0, 1] = "\\"
174 elsif line[0, 1] = "\\"
183 true
175 true
184 else
176 else
185 false
177 false
186 end
178 end
187 end
179 end
188 end
180 end
189
181
190 def write_offsets
182 def write_offsets
191 if @added > 0 && @added == @removed
183 if @added > 0 && @added == @removed
192 @added.times do |i|
184 @added.times do |i|
193 line = self[-(1 + i)]
185 line = self[-(1 + i)]
194 removed = (@type == 'sbs') ? line : self[-(1 + @added + i)]
186 removed = (@type == 'sbs') ? line : self[-(1 + @added + i)]
195 offsets = offsets(removed.line_left, line.line_right)
187 offsets = offsets(removed.line_left, line.line_right)
196 removed.offsets = line.offsets = offsets
188 removed.offsets = line.offsets = offsets
197 end
189 end
198 end
190 end
199 @added = 0
191 @added = 0
200 @removed = 0
192 @removed = 0
201 end
193 end
202
194
203 def offsets(line_left, line_right)
195 def offsets(line_left, line_right)
204 if line_left.present? && line_right.present? && line_left != line_right
196 if line_left.present? && line_right.present? && line_left != line_right
205 max = [line_left.size, line_right.size].min
197 max = [line_left.size, line_right.size].min
206 starting = 0
198 starting = 0
207 while starting < max && line_left[starting] == line_right[starting]
199 while starting < max && line_left[starting] == line_right[starting]
208 starting += 1
200 starting += 1
209 end
201 end
202 while line_left[starting].ord.between?(128, 191) && starting > 0
203 starting -= 1
204 end
210 ending = -1
205 ending = -1
211 while ending >= -(max - starting) && line_left[ending] == line_right[ending]
206 while ending >= -(max - starting) && line_left[ending] == line_right[ending]
212 ending -= 1
207 ending -= 1
213 end
208 end
209 while line_left[ending].ord.between?(128, 191) && ending > -1
210 ending -= 1
211 end
214 unless starting == 0 && ending == -1
212 unless starting == 0 && ending == -1
215 [starting, ending]
213 [starting, ending]
216 end
214 end
217 end
215 end
218 end
216 end
219 end
217 end
220
218
221 # A line of diff
219 # A line of diff
222 class Diff
220 class Diff
223 attr_accessor :nb_line_left
221 attr_accessor :nb_line_left
224 attr_accessor :line_left
222 attr_accessor :line_left
225 attr_accessor :nb_line_right
223 attr_accessor :nb_line_right
226 attr_accessor :line_right
224 attr_accessor :line_right
227 attr_accessor :type_diff_right
225 attr_accessor :type_diff_right
228 attr_accessor :type_diff_left
226 attr_accessor :type_diff_left
229 attr_accessor :offsets
227 attr_accessor :offsets
230
228
231 def initialize()
229 def initialize()
232 self.nb_line_left = ''
230 self.nb_line_left = ''
233 self.nb_line_right = ''
231 self.nb_line_right = ''
234 self.line_left = ''
232 self.line_left = ''
235 self.line_right = ''
233 self.line_right = ''
236 self.type_diff_right = ''
234 self.type_diff_right = ''
237 self.type_diff_left = ''
235 self.type_diff_left = ''
238 end
236 end
239
237
240 def type_diff
238 def type_diff
241 type_diff_right == 'diff_in' ? type_diff_right : type_diff_left
239 type_diff_right == 'diff_in' ? type_diff_right : type_diff_left
242 end
240 end
243
241
244 def line
242 def line
245 type_diff_right == 'diff_in' ? line_right : line_left
243 type_diff_right == 'diff_in' ? line_right : line_left
246 end
244 end
247
245
248 def html_line_left
246 def html_line_left
249 line_to_html(line_left, offsets)
247 line_to_html(line_left, offsets)
250 end
248 end
251
249
252 def html_line_right
250 def html_line_right
253 line_to_html(line_right, offsets)
251 line_to_html(line_right, offsets)
254 end
252 end
255
253
256 def html_line
254 def html_line
257 line_to_html(line, offsets)
255 line_to_html(line, offsets)
258 end
256 end
259
257
260 def inspect
258 def inspect
261 puts '### Start Line Diff ###'
259 puts '### Start Line Diff ###'
262 puts self.nb_line_left
260 puts self.nb_line_left
263 puts self.line_left
261 puts self.line_left
264 puts self.nb_line_right
262 puts self.nb_line_right
265 puts self.line_right
263 puts self.line_right
266 end
264 end
267
265
268 private
266 private
269
267
270 def line_to_html(line, offsets)
268 def line_to_html(line, offsets)
269 html = line_to_html_raw(line, offsets)
270 html.force_encoding('UTF-8') if html.respond_to?(:force_encoding)
271 html
272 end
273
274 def line_to_html_raw(line, offsets)
271 if offsets
275 if offsets
272 s = ''
276 s = ''
273 unless offsets.first == 0
277 unless offsets.first == 0
274 s << CGI.escapeHTML(line[0..offsets.first-1])
278 s << CGI.escapeHTML(line[0..offsets.first-1])
275 end
279 end
276 s << '<span>' + CGI.escapeHTML(line[offsets.first..offsets.last]) + '</span>'
280 s << '<span>' + CGI.escapeHTML(line[offsets.first..offsets.last]) + '</span>'
277 unless offsets.last == -1
281 unless offsets.last == -1
278 s << CGI.escapeHTML(line[offsets.last+1..-1])
282 s << CGI.escapeHTML(line[offsets.last+1..-1])
279 end
283 end
280 s
284 s
281 else
285 else
282 CGI.escapeHTML(line)
286 CGI.escapeHTML(line)
283 end
287 end
284 end
288 end
285 end
289 end
286 end
290 end
@@ -1,229 +1,252
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2013 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.
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 def test_subversion_diff
21 def test_subversion_diff
22 diff = Redmine::UnifiedDiff.new(read_diff_fixture('subversion.diff'))
22 diff = Redmine::UnifiedDiff.new(read_diff_fixture('subversion.diff'))
23 # number of files
23 # number of files
24 assert_equal 4, diff.size
24 assert_equal 4, diff.size
25 assert diff.detect {|file| file.file_name =~ %r{^config/settings.yml}}
25 assert diff.detect {|file| file.file_name =~ %r{^config/settings.yml}}
26 end
26 end
27
27
28 def test_truncate_diff
28 def test_truncate_diff
29 diff = Redmine::UnifiedDiff.new(read_diff_fixture('subversion.diff'), :max_lines => 20)
29 diff = Redmine::UnifiedDiff.new(read_diff_fixture('subversion.diff'), :max_lines => 20)
30 assert_equal 2, diff.size
30 assert_equal 2, diff.size
31 end
31 end
32
32
33 def test_inline_partials
33 def test_inline_partials
34 diff = Redmine::UnifiedDiff.new(read_diff_fixture('partials.diff'))
34 diff = Redmine::UnifiedDiff.new(read_diff_fixture('partials.diff'))
35 assert_equal 1, diff.size
35 assert_equal 1, diff.size
36 diff = diff.first
36 diff = diff.first
37 assert_equal 43, diff.size
37 assert_equal 43, diff.size
38
38
39 assert_equal [51, -1], diff[0].offsets
39 assert_equal [51, -1], diff[0].offsets
40 assert_equal [51, -1], diff[1].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
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
42 assert_equal 'Lorem ipsum dolor sit amet, consectetur adipiscing <span>xx</span>', diff[1].html_line
43
43
44 assert_nil diff[2].offsets
44 assert_nil diff[2].offsets
45 assert_equal 'Praesent et sagittis dui. Vivamus ac diam diam', diff[2].html_line
45 assert_equal 'Praesent et sagittis dui. Vivamus ac diam diam', diff[2].html_line
46
46
47 assert_equal [0, -14], diff[3].offsets
47 assert_equal [0, -14], diff[3].offsets
48 assert_equal [0, -14], diff[4].offsets
48 assert_equal [0, -14], diff[4].offsets
49 assert_equal '<span>Ut sed</span> auctor justo', diff[3].html_line
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
50 assert_equal '<span>xxx</span> auctor justo', diff[4].html_line
51
51
52 assert_equal [13, -19], diff[6].offsets
52 assert_equal [13, -19], diff[6].offsets
53 assert_equal [13, -19], diff[7].offsets
53 assert_equal [13, -19], diff[7].offsets
54
54
55 assert_equal [24, -8], diff[9].offsets
55 assert_equal [24, -8], diff[9].offsets
56 assert_equal [24, -8], diff[10].offsets
56 assert_equal [24, -8], diff[10].offsets
57
57
58 assert_equal [37, -1], diff[12].offsets
58 assert_equal [37, -1], diff[12].offsets
59 assert_equal [37, -1], diff[13].offsets
59 assert_equal [37, -1], diff[13].offsets
60
60
61 assert_equal [0, -38], diff[15].offsets
61 assert_equal [0, -38], diff[15].offsets
62 assert_equal [0, -38], diff[16].offsets
62 assert_equal [0, -38], diff[16].offsets
63 end
63 end
64
64
65 def test_side_by_side_partials
65 def test_side_by_side_partials
66 diff = Redmine::UnifiedDiff.new(read_diff_fixture('partials.diff'), :type => 'sbs')
66 diff = Redmine::UnifiedDiff.new(read_diff_fixture('partials.diff'), :type => 'sbs')
67 assert_equal 1, diff.size
67 assert_equal 1, diff.size
68 diff = diff.first
68 diff = diff.first
69 assert_equal 32, diff.size
69 assert_equal 32, diff.size
70
70
71 assert_equal [51, -1], diff[0].offsets
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
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
73 assert_equal 'Lorem ipsum dolor sit amet, consectetur adipiscing <span>xx</span>', diff[0].html_line_right
74
74
75 assert_nil diff[1].offsets
75 assert_nil diff[1].offsets
76 assert_equal 'Praesent et sagittis dui. Vivamus ac diam diam', diff[1].html_line_left
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
77 assert_equal 'Praesent et sagittis dui. Vivamus ac diam diam', diff[1].html_line_right
78
78
79 assert_equal [0, -14], diff[2].offsets
79 assert_equal [0, -14], diff[2].offsets
80 assert_equal '<span>Ut sed</span> auctor justo', diff[2].html_line_left
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
81 assert_equal '<span>xxx</span> auctor justo', diff[2].html_line_right
82
82
83 assert_equal [13, -19], diff[4].offsets
83 assert_equal [13, -19], diff[4].offsets
84 assert_equal [24, -8], diff[6].offsets
84 assert_equal [24, -8], diff[6].offsets
85 assert_equal [37, -1], diff[8].offsets
85 assert_equal [37, -1], diff[8].offsets
86 assert_equal [0, -38], diff[10].offsets
86 assert_equal [0, -38], diff[10].offsets
87
87
88 end
88 end
89
89
90 def test_partials_with_html_entities
90 def test_partials_with_html_entities
91 raw = <<-DIFF
91 raw = <<-DIFF
92 --- test.orig.txt Wed Feb 15 16:10:39 2012
92 --- test.orig.txt Wed Feb 15 16:10:39 2012
93 +++ test.new.txt Wed Feb 15 16:11:25 2012
93 +++ test.new.txt Wed Feb 15 16:11:25 2012
94 @@ -1,5 +1,5 @@
94 @@ -1,5 +1,5 @@
95 Semicolons were mysteriously appearing in code diffs in the repository
95 Semicolons were mysteriously appearing in code diffs in the repository
96
96
97 -void DoSomething(std::auto_ptr<MyClass> myObj)
97 -void DoSomething(std::auto_ptr<MyClass> myObj)
98 +void DoSomething(const MyClass& myObj)
98 +void DoSomething(const MyClass& myObj)
99
99
100 DIFF
100 DIFF
101
101
102 diff = Redmine::UnifiedDiff.new(raw, :type => 'sbs')
102 diff = Redmine::UnifiedDiff.new(raw, :type => 'sbs')
103 assert_equal 1, diff.size
103 assert_equal 1, diff.size
104 assert_equal 'void DoSomething(<span>std::auto_ptr&lt;MyClass&gt;</span> myObj)', diff.first[2].html_line_left
104 assert_equal 'void DoSomething(<span>std::auto_ptr&lt;MyClass&gt;</span> myObj)', diff.first[2].html_line_left
105 assert_equal 'void DoSomething(<span>const MyClass&amp;</span> myObj)', diff.first[2].html_line_right
105 assert_equal 'void DoSomething(<span>const MyClass&amp;</span> myObj)', diff.first[2].html_line_right
106
106
107 diff = Redmine::UnifiedDiff.new(raw, :type => 'inline')
107 diff = Redmine::UnifiedDiff.new(raw, :type => 'inline')
108 assert_equal 1, diff.size
108 assert_equal 1, diff.size
109 assert_equal 'void DoSomething(<span>std::auto_ptr&lt;MyClass&gt;</span> myObj)', diff.first[2].html_line
109 assert_equal 'void DoSomething(<span>std::auto_ptr&lt;MyClass&gt;</span> myObj)', diff.first[2].html_line
110 assert_equal 'void DoSomething(<span>const MyClass&amp;</span> myObj)', diff.first[3].html_line
110 assert_equal 'void DoSomething(<span>const MyClass&amp;</span> myObj)', diff.first[3].html_line
111 end
111 end
112
112
113 def test_line_starting_with_dashes
113 def test_line_starting_with_dashes
114 diff = Redmine::UnifiedDiff.new(<<-DIFF
114 diff = Redmine::UnifiedDiff.new(<<-DIFF
115 --- old.txt Wed Nov 11 14:24:58 2009
115 --- old.txt Wed Nov 11 14:24:58 2009
116 +++ new.txt Wed Nov 11 14:25:02 2009
116 +++ new.txt Wed Nov 11 14:25:02 2009
117 @@ -1,8 +1,4 @@
117 @@ -1,8 +1,4 @@
118 -Lines that starts with dashes:
118 -Lines that starts with dashes:
119 -
119 -
120 -------------------------
120 -------------------------
121 --- file.c
121 --- file.c
122 -------------------------
122 -------------------------
123 +A line that starts with dashes:
123 +A line that starts with dashes:
124
124
125 and removed.
125 and removed.
126
126
127 @@ -23,4 +19,4 @@
127 @@ -23,4 +19,4 @@
128
128
129
129
130
130
131 -Another chunk of change
131 -Another chunk of change
132 +Another chunk of changes
132 +Another chunk of changes
133
133
134 DIFF
134 DIFF
135 )
135 )
136 assert_equal 1, diff.size
136 assert_equal 1, diff.size
137 end
137 end
138
138
139 def test_one_line_new_files
139 def test_one_line_new_files
140 diff = Redmine::UnifiedDiff.new(<<-DIFF
140 diff = Redmine::UnifiedDiff.new(<<-DIFF
141 diff -r 000000000000 -r ea98b14f75f0 README1
141 diff -r 000000000000 -r ea98b14f75f0 README1
142 --- /dev/null
142 --- /dev/null
143 +++ b/README1
143 +++ b/README1
144 @@ -0,0 +1,1 @@
144 @@ -0,0 +1,1 @@
145 +test1
145 +test1
146 diff -r 000000000000 -r ea98b14f75f0 README2
146 diff -r 000000000000 -r ea98b14f75f0 README2
147 --- /dev/null
147 --- /dev/null
148 +++ b/README2
148 +++ b/README2
149 @@ -0,0 +1,1 @@
149 @@ -0,0 +1,1 @@
150 +test2
150 +test2
151 diff -r 000000000000 -r ea98b14f75f0 README3
151 diff -r 000000000000 -r ea98b14f75f0 README3
152 --- /dev/null
152 --- /dev/null
153 +++ b/README3
153 +++ b/README3
154 @@ -0,0 +1,3 @@
154 @@ -0,0 +1,3 @@
155 +test4
155 +test4
156 +test5
156 +test5
157 +test6
157 +test6
158 diff -r 000000000000 -r ea98b14f75f0 README4
158 diff -r 000000000000 -r ea98b14f75f0 README4
159 --- /dev/null
159 --- /dev/null
160 +++ b/README4
160 +++ b/README4
161 @@ -0,0 +1,3 @@
161 @@ -0,0 +1,3 @@
162 +test4
162 +test4
163 +test5
163 +test5
164 +test6
164 +test6
165 DIFF
165 DIFF
166 )
166 )
167 assert_equal 4, diff.size
167 assert_equal 4, diff.size
168 assert_equal "README1", diff[0].file_name
168 assert_equal "README1", diff[0].file_name
169 end
169 end
170
170
171 def test_both_git_diff
171 def test_both_git_diff
172 diff = Redmine::UnifiedDiff.new(<<-DIFF
172 diff = Redmine::UnifiedDiff.new(<<-DIFF
173 # HG changeset patch
173 # HG changeset patch
174 # User test
174 # User test
175 # Date 1348014182 -32400
175 # Date 1348014182 -32400
176 # Node ID d1c871b8ef113df7f1c56d41e6e3bfbaff976e1f
176 # Node ID d1c871b8ef113df7f1c56d41e6e3bfbaff976e1f
177 # Parent 180b6605936cdc7909c5f08b59746ec1a7c99b3e
177 # Parent 180b6605936cdc7909c5f08b59746ec1a7c99b3e
178 modify test1.txt
178 modify test1.txt
179
179
180 diff -r 180b6605936c -r d1c871b8ef11 test1.txt
180 diff -r 180b6605936c -r d1c871b8ef11 test1.txt
181 --- a/test1.txt
181 --- a/test1.txt
182 +++ b/test1.txt
182 +++ b/test1.txt
183 @@ -1,1 +1,1 @@
183 @@ -1,1 +1,1 @@
184 -test1
184 -test1
185 +modify test1
185 +modify test1
186 DIFF
186 DIFF
187 )
187 )
188 assert_equal 1, diff.size
188 assert_equal 1, diff.size
189 assert_equal "test1.txt", diff[0].file_name
189 assert_equal "test1.txt", diff[0].file_name
190 end
190 end
191
191
192 def test_include_a_b_slash
192 def test_include_a_b_slash
193 diff = Redmine::UnifiedDiff.new(<<-DIFF
193 diff = Redmine::UnifiedDiff.new(<<-DIFF
194 --- test1.txt
194 --- test1.txt
195 +++ b/test02.txt
195 +++ b/test02.txt
196 @@ -1 +0,0 @@
196 @@ -1 +0,0 @@
197 -modify test1
197 -modify test1
198 DIFF
198 DIFF
199 )
199 )
200 assert_equal 1, diff.size
200 assert_equal 1, diff.size
201 assert_equal "b/test02.txt", diff[0].file_name
201 assert_equal "b/test02.txt", diff[0].file_name
202
202
203 diff = Redmine::UnifiedDiff.new(<<-DIFF
203 diff = Redmine::UnifiedDiff.new(<<-DIFF
204 --- a/test1.txt
204 --- a/test1.txt
205 +++ a/test02.txt
205 +++ a/test02.txt
206 @@ -1 +0,0 @@
206 @@ -1 +0,0 @@
207 -modify test1
207 -modify test1
208 DIFF
208 DIFF
209 )
209 )
210 assert_equal 1, diff.size
210 assert_equal 1, diff.size
211 assert_equal "a/test02.txt", diff[0].file_name
211 assert_equal "a/test02.txt", diff[0].file_name
212
212
213 diff = Redmine::UnifiedDiff.new(<<-DIFF
213 diff = Redmine::UnifiedDiff.new(<<-DIFF
214 --- a/test1.txt
214 --- a/test1.txt
215 +++ test02.txt
215 +++ test02.txt
216 @@ -1 +0,0 @@
216 @@ -1 +0,0 @@
217 -modify test1
217 -modify test1
218 DIFF
218 DIFF
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
224 private
247 private
225
248
226 def read_diff_fixture(filename)
249 def read_diff_fixture(filename)
227 File.new(File.join(File.dirname(__FILE__), '/../../../fixtures/diffs', filename)).read
250 File.new(File.join(File.dirname(__FILE__), '/../../../fixtures/diffs', filename)).read
228 end
251 end
229 end
252 end
General Comments 0
You need to be logged in to leave comments. Login now