initial import
[vuplus_webkit] / Tools / Scripts / webkitperl / VCSUtils_unittest / parseSvnPropertyValue.pl
1 #!/usr/bin/perl -w
2 #
3 # Copyright (C) Research in Motion Limited 2010. All Rights Reserved.
4 # Copyright (C) 2010 Chris Jerdonek (chris.jerdonek@gmail.com)
5 #
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions are
8 # met:
9 #
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
15 # distribution.
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.
19 #
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.
31
32 # Unit tests of parseSvnPropertyValue().
33
34 use strict;
35 use warnings;
36
37 use Test::More;
38 use VCSUtils;
39
40 my @testCaseHashRefs = (
41 {
42     # New test
43     diffName => "singe-line '+' change",
44     inputText => <<'END',
45    + *
46 END
47     expectedReturn => ["*", undef],
48     expectedNextLine => undef,
49 },
50 {
51     # New test
52     diffName => "single-line '-' change",
53     inputText => <<'END',
54    - *
55 END
56     expectedReturn => ["*", undef],
57     expectedNextLine => undef,
58 },
59 {
60     # New test
61     diffName => "'Merged' change",
62     inputText => <<'END',
63    Merged /trunk/Makefile:r33020
64 END
65     expectedReturn => ["/trunk/Makefile:r33020", undef],
66     expectedNextLine => undef,
67 },
68 {
69     # New test
70     diffName => "'Reverse-merged' change",
71     inputText => <<'END',
72    Reverse-merged /trunk/Makefile:r33020
73 END
74     expectedReturn => ["/trunk/Makefile:r33020", undef],
75     expectedNextLine => undef,
76 },
77 {
78     # New test
79     diffName => "single-line '-' change followed by empty line with Unix line endings",
80     inputText => <<'END',
81    - *
82
83 END
84     expectedReturn => ["*", "\n"],
85     expectedNextLine => undef,
86 },
87 {
88     # New test
89     diffName => "single-line '-' change followed by empty line with Windows line endings",
90     inputText => toWindowsLineEndings(<<'END',
91    - *
92
93 END
94 ),
95     expectedReturn => ["*", "\r\n"],
96     expectedNextLine => undef,
97 },
98 {
99     # New test
100     diffName => "single-line '-' change followed by the next property",
101     inputText => <<'END',
102    - *
103 Deleted: svn:executable
104 END
105     expectedReturn => ["*", "Deleted: svn:executable\n"],
106     expectedNextLine => undef,
107 },
108 {
109     # New test
110     diffName => "multi-line '+' change and start of binary patch",
111     inputText => <<'END',
112    + A
113 long sentence that spans
114 multiple lines.
115
116 Q1dTBx0AAAB42itg4GlgYJjGwMDDyODMxMDw34GBgQEAJPQDJA==
117 END
118     expectedReturn => ["A\nlong sentence that spans\nmultiple lines.", "\n"],
119     expectedNextLine => "Q1dTBx0AAAB42itg4GlgYJjGwMDDyODMxMDw34GBgQEAJPQDJA==\n",
120 },
121 {
122     # New test
123     diffName => "multi-line '+' change and start of binary patch with Windows line endings",
124     inputText => toWindowsLineEndings(<<'END',
125    + A
126 long sentence that spans
127 multiple lines.
128
129 Q1dTBx0AAAB42itg4GlgYJjGwMDDyODMxMDw34GBgQEAJPQDJA==
130 END
131 ),
132     expectedReturn => ["A\r\nlong sentence that spans\r\nmultiple lines.", "\r\n"],
133     expectedNextLine => "Q1dTBx0AAAB42itg4GlgYJjGwMDDyODMxMDw34GBgQEAJPQDJA==\r\n",
134 },
135 {
136     # New test
137     diffName => "multi-line '-' change followed by '+' single-line change",
138     inputText => <<'END',
139    - A
140 long sentence that spans
141 multiple lines.
142    + A single-line.
143 END
144     expectedReturn => ["A\nlong sentence that spans\nmultiple lines.", "   + A single-line.\n"],
145     expectedNextLine => undef,
146 },
147 {
148     # New test
149     diffName => "multi-line '-' change followed by the next property",
150     inputText => <<'END',
151    - A
152 long sentence that spans
153 multiple lines.
154 Added: svn:executable
155 END
156     expectedReturn => ["A\nlong sentence that spans\nmultiple lines.", "Added: svn:executable\n"],
157     expectedNextLine => undef,
158 },
159 {
160     # New test
161     diffName => "multi-line '-' change followed by '+' multi-line change",
162     inputText => <<'END',
163    - A
164 long sentence that spans
165 multiple lines.
166    + Another
167 long sentence that spans
168 multiple lines.
169 END
170     expectedReturn => ["A\nlong sentence that spans\nmultiple lines.", "   + Another\n"],
171     expectedNextLine => "long sentence that spans\n",
172 },
173 {
174     # New test
175     diffName => "'Reverse-merged' change followed by 'Merge' change",
176     inputText => <<'END',
177    Reverse-merged /trunk/Makefile:r33020
178    Merged /trunk/Makefile:r41697
179 END
180     expectedReturn => ["/trunk/Makefile:r33020", "   Merged /trunk/Makefile:r41697\n"],
181     expectedNextLine => undef,
182 },
183 {
184     # New test
185     diffName => "'Merged' change followed by 'Merge' change",
186     inputText => <<'END',
187    Merged /trunk/Makefile:r33020
188    Merged /trunk/Makefile.shared:r58350
189 END
190     expectedReturn => ["/trunk/Makefile:r33020", "   Merged /trunk/Makefile.shared:r58350\n"],
191     expectedNextLine => undef,
192 },
193 {
194     # New test
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
199 END
200     expectedReturn => ["/trunk/Makefile:r33020", "   Reverse-merged /trunk/Makefile.shared:r58350\n"],
201     expectedNextLine => undef,
202 },
203 {
204     # New test
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
210 END
211     expectedReturn => ["/trunk/Makefile:r33020", "   Reverse-merged /trunk/Makefile.shared:r58350\n"],
212     expectedNextLine => "   Merged /trunk/ChangeLog:r64190\n",
213 },
214 );
215
216 my $testCasesCount = @testCaseHashRefs;
217 plan(tests => 2 * $testCasesCount); # Total number of assertions.
218
219 foreach my $testCase (@testCaseHashRefs) {
220     my $testNameStart = "parseSvnPropertyValue(): $testCase->{diffName}: comparing";
221
222     my $fileHandle;
223     open($fileHandle, "<", \$testCase->{inputText});
224     my $line = <$fileHandle>;
225
226     my @got = VCSUtils::parseSvnPropertyValue($fileHandle, $line);
227     my $expectedReturn = $testCase->{expectedReturn};
228
229     is_deeply(\@got, $expectedReturn, "$testNameStart return value.");
230
231     my $gotNextLine = <$fileHandle>;
232     is($gotNextLine, $testCase->{expectedNextLine},  "$testNameStart next read line.");
233 }