Home | History | Annotate | Download | only in VCSUtils_unittest
      1 #!/usr/bin/perl -w
      2 #
      3 # Copyright (C) 2010 Chris Jerdonek (cjerdonek (at] webkit.org)
      4 #
      5 # Redistribution and use in source and binary forms, with or without
      6 # modification, are permitted provided that the following conditions
      7 # are met:
      8 # 1.  Redistributions of source code must retain the above copyright
      9 #     notice, this list of conditions and the following disclaimer.
     10 # 2.  Redistributions in binary form must reproduce the above copyright
     11 #     notice, this list of conditions and the following disclaimer in the
     12 #     documentation and/or other materials provided with the distribution.
     13 #
     14 # THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
     15 # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     16 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     17 # DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
     18 # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     19 # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     20 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
     21 # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     22 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
     23 # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     24 
     25 # Unit tests of prepareParsedPatch().
     26 
     27 use strict;
     28 use warnings;
     29 
     30 use Test::More;
     31 use VCSUtils;
     32 
     33 my $diffHashRef1 = { # not a copy, no source revision
     34     copiedFromPath => undef,
     35     indexPath => "indexPath1",
     36     sourceRevision => undef,
     37     svnConvertedText => "diff1",
     38 };
     39 my $diffHashRef2 = { # not a copy, has source revision
     40     copiedFromPath => undef,
     41     indexPath => "indexPath2",
     42     sourceRevision => 20,
     43     svnConvertedText => "diff2",
     44 };
     45 my $diffHashRef3 = { # a copy (copies always have source revision)
     46     copiedFromPath => "sourcePath3",
     47     indexPath => "indexPath2", # Deliberately choosing same as $diffHashRef2
     48     sourceRevision => 3,
     49     svnConvertedText => "diff3",
     50 };
     51 
     52 my @testCases = (
     53 {
     54     # New test
     55     testName => "zero diffs: empty array",
     56     diffHashRefsInput => [],
     57     expected => {
     58         copyDiffHashRefs => [],
     59         nonCopyDiffHashRefs => [],
     60         sourceRevisionHash => {},
     61     },
     62 },
     63 {
     64     # New test
     65     testName => "one diff: non-copy, no revision",
     66     diffHashRefsInput => [$diffHashRef1],
     67     expected => {
     68         copyDiffHashRefs => [],
     69         nonCopyDiffHashRefs => [$diffHashRef1],
     70         sourceRevisionHash => {},
     71     },
     72 },
     73 {
     74     # New test
     75     testName => "one diff: non-copy, has revision",
     76     diffHashRefsInput => [$diffHashRef2],
     77     expected => {
     78         copyDiffHashRefs => [],
     79         nonCopyDiffHashRefs => [$diffHashRef2],
     80         sourceRevisionHash => {
     81             "indexPath2" => 20,
     82         }
     83     },
     84 },
     85 {
     86     # New test
     87     testName => "one diff: copy (has revision)",
     88     diffHashRefsInput => [$diffHashRef3],
     89     expected => {
     90         copyDiffHashRefs => [$diffHashRef3],
     91         nonCopyDiffHashRefs => [],
     92         sourceRevisionHash => {
     93             "sourcePath3" => 3,
     94         }
     95     },
     96 },
     97 {
     98     # New test
     99     testName => "two diffs: two non-copies",
    100     diffHashRefsInput => [$diffHashRef1, $diffHashRef2],
    101     expected => {
    102         copyDiffHashRefs => [],
    103         nonCopyDiffHashRefs => [$diffHashRef1, $diffHashRef2],
    104         sourceRevisionHash => {
    105             "indexPath2" => 20,
    106         }
    107     },
    108 },
    109 {
    110     # New test
    111     testName => "two diffs: non-copy and copy",
    112     diffHashRefsInput => [$diffHashRef2, $diffHashRef3],
    113     expected => {
    114         copyDiffHashRefs => [$diffHashRef3],
    115         nonCopyDiffHashRefs => [$diffHashRef2],
    116         sourceRevisionHash => {
    117             "sourcePath3" => 3,
    118             "indexPath2" => 20,
    119         }
    120     },
    121 },
    122 );
    123 
    124 my $testCasesCount = @testCases;
    125 plan(tests => $testCasesCount);
    126 
    127 foreach my $testCase (@testCases) {
    128     my $testName = $testCase->{testName};
    129     my @diffHashRefs = @{$testCase->{diffHashRefsInput}};
    130     my $expected = $testCase->{expected};
    131 
    132     my $got = prepareParsedPatch(0, @diffHashRefs);
    133 
    134     is_deeply($got, $expected, $testName);
    135 }
    136 
    137