3 # Copyright (C) 2011 Research In Motion Limited. All rights reserved.
4 # Copyright (C) 2010 Chris Jerdonek (chris.jerdonek@gmail.com)
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions are
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
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.
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.
32 # Unit tests of VCSUtils::parseChunkRange().
40 my @testCaseHashRefs = (
42 # Invalid and malformed chunk range
44 # FIXME: We should make this set of tests more comprehensive.
46 testName => "[invalid] Empty string",
51 testName => "[invalid] Bogus chunk range",
52 inputText => "@@ this is not valid @@",
56 testName => "[invalid] Chunk range missing -/+ prefix",
57 inputText => "@@ 0,0 1,4 @@",
61 testName => "[invalid] Chunk range missing commas",
62 inputText => "@@ -0 0 +1 4 @@",
66 testName => "[invalid] Chunk range with swapped old and rew ranges",
67 inputText => "@@ +0,0 -1,4 @@",
71 testName => "[invalid] Chunk range with leading junk",
72 inputText => "leading junk @@ -0,0 +1,4 @@",
79 testName => "Line count is 0",
80 inputText => "@@ -0,0 +1,4 @@",
91 testName => "Line count is 1",
92 inputText => "@@ -1 +1,4 @@",
103 testName => "Both original and new line count is 1",
104 inputText => "@@ -1 +1 @@",
109 newStartingLine => 1,
115 testName => "Line count and new line count > 1",
116 inputText => "@@ -1,2 +1,4 @@",
121 newStartingLine => 1,
127 testName => "New line count is 0",
128 inputText => "@@ -1,4 +0,0 @@",
133 newStartingLine => 0,
139 testName => "New line count is 1",
140 inputText => "@@ -1,4 +1 @@",
145 newStartingLine => 1,
151 # Chunk range followed by ending junk
154 testName => "Line count is 0 and chunk range has ending junk",
155 inputText => "@@ -0,0 +1,4 @@ foo()",
160 newStartingLine => 1,
166 testName => "Line count is 1 and chunk range has ending junk",
167 inputText => "@@ -1 +1,4 @@ foo()",
172 newStartingLine => 1,
178 testName => "Both original and new line count is 1 and chunk range has ending junk",
179 inputText => "@@ -1 +1 @@ foo()",
184 newStartingLine => 1,
190 testName => "Line count and new line count > 1 and chunk range has ending junk",
191 inputText => "@@ -1,2 +1,4 @@ foo()",
196 newStartingLine => 1,
202 testName => "New line count is 0 and chunk range has ending junk",
203 inputText => "@@ -1,4 +0,0 @@ foo()",
208 newStartingLine => 0,
214 testName => "New line count is 1 and chunk range has ending junk",
215 inputText => "@@ -1,4 +1 @@ foo()",
220 newStartingLine => 1,
227 my $testCasesCount = @testCaseHashRefs;
228 plan(tests => $testCasesCount);
230 foreach my $testCase (@testCaseHashRefs) {
231 my $testNameStart = "parseChunkRange(): $testCase->{testName}: comparing";
233 my @got = VCSUtils::parseChunkRange($testCase->{inputText});
234 my $expectedReturn = $testCase->{expectedReturn};
236 is_deeply(\@got, $expectedReturn, "$testNameStart return value.");