WebKitTools/Scripts/webkitperl/VCSUtils_unittest/parseSvnPropertyValue.pl
changeset 0 4f2f89ce4247
equal deleted inserted replaced
-1:000000000000 0:4f2f89ce4247
       
     1 #!/usr/bin/perl -w
       
     2 #
       
     3 # Copyright (C) Research in Motion Limited 2010. All Rights Reserved.
       
     4 # Copyright (C) 2010 Chris Jerdonek (chris.jerdonek@gmail.com)
       
     5 #
       
     6 # Redistribution and use in source and binary forms, with or without
       
     7 # modification, are permitted provided that the following conditions are
       
     8 # met:
       
     9 #
       
    10 #     * Redistributions of source code must retain the above copyright
       
    11 # notice, this list of conditions and the following disclaimer.
       
    12 #     * Redistributions in binary form must reproduce the above
       
    13 # copyright notice, this list of conditions and the following disclaimer
       
    14 # in the documentation and/or other materials provided with the
       
    15 # distribution.
       
    16 #     * Neither the name of Apple Computer, Inc. ("Apple") nor the names of
       
    17 # its contributors may be used to endorse or promote products derived
       
    18 # from this software without specific prior written permission.
       
    19 #
       
    20 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
       
    21 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
       
    22 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
       
    23 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
       
    24 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
       
    25 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
       
    26 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
       
    27 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
       
    28 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
       
    29 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
       
    30 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
       
    31 
       
    32 # Unit tests of parseSvnPropertyValue().
       
    33 
       
    34 use strict;
       
    35 use warnings;
       
    36 
       
    37 use Test::More;
       
    38 use VCSUtils;
       
    39 
       
    40 my @testCaseHashRefs = (
       
    41 {
       
    42     # New test
       
    43     diffName => "singe-line '+' change",
       
    44     inputText => <<'END',
       
    45    + *
       
    46 END
       
    47     expectedReturn => ["*", undef],
       
    48     expectedNextLine => undef,
       
    49 },
       
    50 {
       
    51     # New test
       
    52     diffName => "single-line '-' change",
       
    53     inputText => <<'END',
       
    54    - *
       
    55 END
       
    56     expectedReturn => ["*", undef],
       
    57     expectedNextLine => undef,
       
    58 },
       
    59 {
       
    60     # New test
       
    61     diffName => "single-line '-' change followed by empty line",
       
    62     inputText => <<'END',
       
    63    - *
       
    64 
       
    65 END
       
    66     expectedReturn => ["*", "\n"],
       
    67     expectedNextLine => undef,
       
    68 },
       
    69 {
       
    70     # New test
       
    71     diffName => "single-line '-' change followed by the next property",
       
    72     inputText => <<'END',
       
    73    - *
       
    74 Deleted: svn:executable
       
    75 END
       
    76     expectedReturn => ["*", "Deleted: svn:executable\n"],
       
    77     expectedNextLine => undef,
       
    78 },
       
    79 {
       
    80     # New test
       
    81     diffName => "multi-line '+' change and start of binary patch",
       
    82     inputText => <<'END',
       
    83    + A
       
    84 long sentence that spans
       
    85 multiple lines.
       
    86 
       
    87 Q1dTBx0AAAB42itg4GlgYJjGwMDDyODMxMDw34GBgQEAJPQDJA==
       
    88 END
       
    89     expectedReturn => ["A\nlong sentence that spans\nmultiple lines.", "\n"],
       
    90     expectedNextLine => "Q1dTBx0AAAB42itg4GlgYJjGwMDDyODMxMDw34GBgQEAJPQDJA==\n",
       
    91 },
       
    92 {
       
    93     # New test
       
    94     diffName => "multi-line '-' change followed by '+' single-line change",
       
    95     inputText => <<'END',
       
    96    - A
       
    97 long sentence that spans
       
    98 multiple lines.
       
    99    + A single-line.
       
   100 END
       
   101     expectedReturn => ["A\nlong sentence that spans\nmultiple lines.", "   + A single-line.\n"],
       
   102     expectedNextLine => undef,
       
   103 },
       
   104 {
       
   105     # New test
       
   106     diffName => "multi-line '-' change followed by the next property",
       
   107     inputText => <<'END',
       
   108    - A
       
   109 long sentence that spans
       
   110 multiple lines.
       
   111 Added: svn:executable
       
   112 END
       
   113     expectedReturn => ["A\nlong sentence that spans\nmultiple lines.", "Added: svn:executable\n"],
       
   114     expectedNextLine => undef,
       
   115 },
       
   116 {
       
   117     # New test
       
   118     diffName => "multi-line '-' change followed by '+' multi-line change",
       
   119     inputText => <<'END',
       
   120    - A
       
   121 long sentence that spans
       
   122 multiple lines.
       
   123    + Another
       
   124 long sentence that spans
       
   125 multiple lines.
       
   126 END
       
   127     expectedReturn => ["A\nlong sentence that spans\nmultiple lines.", "   + Another\n"],
       
   128     expectedNextLine => "long sentence that spans\n",
       
   129 },
       
   130 );
       
   131 
       
   132 my $testCasesCount = @testCaseHashRefs;
       
   133 plan(tests => 2 * $testCasesCount); # Total number of assertions.
       
   134 
       
   135 foreach my $testCase (@testCaseHashRefs) {
       
   136     my $testNameStart = "parseSvnPropertyValue(): $testCase->{diffName}: comparing";
       
   137 
       
   138     my $fileHandle;
       
   139     open($fileHandle, "<", \$testCase->{inputText});
       
   140     my $line = <$fileHandle>;
       
   141 
       
   142     my @got = VCSUtils::parseSvnPropertyValue($fileHandle, $line);
       
   143     my $expectedReturn = $testCase->{expectedReturn};
       
   144 
       
   145     is_deeply(\@got, $expectedReturn, "$testNameStart return value.");
       
   146 
       
   147     my $gotNextLine = <$fileHandle>;
       
   148     is($gotNextLine, $testCase->{expectedNextLine},  "$testNameStart next read line.");
       
   149 }