1 #!/usr/bin/perl -w 2 # 3 # Copyright (C) 2011 Research In Motion Limited. All rights reserved. 4 # 5 # This library is free software; you can redistribute it and/or 6 # modify it under the terms of the GNU Lesser General Public 7 # License as published by the Free Software Foundation; either 8 # version 2.1 of the License, or (at your option) any later version. 9 # 10 # This library is distributed in the hope that it will be useful, 11 # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 # Lesser General Public License for more details. 14 # 15 # You should have received a copy of the GNU Lesser General Public 16 # License along with this library; if not, write to the Free Software 17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 19 # Unit tests of VCSUtils::parseFirstEOL(). 20 21 use strict; 22 use warnings; 23 24 use Test::Simple tests => 7; 25 use VCSUtils; 26 27 my $title; 28 29 # New test 30 $title = "parseFirstEOL: Empty string."; 31 ok(!defined(firstEOLInString("")), $title); 32 33 # New test 34 $title = "parseFirstEOL: Line without a line ending character"; 35 ok(!defined(firstEOLInString("This line doesn't have a line ending character.")), $title); 36 37 # New test 38 $title = "parseFirstEOL: Line with Windows line ending."; 39 ok(firstEOLInString("This line ends with a Windows line ending.\r\n") eq "\r\n", $title); 40 41 # New test 42 $title = "parseFirstEOL: Line with Unix line ending."; 43 ok(firstEOLInString("This line ends with a Unix line ending.\n") eq "\n", $title); 44 45 # New test 46 $title = "parseFirstEOL: Line with Mac line ending."; 47 ok(firstEOLInString("This line ends with a Mac line ending.\r") eq "\r", $title); 48 49 # New test 50 $title = "parseFirstEOL: Line with Mac line ending followed by line without a line ending."; 51 ok(firstEOLInString("This line ends with a Mac line ending.\rThis line doesn't have a line ending.") eq "\r", $title); 52 53 # New test 54 $title = "parseFirstEOL: Line with a mix of line endings."; 55 ok(firstEOLInString("This line contains a mix of line endings.\r\n\r\n\r\r\n\n\n\n") eq "\r\n", $title); 56 57 sub firstEOLInString 58 { 59 my ($string) = @_; 60 my $fileHandle; 61 open($fileHandle, "<", \$string); 62 return parseFirstEOL($fileHandle); 63 } 64