3 # Copyright (C) 2010 Chris Jerdonek (cjerdonek@webkit.org)
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions
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.
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.
25 # Unit tests of prepareParsedPatch().
33 my $diffHashRef1 = { # not a copy, no source revision
34 copiedFromPath => undef,
35 indexPath => "indexPath1",
36 sourceRevision => undef,
37 svnConvertedText => "diff1",
39 my $diffHashRef2 = { # not a copy, has source revision
40 copiedFromPath => undef,
41 indexPath => "indexPath2",
43 svnConvertedText => "diff2",
45 my $diffHashRef3 = { # a copy (copies always have source revision)
46 copiedFromPath => "sourcePath3",
47 indexPath => "indexPath2", # Deliberately choosing same as $diffHashRef2
49 svnConvertedText => "diff3",
55 testName => "zero diffs: empty array",
56 diffHashRefsInput => [],
58 copyDiffHashRefs => [],
59 nonCopyDiffHashRefs => [],
60 sourceRevisionHash => {},
65 testName => "one diff: non-copy, no revision",
66 diffHashRefsInput => [$diffHashRef1],
68 copyDiffHashRefs => [],
69 nonCopyDiffHashRefs => [$diffHashRef1],
70 sourceRevisionHash => {},
75 testName => "one diff: non-copy, has revision",
76 diffHashRefsInput => [$diffHashRef2],
78 copyDiffHashRefs => [],
79 nonCopyDiffHashRefs => [$diffHashRef2],
80 sourceRevisionHash => {
87 testName => "one diff: copy (has revision)",
88 diffHashRefsInput => [$diffHashRef3],
90 copyDiffHashRefs => [$diffHashRef3],
91 nonCopyDiffHashRefs => [],
92 sourceRevisionHash => {
99 testName => "two diffs: two non-copies",
100 diffHashRefsInput => [$diffHashRef1, $diffHashRef2],
102 copyDiffHashRefs => [],
103 nonCopyDiffHashRefs => [$diffHashRef1, $diffHashRef2],
104 sourceRevisionHash => {
111 testName => "two diffs: non-copy and copy",
112 diffHashRefsInput => [$diffHashRef2, $diffHashRef3],
114 copyDiffHashRefs => [$diffHashRef3],
115 nonCopyDiffHashRefs => [$diffHashRef2],
116 sourceRevisionHash => {
124 my $testCasesCount = @testCases;
125 plan(tests => $testCasesCount);
127 foreach my $testCase (@testCases) {
128 my $testName = $testCase->{testName};
129 my @diffHashRefs = @{$testCase->{diffHashRefsInput}};
130 my $expected = $testCase->{expected};
132 my $got = prepareParsedPatch(0, @diffHashRefs);
134 is_deeply($got, $expected, $testName);