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 parseSvnProperty().
40 my @testCaseHashRefs = (
46 diffName => "simple: add svn:executable",
53 name => "svn:executable",
54 propertyChangeDelta => 1,
58 expectedNextLine => undef,
62 diffName => "simple: delete svn:executable",
64 Deleted: svn:executable
69 name => "svn:executable",
70 propertyChangeDelta => -1,
74 expectedNextLine => undef,
78 diffName => "simple: add svn:mergeinfo",
81 Merged /trunk/Makefile:r33020
85 name => "svn:mergeinfo",
86 propertyChangeDelta => 1,
87 value => "/trunk/Makefile:r33020",
90 expectedNextLine => undef,
94 diffName => "simple: delete svn:mergeinfo",
96 Deleted: svn:mergeinfo
97 Reverse-merged /trunk/Makefile:r33020
101 name => "svn:mergeinfo",
102 propertyChangeDelta => -1,
103 value => "/trunk/Makefile:r33020",
106 expectedNextLine => undef,
110 diffName => "simple: modified svn:mergeinfo",
111 inputText => <<'END',
112 Modified: svn:mergeinfo
113 Reverse-merged /trunk/Makefile:r33020
114 Merged /trunk/Makefile:r41697
118 name => "svn:mergeinfo",
119 propertyChangeDelta => 1,
120 value => "/trunk/Makefile:r41697",
123 expectedNextLine => undef,
126 # Using SVN 1.4 syntax
130 diffName => "simple: modified svn:mergeinfo using SVN 1.4 syntax",
131 inputText => <<'END',
133 Reverse-merged /trunk/Makefile:r33020
134 Merged /trunk/Makefile:r41697
138 name => "svn:mergeinfo",
139 propertyChangeDelta => 1,
140 value => "/trunk/Makefile:r41697",
143 expectedNextLine => undef,
147 diffName => "simple: delete svn:executable using SVN 1.4 syntax",
148 inputText => <<'END',
154 name => "svn:executable",
155 propertyChangeDelta => -1,
159 expectedNextLine => undef,
163 diffName => "simple: add svn:executable using SVN 1.4 syntax",
164 inputText => <<'END',
170 name => "svn:executable",
171 propertyChangeDelta => 1,
175 expectedNextLine => undef,
178 # Property value followed by empty line and start of next diff
182 diffName => "add svn:executable, followed by empty line and start of next diff",
183 inputText => <<'END',
184 Added: svn:executable
187 Index: Makefile.shared
191 name => "svn:executable",
192 propertyChangeDelta => 1,
196 expectedNextLine => "Index: Makefile.shared\n",
200 diffName => "add svn:executable, followed by empty line and start of next diff using Windows line endings",
201 inputText => toWindowsLineEndings(<<'END',
202 Added: svn:executable
205 Index: Makefile.shared
210 name => "svn:executable",
211 propertyChangeDelta => 1,
215 expectedNextLine => "Index: Makefile.shared\r\n",
219 diffName => "add svn:executable, followed by empty line and start of next property diff",
220 inputText => <<'END',
221 Added: svn:executable
224 Property changes on: Makefile.shared
228 name => "svn:executable",
229 propertyChangeDelta => 1,
233 expectedNextLine => "Property changes on: Makefile.shared\n",
237 diffName => "add svn:executable, followed by empty line and start of next property diff using Windows line endings",
238 inputText => toWindowsLineEndings(<<'END',
239 Added: svn:executable
242 Property changes on: Makefile.shared
247 name => "svn:executable",
248 propertyChangeDelta => 1,
252 expectedNextLine => "Property changes on: Makefile.shared\r\n",
256 diffName => "multi-line '+' change, followed by empty line and start of next diff",
257 inputText => <<'END',
260 long sentence that spans
263 Index: Makefile.shared
267 name => "documentation",
268 propertyChangeDelta => 1,
269 value => "A\nlong sentence that spans\nmultiple lines.",
272 expectedNextLine => "Index: Makefile.shared\n",
276 diffName => "multi-line '+' change, followed by empty line and start of next diff using Windows line endings",
277 inputText => toWindowsLineEndings(<<'END',
280 long sentence that spans
283 Index: Makefile.shared
288 name => "documentation",
289 propertyChangeDelta => 1,
290 value => "A\r\nlong sentence that spans\r\nmultiple lines.",
293 expectedNextLine => "Index: Makefile.shared\r\n",
297 diffName => "multi-line '+' change, followed by empty line and start of next property diff",
298 inputText => <<'END',
301 long sentence that spans
304 Property changes on: Makefile.shared
308 name => "documentation",
309 propertyChangeDelta => 1,
310 value => "A\nlong sentence that spans\nmultiple lines.",
313 expectedNextLine => "Property changes on: Makefile.shared\n",
317 diffName => "multi-line '+' change, followed by empty line and start of next property diff using Windows line endings",
318 inputText => toWindowsLineEndings(<<'END',
321 long sentence that spans
324 Property changes on: Makefile.shared
329 name => "documentation",
330 propertyChangeDelta => 1,
331 value => "A\r\nlong sentence that spans\r\nmultiple lines.",
334 expectedNextLine => "Property changes on: Makefile.shared\r\n",
337 # Property value followed by empty line and start of binary patch
341 diffName => "add svn:executable, followed by empty line and start of binary patch",
342 inputText => <<'END',
343 Added: svn:executable
346 Q1dTBx0AAAB42itg4GlgYJjGwMDDyODMxMDw34GBgQEAJPQDJA==
350 name => "svn:executable",
351 propertyChangeDelta => 1,
355 expectedNextLine => "Q1dTBx0AAAB42itg4GlgYJjGwMDDyODMxMDw34GBgQEAJPQDJA==\n",
359 diffName => "add svn:executable, followed by empty line and start of binary patch using Windows line endings",
360 inputText => toWindowsLineEndings(<<'END',
361 Added: svn:executable
364 Q1dTBx0AAAB42itg4GlgYJjGwMDDyODMxMDw34GBgQEAJPQDJA==
369 name => "svn:executable",
370 propertyChangeDelta => 1,
374 expectedNextLine => "Q1dTBx0AAAB42itg4GlgYJjGwMDDyODMxMDw34GBgQEAJPQDJA==\r\n",
378 diffName => "multi-line '+' change, followed by empty line and start of binary patch",
379 inputText => <<'END',
382 long sentence that spans
385 Q1dTBx0AAAB42itg4GlgYJjGwMDDyODMxMDw34GBgQEAJPQDJA==
389 name => "documentation",
390 propertyChangeDelta => 1,
391 value => "A\nlong sentence that spans\nmultiple lines.",
394 expectedNextLine => "Q1dTBx0AAAB42itg4GlgYJjGwMDDyODMxMDw34GBgQEAJPQDJA==\n",
398 diffName => "multi-line '+' change, followed by empty line and start of binary patch using Windows line endings",
399 inputText => toWindowsLineEndings(<<'END',
402 long sentence that spans
405 Q1dTBx0AAAB42itg4GlgYJjGwMDDyODMxMDw34GBgQEAJPQDJA==
410 name => "documentation",
411 propertyChangeDelta => 1,
412 value => "A\r\nlong sentence that spans\r\nmultiple lines.",
415 expectedNextLine => "Q1dTBx0AAAB42itg4GlgYJjGwMDDyODMxMDw34GBgQEAJPQDJA==\r\n",
419 diffName => "multi-line '-' change, followed by multi-line '+' change, empty line, and start of binary patch",
420 inputText => <<'END',
421 Modified: documentation
423 long sentence that spans
426 long sentence that spans
429 Q1dTBx0AAAB42itg4GlgYJjGwMDDyODMxMDw34GBgQEAJPQDJA==
433 name => "documentation",
434 propertyChangeDelta => 1,
435 value => "Another\nlong sentence that spans\nmultiple lines.",
438 expectedNextLine => "Q1dTBx0AAAB42itg4GlgYJjGwMDDyODMxMDw34GBgQEAJPQDJA==\n",
442 diffName => "multi-line '-' change, followed by multi-line '+' change, empty line, and start of binary patch using Windows line endings",
443 inputText => toWindowsLineEndings(<<'END',
444 Modified: documentation
446 long sentence that spans
449 long sentence that spans
452 Q1dTBx0AAAB42itg4GlgYJjGwMDDyODMxMDw34GBgQEAJPQDJA==
457 name => "documentation",
458 propertyChangeDelta => 1,
459 value => "Another\r\nlong sentence that spans\r\nmultiple lines.",
462 expectedNextLine => "Q1dTBx0AAAB42itg4GlgYJjGwMDDyODMxMDw34GBgQEAJPQDJA==\r\n",
465 # Successive properties
469 diffName => "single-line '+' change followed by custom property with single-line '+' change",
470 inputText => <<'END',
471 Added: svn:executable
478 name => "svn:executable",
479 propertyChangeDelta => 1,
482 "Added: documentation\n"],
483 expectedNextLine => " + A sentence.\n",
487 diffName => "multi-line '+' change, followed by svn:executable",
488 inputText => <<'END',
491 long sentence that spans
498 name => "documentation",
499 propertyChangeDelta => 1,
500 value => "A\nlong sentence that spans\nmultiple lines.",
502 "Name: svn:executable\n"],
503 expectedNextLine => " + *\n",
507 diffName => "multi-line '-' change, followed by multi-line '+' change and add svn:executable",
508 inputText => <<'END',
509 Modified: documentation
511 long sentence that spans
514 long sentence that spans
516 Added: svn:executable
521 name => "documentation",
522 propertyChangeDelta => 1,
523 value => "Another\nlong sentence that spans\nmultiple lines.",
525 "Added: svn:executable\n"],
526 expectedNextLine => " + *\n",
530 diffName => "'Merged' change followed by 'Merged' change",
531 inputText => <<'END',
533 Merged /trunk/Makefile:r33020
534 Merged /trunk/Makefile.shared:r58350
538 name => "svn:mergeinfo",
539 propertyChangeDelta => 1,
540 value => "/trunk/Makefile.shared:r58350",
543 expectedNextLine => undef,
547 diffName => "'Reverse-merged' change followed by 'Reverse-merged' change",
548 inputText => <<'END',
549 Deleted: svn:mergeinfo
550 Reverse-merged /trunk/Makefile:r33020
551 Reverse-merged /trunk/Makefile.shared:r58350
555 name => "svn:mergeinfo",
556 propertyChangeDelta => -1,
557 value => "/trunk/Makefile.shared:r58350",
560 expectedNextLine => undef,
563 # Property values with trailing new lines.
565 # FIXME: We do not support property values with trailing new lines, since it is difficult to
566 # disambiguate them from the empty line that preceeds the contents of a binary patch as
567 # in the test case (above): "multi-line '+' change, followed by empty line and start of binary patch".
570 diffName => "single-line '+' with trailing new line",
571 inputText => <<'END',
578 name => "documentation",
579 propertyChangeDelta => 1,
580 value => "A sentence.",
583 expectedNextLine => undef,
587 diffName => "single-line '+' with trailing new line using Windows line endings",
588 inputText => toWindowsLineEndings(<<'END',
596 name => "documentation",
597 propertyChangeDelta => 1,
598 value => "A sentence.",
601 expectedNextLine => undef,
605 diffName => "single-line '+' with trailing new line, followed by empty line and start of binary patch",
606 inputText => <<'END',
611 Q1dTBx0AAAB42itg4GlgYJjGwMDDyODMxMDw34GBgQEAJPQDJA==
615 name => "documentation",
616 propertyChangeDelta => 1,
617 value => "A sentence.",
620 expectedNextLine => "\n",
624 diffName => "single-line '+' with trailing new line, followed by empty line and start of binary patch using Windows line endings",
625 inputText => toWindowsLineEndings(<<'END',
630 Q1dTBx0AAAB42itg4GlgYJjGwMDDyODMxMDw34GBgQEAJPQDJA==
635 name => "documentation",
636 propertyChangeDelta => 1,
637 value => "A sentence.",
640 expectedNextLine => "\r\n",
644 diffName => "single-line '-' change with trailing new line, and single-line '+' change",
645 inputText => <<'END',
646 Modified: documentation
653 name => "documentation",
654 propertyChangeDelta => -1, # Since we only interpret the '-' property.
655 value => "A long sentence.",
658 expectedNextLine => " + A sentence.\n",
662 diffName => "single-line '-' change with trailing new line, and single-line '+' change using Windows line endings",
663 inputText => toWindowsLineEndings(<<'END',
664 Modified: documentation
672 name => "documentation",
673 propertyChangeDelta => -1, # Since we only interpret the '-' property.
674 value => "A long sentence.",
677 expectedNextLine => " + A sentence.\r\n",
681 diffName => "multi-line '-' change with trailing new line, and multi-line '+' change",
682 inputText => <<'END',
683 Modified: documentation
685 long sentence that spans
689 long sentence that spans
694 name => "documentation",
695 propertyChangeDelta => -1, # Since we only interpret the '-' property.
696 value => "A\nlong sentence that spans\nmultiple lines.",
699 expectedNextLine => " + Another\n",
703 diffName => "multi-line '-' change with trailing new line, and multi-line '+' change using Windows line endings",
704 inputText => toWindowsLineEndings(<<'END',
705 Modified: documentation
707 long sentence that spans
711 long sentence that spans
717 name => "documentation",
718 propertyChangeDelta => -1, # Since we only interpret the '-' property.
719 value => "A\r\nlong sentence that spans\r\nmultiple lines.",
722 expectedNextLine => " + Another\r\n",
726 my $testCasesCount = @testCaseHashRefs;
727 plan(tests => 2 * $testCasesCount); # Total number of assertions.
729 foreach my $testCase (@testCaseHashRefs) {
730 my $testNameStart = "parseSvnProperty(): $testCase->{diffName}: comparing";
733 open($fileHandle, "<", \$testCase->{inputText});
734 my $line = <$fileHandle>;
736 my @got = VCSUtils::parseSvnProperty($fileHandle, $line);
737 my $expectedReturn = $testCase->{expectedReturn};
739 is_deeply(\@got, $expectedReturn, "$testNameStart return value.");
741 my $gotNextLine = <$fileHandle>;
742 is($gotNextLine, $testCase->{expectedNextLine}, "$testNameStart next read line.");