Chris@0: # Redmine - project management software Chris@0: # Copyright (C) 2006-2008 Jean-Philippe Lang Chris@0: # Chris@0: # This program is free software; you can redistribute it and/or Chris@0: # modify it under the terms of the GNU General Public License Chris@0: # as published by the Free Software Foundation; either version 2 Chris@0: # of the License, or (at your option) any later version. Chris@0: # Chris@0: # This program is distributed in the hope that it will be useful, Chris@0: # but WITHOUT ANY WARRANTY; without even the implied warranty of Chris@0: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Chris@0: # GNU General Public License for more details. Chris@0: # Chris@0: # You should have received a copy of the GNU General Public License Chris@0: # along with this program; if not, write to the Free Software Chris@0: # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Chris@0: Chris@0: require File.dirname(__FILE__) + '/../../../test_helper' Chris@0: Chris@0: class Redmine::UnifiedDiffTest < ActiveSupport::TestCase Chris@0: Chris@0: def setup Chris@0: end Chris@0: Chris@0: def test_subversion_diff Chris@0: diff = Redmine::UnifiedDiff.new(read_diff_fixture('subversion.diff')) Chris@0: # number of files Chris@0: assert_equal 4, diff.size Chris@0: assert diff.detect {|file| file.file_name =~ %r{^config/settings.yml}} Chris@0: end Chris@0: Chris@0: def test_truncate_diff Chris@0: diff = Redmine::UnifiedDiff.new(read_diff_fixture('subversion.diff'), :max_lines => 20) Chris@0: assert_equal 2, diff.size Chris@0: end Chris@0: Chris@0: def test_line_starting_with_dashes Chris@0: diff = Redmine::UnifiedDiff.new(<<-DIFF Chris@0: --- old.txt Wed Nov 11 14:24:58 2009 Chris@0: +++ new.txt Wed Nov 11 14:25:02 2009 Chris@0: @@ -1,8 +1,4 @@ Chris@0: -Lines that starts with dashes: Chris@0: - Chris@0: ------------------------- Chris@0: --- file.c Chris@0: ------------------------- Chris@0: +A line that starts with dashes: Chris@0: Chris@0: and removed. Chris@0: Chris@0: @@ -23,4 +19,4 @@ Chris@0: Chris@0: Chris@0: Chris@0: -Another chunk of change Chris@0: +Another chunk of changes Chris@0: Chris@0: DIFF Chris@0: ) Chris@0: assert_equal 1, diff.size Chris@0: end Chris@0: Chris@0: private Chris@0: Chris@0: def read_diff_fixture(filename) Chris@0: File.new(File.join(File.dirname(__FILE__), '/../../../fixtures/diffs', filename)).read Chris@0: end Chris@0: end