summaryrefslogtreecommitdiffstats
path: root/Tools/Scripts/webkitperl/VCSUtils_unittest/parseFirstEOL.pl
blob: 367ad1d4996ee8a6384a6818f754f2f604b94064 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/perl -w
#
# Copyright (C) 2011 Research In Motion Limited. All rights reserved.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
# 
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
# 
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

# Unit tests of VCSUtils::parseFirstEOL().

use strict;
use warnings;

use Test::Simple tests => 7;
use VCSUtils;

my $title;

# New test
$title = "parseFirstEOL: Empty string.";
ok(!defined(firstEOLInString("")), $title);

# New test
$title = "parseFirstEOL: Line without a line ending character";
ok(!defined(firstEOLInString("This line doesn't have a line ending character.")), $title);

# New test
$title = "parseFirstEOL: Line with Windows line ending.";
ok(firstEOLInString("This line ends with a Windows line ending.\r\n") eq "\r\n", $title);

# New test
$title = "parseFirstEOL: Line with Unix line ending.";
ok(firstEOLInString("This line ends with a Unix line ending.\n") eq "\n", $title);

# New test
$title = "parseFirstEOL: Line with Mac line ending.";
ok(firstEOLInString("This line ends with a Mac line ending.\r") eq "\r", $title);

# New test
$title = "parseFirstEOL: Line with Mac line ending followed by line without a line ending.";
ok(firstEOLInString("This line ends with a Mac line ending.\rThis line doesn't have a line ending.") eq "\r", $title);

# New test
$title = "parseFirstEOL: Line with a mix of line endings.";
ok(firstEOLInString("This line contains a mix of line endings.\r\n\r\n\r\r\n\n\n\n") eq "\r\n", $title);

sub firstEOLInString
{
    my ($string) = @_;
    my $fileHandle;
    open($fileHandle, "<", \$string);
    return parseFirstEOL($fileHandle);
}