WebKitTools/Scripts/webkitperl/VCSUtils_unittest/parseSvnProperty.pl
changeset 0 4f2f89ce4247
equal deleted inserted replaced
-1:000000000000 0:4f2f89ce4247
       
     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 parseSvnProperty().
       
    33 
       
    34 use strict;
       
    35 use warnings;
       
    36 
       
    37 use Test::More;
       
    38 use VCSUtils;
       
    39 
       
    40 my @testCaseHashRefs = (
       
    41 ####
       
    42 # Simple test cases
       
    43 ##
       
    44 {
       
    45     # New test
       
    46     diffName => "simple: add svn:executable",
       
    47     inputText => <<'END',
       
    48 Added: svn:executable
       
    49    + *
       
    50 END
       
    51     expectedReturn => [
       
    52 {
       
    53     name => "svn:executable",
       
    54     propertyChangeDelta => 1,
       
    55     value => "*",
       
    56 },
       
    57 undef],
       
    58     expectedNextLine => undef,
       
    59 },
       
    60 {
       
    61     # New test
       
    62     diffName => "simple: delete svn:executable",
       
    63     inputText => <<'END',
       
    64 Deleted: svn:executable
       
    65    - *
       
    66 END
       
    67     expectedReturn => [
       
    68 {
       
    69     name => "svn:executable",
       
    70     propertyChangeDelta => -1,
       
    71     value => "*",
       
    72 },
       
    73 undef],
       
    74     expectedNextLine => undef,
       
    75 },
       
    76 ####
       
    77 # Using SVN 1.4 syntax
       
    78 ##
       
    79 {
       
    80     # New test
       
    81     diffName => "simple: delete svn:executable using SVN 1.4 syntax",
       
    82     inputText => <<'END',
       
    83 Name: svn:executable
       
    84    - *
       
    85 END
       
    86     expectedReturn => [
       
    87 {
       
    88     name => "svn:executable",
       
    89     propertyChangeDelta => -1,
       
    90     value => "*",
       
    91 },
       
    92 undef],
       
    93     expectedNextLine => undef,
       
    94 },
       
    95 {
       
    96     # New test
       
    97     diffName => "simple: add svn:executable using SVN 1.4 syntax",
       
    98     inputText => <<'END',
       
    99 Name: svn:executable
       
   100    + *
       
   101 END
       
   102     expectedReturn => [
       
   103 {
       
   104     name => "svn:executable",
       
   105     propertyChangeDelta => 1,
       
   106     value => "*",
       
   107 },
       
   108 undef],
       
   109     expectedNextLine => undef,
       
   110 },
       
   111 ####
       
   112 # Property value followed by empty line and start of next diff
       
   113 ##
       
   114 {
       
   115     # New test
       
   116     diffName => "add svn:executable, followed by empty line and start of next diff",
       
   117     inputText => <<'END',
       
   118 Added: svn:executable
       
   119    + *
       
   120 
       
   121 Index: Makefile.shared
       
   122 END
       
   123     expectedReturn => [
       
   124 {
       
   125     name => "svn:executable",
       
   126     propertyChangeDelta => 1,
       
   127     value => "*",
       
   128 },
       
   129 "\n"],
       
   130     expectedNextLine => "Index: Makefile.shared\n",
       
   131 },
       
   132 {
       
   133     # New test
       
   134     diffName => "add svn:executable, followed by empty line and start of next property diff",
       
   135     inputText => <<'END',
       
   136 Added: svn:executable
       
   137    + *
       
   138 
       
   139 Property changes on: Makefile.shared
       
   140 END
       
   141     expectedReturn => [
       
   142 {
       
   143     name => "svn:executable",
       
   144     propertyChangeDelta => 1,
       
   145     value => "*",
       
   146 },
       
   147 "\n"],
       
   148     expectedNextLine => "Property changes on: Makefile.shared\n",
       
   149 },
       
   150 {
       
   151     # New test
       
   152     diffName => "multi-line '+' change, followed by empty line and start of next diff",
       
   153     inputText => <<'END',
       
   154 Name: documentation
       
   155    + A
       
   156 long sentence that spans
       
   157 multiple lines.
       
   158 
       
   159 Index: Makefile.shared
       
   160 END
       
   161     expectedReturn => [
       
   162 {
       
   163     name => "documentation",
       
   164     propertyChangeDelta => 1,
       
   165     value => "A\nlong sentence that spans\nmultiple lines.",
       
   166 },
       
   167 "\n"],
       
   168     expectedNextLine => "Index: Makefile.shared\n",
       
   169 },
       
   170 {
       
   171     # New test
       
   172     diffName => "multi-line '+' change, followed by empty line and start of next property diff",
       
   173     inputText => <<'END',
       
   174 Name: documentation
       
   175    + A
       
   176 long sentence that spans
       
   177 multiple lines.
       
   178 
       
   179 Property changes on: Makefile.shared
       
   180 END
       
   181     expectedReturn => [
       
   182 {
       
   183     name => "documentation",
       
   184     propertyChangeDelta => 1,
       
   185     value => "A\nlong sentence that spans\nmultiple lines.",
       
   186 },
       
   187 "\n"],
       
   188     expectedNextLine => "Property changes on: Makefile.shared\n",
       
   189 },
       
   190 ####
       
   191 # Property value followed by empty line and start of binary patch
       
   192 ##
       
   193 {
       
   194     # New test
       
   195     diffName => "add svn:executable, followed by empty line and start of binary patch",
       
   196     inputText => <<'END',
       
   197 Added: svn:executable
       
   198    + *
       
   199 
       
   200 Q1dTBx0AAAB42itg4GlgYJjGwMDDyODMxMDw34GBgQEAJPQDJA==
       
   201 END
       
   202     expectedReturn => [
       
   203 {
       
   204     name => "svn:executable",
       
   205     propertyChangeDelta => 1,
       
   206     value => "*",
       
   207 },
       
   208 "\n"],
       
   209     expectedNextLine => "Q1dTBx0AAAB42itg4GlgYJjGwMDDyODMxMDw34GBgQEAJPQDJA==\n",
       
   210 },
       
   211 {
       
   212     # New test
       
   213     diffName => "multi-line '+' change, followed by empty line and start of binary patch",
       
   214     inputText => <<'END',
       
   215 Name: documentation
       
   216    + A
       
   217 long sentence that spans
       
   218 multiple lines.
       
   219 
       
   220 Q1dTBx0AAAB42itg4GlgYJjGwMDDyODMxMDw34GBgQEAJPQDJA==
       
   221 END
       
   222     expectedReturn => [
       
   223 {
       
   224     name => "documentation",
       
   225     propertyChangeDelta => 1,
       
   226     value => "A\nlong sentence that spans\nmultiple lines.",
       
   227 },
       
   228 "\n"],
       
   229     expectedNextLine => "Q1dTBx0AAAB42itg4GlgYJjGwMDDyODMxMDw34GBgQEAJPQDJA==\n",
       
   230 },
       
   231 {
       
   232     # New test
       
   233     diffName => "multi-line '-' change, followed by multi-line '+' change, empty line, and start of binary patch",
       
   234     inputText => <<'END',
       
   235 Modified: documentation
       
   236    - A
       
   237 long sentence that spans
       
   238 multiple lines.
       
   239    + Another
       
   240 long sentence that spans
       
   241 multiple lines.
       
   242 
       
   243 Q1dTBx0AAAB42itg4GlgYJjGwMDDyODMxMDw34GBgQEAJPQDJA==
       
   244 END
       
   245     expectedReturn => [
       
   246 {
       
   247     name => "documentation",
       
   248     propertyChangeDelta => 1,
       
   249     value => "Another\nlong sentence that spans\nmultiple lines.",
       
   250 },
       
   251 "\n"],
       
   252     expectedNextLine => "Q1dTBx0AAAB42itg4GlgYJjGwMDDyODMxMDw34GBgQEAJPQDJA==\n",
       
   253 },
       
   254 ####
       
   255 # Successive properties
       
   256 ##
       
   257 {
       
   258     # New test
       
   259     diffName => "single-line '+' change followed by custom property with single-line '+' change",
       
   260     inputText => <<'END',
       
   261 Added: svn:executable
       
   262    + *
       
   263 Added: documentation
       
   264    + A sentence.
       
   265 END
       
   266     expectedReturn => [
       
   267 {
       
   268     name => "svn:executable",
       
   269     propertyChangeDelta => 1,
       
   270     value => "*",
       
   271 },
       
   272 "Added: documentation\n"],
       
   273     expectedNextLine => "   + A sentence.\n",
       
   274 },
       
   275 {
       
   276     # New test
       
   277     diffName => "multi-line '+' change, followed by svn:executable",
       
   278     inputText => <<'END',
       
   279 Name: documentation
       
   280    + A
       
   281 long sentence that spans
       
   282 multiple lines.
       
   283 Name: svn:executable
       
   284    + *
       
   285 END
       
   286     expectedReturn => [
       
   287 {
       
   288     name => "documentation",
       
   289     propertyChangeDelta => 1,
       
   290     value => "A\nlong sentence that spans\nmultiple lines.",
       
   291 },
       
   292 "Name: svn:executable\n"],
       
   293     expectedNextLine => "   + *\n",
       
   294 },
       
   295 {
       
   296     # New test
       
   297     diffName => "multi-line '-' change, followed by multi-line '+' change and add svn:executable",
       
   298     inputText => <<'END',
       
   299 Modified: documentation
       
   300    - A
       
   301 long sentence that spans
       
   302 multiple lines.
       
   303    + Another
       
   304 long sentence that spans
       
   305 multiple lines.
       
   306 Added: svn:executable
       
   307    + *
       
   308 END
       
   309     expectedReturn => [
       
   310 {
       
   311     name => "documentation",
       
   312     propertyChangeDelta => 1,
       
   313     value => "Another\nlong sentence that spans\nmultiple lines.",
       
   314 },
       
   315 "Added: svn:executable\n"],
       
   316     expectedNextLine => "   + *\n",
       
   317 },
       
   318 ####
       
   319 # Property values with trailing new lines.
       
   320 ##
       
   321 # FIXME: We do not support property values with trailing new lines, since it is difficult to
       
   322 #        disambiguate them from the empty line that preceeds the contents of a binary patch as
       
   323 #        in the test case (above): "multi-line '+' change, followed by empty line and start of binary patch".
       
   324 {
       
   325     # New test
       
   326     diffName => "single-line '+' with trailing new line",
       
   327     inputText => <<'END',
       
   328 Added: documentation
       
   329    + A sentence.
       
   330 
       
   331 END
       
   332     expectedReturn => [
       
   333 {
       
   334     name => "documentation",
       
   335     propertyChangeDelta => 1,
       
   336     value => "A sentence.",
       
   337 },
       
   338 "\n"],
       
   339     expectedNextLine => undef,
       
   340 },
       
   341 {
       
   342     # New test
       
   343     diffName => "single-line '+' with trailing new line, followed by empty line and start of binary patch",
       
   344     inputText => <<'END',
       
   345 Added: documentation
       
   346    + A sentence.
       
   347 
       
   348 
       
   349 Q1dTBx0AAAB42itg4GlgYJjGwMDDyODMxMDw34GBgQEAJPQDJA==
       
   350 END
       
   351     expectedReturn => [
       
   352 {
       
   353     name => "documentation",
       
   354     propertyChangeDelta => 1,
       
   355     value => "A sentence.",
       
   356 },
       
   357 "\n"],
       
   358     expectedNextLine => "\n",
       
   359 },
       
   360 {
       
   361     # New test
       
   362     diffName => "single-line '-' change with trailing new line, and single-line '+' change",
       
   363     inputText => <<'END',
       
   364 Modified: documentation
       
   365    - A long sentence.
       
   366 
       
   367    + A sentence.
       
   368 END
       
   369     expectedReturn => [
       
   370 {
       
   371     name => "documentation",
       
   372     propertyChangeDelta => -1, # Since we only interpret the '-' property.
       
   373     value => "A long sentence.",
       
   374 },
       
   375 "\n"],
       
   376     expectedNextLine => "   + A sentence.\n",
       
   377 },
       
   378 {
       
   379     # New test
       
   380     diffName => "multi-line '-' change with trailing new line, and multi-line '+' change",
       
   381     inputText => <<'END',
       
   382 Modified: documentation
       
   383    - A
       
   384 long sentence that spans
       
   385 multiple lines.
       
   386 
       
   387    + Another
       
   388 long sentence that spans
       
   389 multiple lines.
       
   390 END
       
   391     expectedReturn => [
       
   392 {
       
   393     name => "documentation",
       
   394     propertyChangeDelta => -1, # Since we only interpret the '-' property.
       
   395     value => "A\nlong sentence that spans\nmultiple lines.",
       
   396 },
       
   397 "\n"],
       
   398     expectedNextLine => "   + Another\n",
       
   399 },
       
   400 );
       
   401 
       
   402 my $testCasesCount = @testCaseHashRefs;
       
   403 plan(tests => 2 * $testCasesCount); # Total number of assertions.
       
   404 
       
   405 foreach my $testCase (@testCaseHashRefs) {
       
   406     my $testNameStart = "parseSvnProperty(): $testCase->{diffName}: comparing";
       
   407 
       
   408     my $fileHandle;
       
   409     open($fileHandle, "<", \$testCase->{inputText});
       
   410     my $line = <$fileHandle>;
       
   411 
       
   412     my @got = VCSUtils::parseSvnProperty($fileHandle, $line);
       
   413     my $expectedReturn = $testCase->{expectedReturn};
       
   414 
       
   415     is_deeply(\@got, $expectedReturn, "$testNameStart return value.");
       
   416 
       
   417     my $gotNextLine = <$fileHandle>;
       
   418     is($gotNextLine, $testCase->{expectedNextLine},  "$testNameStart next read line.");
       
   419 }