@@ -27,11 +27,10 module Redmine | |||||
27 | @truncated = false |
|
27 | @truncated = false | |
28 | diff_table = DiffTable.new(diff_type) |
|
28 | diff_table = DiffTable.new(diff_type) | |
29 | diff.each do |line| |
|
29 | diff.each do |line| | |
30 | if line =~ /^(---|\+\+\+) (.*)$/ |
|
30 | unless diff_table.add_line line | |
31 | self << diff_table if diff_table.length > 1 |
|
31 | self << diff_table if diff_table.length > 1 | |
32 | diff_table = DiffTable.new(diff_type) |
|
32 | diff_table = DiffTable.new(diff_type) | |
33 | end |
|
33 | end | |
34 | diff_table.add_line line |
|
|||
35 | lines += 1 |
|
34 | lines += 1 | |
36 | if options[:max_lines] && lines > options[:max_lines] |
|
35 | if options[:max_lines] && lines > options[:max_lines] | |
37 | @truncated = true |
|
36 | @truncated = true | |
@@ -61,11 +60,11 module Redmine | |||||
61 | end |
|
60 | end | |
62 |
|
61 | |||
63 | # Function for add a line of this Diff |
|
62 | # Function for add a line of this Diff | |
|
63 | # Returns false when the diff ends | |||
64 | def add_line(line) |
|
64 | def add_line(line) | |
65 | unless @parsing |
|
65 | unless @parsing | |
66 | if line =~ /^(---|\+\+\+) (.*)$/ |
|
66 | if line =~ /^(---|\+\+\+) (.*)$/ | |
67 | @file_name = $2 |
|
67 | @file_name = $2 | |
68 | return false |
|
|||
69 | elsif line =~ /^@@ (\+|\-)(\d+)(,\d+)? (\+|\-)(\d+)(,\d+)? @@/ |
|
68 | elsif line =~ /^@@ (\+|\-)(\d+)(,\d+)? (\+|\-)(\d+)(,\d+)? @@/ | |
70 | @line_num_l = $2.to_i |
|
69 | @line_num_l = $2.to_i | |
71 | @line_num_r = $5.to_i |
|
70 | @line_num_r = $5.to_i |
@@ -33,6 +33,32 class Redmine::UnifiedDiffTest < ActiveSupport::TestCase | |||||
33 | diff = Redmine::UnifiedDiff.new(read_diff_fixture('subversion.diff'), :max_lines => 20) |
|
33 | diff = Redmine::UnifiedDiff.new(read_diff_fixture('subversion.diff'), :max_lines => 20) | |
34 | assert_equal 2, diff.size |
|
34 | assert_equal 2, diff.size | |
35 | end |
|
35 | end | |
|
36 | ||||
|
37 | def test_line_starting_with_dashes | |||
|
38 | diff = Redmine::UnifiedDiff.new(<<-DIFF | |||
|
39 | --- old.txt Wed Nov 11 14:24:58 2009 | |||
|
40 | +++ new.txt Wed Nov 11 14:25:02 2009 | |||
|
41 | @@ -1,8 +1,4 @@ | |||
|
42 | -Lines that starts with dashes: | |||
|
43 | - | |||
|
44 | ------------------------- | |||
|
45 | --- file.c | |||
|
46 | ------------------------- | |||
|
47 | +A line that starts with dashes: | |||
|
48 | ||||
|
49 | and removed. | |||
|
50 | ||||
|
51 | @@ -23,4 +19,4 @@ | |||
|
52 | ||||
|
53 | ||||
|
54 | ||||
|
55 | -Another chunk of change | |||
|
56 | +Another chunk of changes | |||
|
57 | ||||
|
58 | DIFF | |||
|
59 | ) | |||
|
60 | assert_equal 1, diff.size | |||
|
61 | end | |||
36 |
|
62 | |||
37 | private |
|
63 | private | |
38 |
|
64 |
General Comments 0
You need to be logged in to leave comments.
Login now