annotate test/unit/lib/redmine/unified_diff_test.rb @ 245:051f544170fe

* Update to SVN trunk revision 4993
author Chris Cannam
date Thu, 03 Mar 2011 11:42:28 +0000
parents 8661b858af72
children cbce1fd3b1b7
rev   line source
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@119 18 require File.expand_path('../../../../test_helper', __FILE__)
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@245 63 def test_one_line_new_files
Chris@245 64 diff = Redmine::UnifiedDiff.new(<<-DIFF
Chris@245 65 diff -r 000000000000 -r ea98b14f75f0 README1
Chris@245 66 --- /dev/null
Chris@245 67 +++ b/README1
Chris@245 68 @@ -0,0 +1,1 @@
Chris@245 69 +test1
Chris@245 70 diff -r 000000000000 -r ea98b14f75f0 README2
Chris@245 71 --- /dev/null
Chris@245 72 +++ b/README2
Chris@245 73 @@ -0,0 +1,1 @@
Chris@245 74 +test2
Chris@245 75 diff -r 000000000000 -r ea98b14f75f0 README3
Chris@245 76 --- /dev/null
Chris@245 77 +++ b/README3
Chris@245 78 @@ -0,0 +1,3 @@
Chris@245 79 +test4
Chris@245 80 +test5
Chris@245 81 +test6
Chris@245 82 diff -r 000000000000 -r ea98b14f75f0 README4
Chris@245 83 --- /dev/null
Chris@245 84 +++ b/README4
Chris@245 85 @@ -0,0 +1,3 @@
Chris@245 86 +test4
Chris@245 87 +test5
Chris@245 88 +test6
Chris@245 89 DIFF
Chris@245 90 )
Chris@245 91 assert_equal 4, diff.size
Chris@245 92 end
Chris@245 93
Chris@0 94 private
Chris@245 95
Chris@0 96 def read_diff_fixture(filename)
Chris@0 97 File.new(File.join(File.dirname(__FILE__), '/../../../fixtures/diffs', filename)).read
Chris@0 98 end
Chris@0 99 end