3 # Copyright (C) Research in Motion Limited 2010. 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 parseSvnPropertyValue().
40 my @testCaseHashRefs = (
43 diffName => "singe-line '+' change",
47 expectedReturn => ["*", undef],
48 expectedNextLine => undef,
52 diffName => "single-line '-' change",
56 expectedReturn => ["*", undef],
57 expectedNextLine => undef,
61 diffName => "'Merged' change",
63 Merged /trunk/Makefile:r33020
65 expectedReturn => ["/trunk/Makefile:r33020", undef],
66 expectedNextLine => undef,
70 diffName => "'Reverse-merged' change",
72 Reverse-merged /trunk/Makefile:r33020
74 expectedReturn => ["/trunk/Makefile:r33020", undef],
75 expectedNextLine => undef,
79 diffName => "single-line '-' change followed by empty line with Unix line endings",
84 expectedReturn => ["*", "\n"],
85 expectedNextLine => undef,
89 diffName => "single-line '-' change followed by empty line with Windows line endings",
90 inputText => toWindowsLineEndings(<<'END',
95 expectedReturn => ["*", "\r\n"],
96 expectedNextLine => undef,
100 diffName => "single-line '-' change followed by the next property",
101 inputText => <<'END',
103 Deleted: svn:executable
105 expectedReturn => ["*", "Deleted: svn:executable\n"],
106 expectedNextLine => undef,
110 diffName => "multi-line '+' change and start of binary patch",
111 inputText => <<'END',
113 long sentence that spans
116 Q1dTBx0AAAB42itg4GlgYJjGwMDDyODMxMDw34GBgQEAJPQDJA==
118 expectedReturn => ["A\nlong sentence that spans\nmultiple lines.", "\n"],
119 expectedNextLine => "Q1dTBx0AAAB42itg4GlgYJjGwMDDyODMxMDw34GBgQEAJPQDJA==\n",
123 diffName => "multi-line '+' change and start of binary patch with Windows line endings",
124 inputText => toWindowsLineEndings(<<'END',
126 long sentence that spans
129 Q1dTBx0AAAB42itg4GlgYJjGwMDDyODMxMDw34GBgQEAJPQDJA==
132 expectedReturn => ["A\r\nlong sentence that spans\r\nmultiple lines.", "\r\n"],
133 expectedNextLine => "Q1dTBx0AAAB42itg4GlgYJjGwMDDyODMxMDw34GBgQEAJPQDJA==\r\n",
137 diffName => "multi-line '-' change followed by '+' single-line change",
138 inputText => <<'END',
140 long sentence that spans
144 expectedReturn => ["A\nlong sentence that spans\nmultiple lines.", " + A single-line.\n"],
145 expectedNextLine => undef,
149 diffName => "multi-line '-' change followed by the next property",
150 inputText => <<'END',
152 long sentence that spans
154 Added: svn:executable
156 expectedReturn => ["A\nlong sentence that spans\nmultiple lines.", "Added: svn:executable\n"],
157 expectedNextLine => undef,
161 diffName => "multi-line '-' change followed by '+' multi-line change",
162 inputText => <<'END',
164 long sentence that spans
167 long sentence that spans
170 expectedReturn => ["A\nlong sentence that spans\nmultiple lines.", " + Another\n"],
171 expectedNextLine => "long sentence that spans\n",
175 diffName => "'Reverse-merged' change followed by 'Merge' change",
176 inputText => <<'END',
177 Reverse-merged /trunk/Makefile:r33020
178 Merged /trunk/Makefile:r41697
180 expectedReturn => ["/trunk/Makefile:r33020", " Merged /trunk/Makefile:r41697\n"],
181 expectedNextLine => undef,
185 diffName => "'Merged' change followed by 'Merge' change",
186 inputText => <<'END',
187 Merged /trunk/Makefile:r33020
188 Merged /trunk/Makefile.shared:r58350
190 expectedReturn => ["/trunk/Makefile:r33020", " Merged /trunk/Makefile.shared:r58350\n"],
191 expectedNextLine => undef,
195 diffName => "'Reverse-merged' change followed by 'Reverse-merged' change",
196 inputText => <<'END',
197 Reverse-merged /trunk/Makefile:r33020
198 Reverse-merged /trunk/Makefile.shared:r58350
200 expectedReturn => ["/trunk/Makefile:r33020", " Reverse-merged /trunk/Makefile.shared:r58350\n"],
201 expectedNextLine => undef,
205 diffName => "'Reverse-merged' change followed by 'Reverse-merged' change followed by 'Merged' change",
206 inputText => <<'END',
207 Reverse-merged /trunk/Makefile:r33020
208 Reverse-merged /trunk/Makefile.shared:r58350
209 Merged /trunk/ChangeLog:r64190
211 expectedReturn => ["/trunk/Makefile:r33020", " Reverse-merged /trunk/Makefile.shared:r58350\n"],
212 expectedNextLine => " Merged /trunk/ChangeLog:r64190\n",
216 my $testCasesCount = @testCaseHashRefs;
217 plan(tests => 2 * $testCasesCount); # Total number of assertions.
219 foreach my $testCase (@testCaseHashRefs) {
220 my $testNameStart = "parseSvnPropertyValue(): $testCase->{diffName}: comparing";
223 open($fileHandle, "<", \$testCase->{inputText});
224 my $line = <$fileHandle>;
226 my @got = VCSUtils::parseSvnPropertyValue($fileHandle, $line);
227 my $expectedReturn = $testCase->{expectedReturn};
229 is_deeply(\@got, $expectedReturn, "$testNameStart return value.");
231 my $gotNextLine = <$fileHandle>;
232 is($gotNextLine, $testCase->{expectedNextLine}, "$testNameStart next read line.");