1#!/usr/bin/env perl -w 2use strict; 3use Test; 4BEGIN { plan tests => 10 } 5 6use String::Ediff; 7 8ok(test1(), "SUCCESS", "FAILED test1()"); 9ok(test2(), "SUCCESS", "FAILED test2()"); 10ok(test3(), "SUCCESS", "FAILED test3()"); 11ok(test4(), "SUCCESS", "FAILED test4()"); 12ok(test5(), "SUCCESS", "FAILED test5()"); 13ok(test6(), "SUCCESS", "FAILED test6()"); 14ok(test7(), "SUCCESS", "FAILED test7()"); 15ok(test8(), "SUCCESS", "FAILED test8()"); 16ok(test9(), "SUCCESS", "FAILED test9()"); 17ok(test10(), "SUCCESS", "FAILED test10()"); 18 19sub test1 { 20 my $s1 = "hello world"; 21 my $s2 = "hxello worlyd"; 22 23 my $indices = String::Ediff::ediff($s1, $s2); 24 if ($indices !~ /^1 10 0 0 2 11 0 0\s*$/) { 25 print $indices, "\n"; 26 return "FAILURE"; 27 } 28 return "SUCCESS"; 29} 30 31sub test2 { 32 my $s1 = "hello world a hello world"; 33 my $s2 = "hxello worlyd xyz hello"; 34 35 my $indices = String::Ediff::ediff($s1, $s2); 36 if ($indices !~ /^1 10 0 0 2 11 0 0 13 20 0 0 17 23 0 0\s*$/) { 37 print $indices, "\n"; 38 return "FAILURE"; 39 } 40 return "SUCCESS"; 41} 42 43sub test3 { 44 my $s1 = " crit=>'red', emerg=>'red', warning=>"red");"; 45 46 my $s2 = " crit=>'red', emerg=>'red', warning=>"red", 47 d=>"blue", w=>"red",n=>"green", 48 i=>'pink',e=>'red',a=>'red', 49 c=>'red');"; 50 51 my $indices = String::Ediff::ediff($s1, $s2); 52 if ($indices !~ /^0 35 0 0 0 36 0 0 35 95 0 0 35 96 0 0\s*$/) { 53 print $indices, "\n"; 54 return "FAILURE"; 55 } 56 return "SUCCESS"; 57} 58 59sub test4 { 60 my $s1 = "hello work"; 61 my $s2 = "h xello 62 world"; 63 64 my $indices = String::Ediff::ediff($s1, $s2); 65 if ($indices !~ /^1 6 0 0 4 11 0 1\s*$/) { 66 print $indices, "\n"; 67 return "FAILURE"; 68 } 69 return "SUCCESS"; 70} 71 72sub test5 { 73 my $s1 = " int node_idx = find_node(t, ap->m_node_id, 74 75 t->m_str[ap->m_begin_idx]); 76"; 77 my $s2 = " int node_idx = find_node(t, ap->m_node_id, ap_begin_char(t, ap)); 78 "; 79 80 my $indices = String::Ediff::ediff($s1, $s2); 81 if ($indices !~ /^0 85 0 2 0 48 0 0 99 106 2 2 50 57 0 0\s*$/) { 82 print $indices, "\n"; 83 return "FAILURE"; 84 } 85 return "SUCCESS"; 86} 87 88sub test6 { 89 my $s1 = 'for comp in *; do 90 if [ -d $comp -a $comp != "build" ]; then 91 cd $comp 92'; 93 my $s2 = ' 94# Build the controller bean 95cd controller 96'; 97 my $indices = String::Ediff::ediff($s1, $s2); 98 if ($indices !~ /^50 54 1 1 4 9 1 1 58 62 1 1 8 13 1 1 62 75 1 2 27 32 1 2\s*$/) { 99 test_dump($indices, $s1, $s2); 100 return "FAILURE"; 101 } 102 return "SUCCESS"; 103} 104 105# test for fixing this bug: 106# > 746 ret = (char*)malloc(sizeof(char) * INT_LEN * ix * 8); 107# > 747 ret[0] = 0; 108# Note if ix == 0, then ret has no memory allocated, ret[0] = 0 109# could core_dump perl 110# Reported by: Jonathan Noack 111# Analyzed by: Anton Berezin 112sub test7 { 113 my $left_diff = " 1* \$Id\$"; 114 my $right_diff = " 1* \$Header\$"; 115 my $diff_str = String::Ediff::ediff($left_diff, $right_diff); 116 return "SUCCESS"; 117} 118 119sub test8 { 120 my $s2 = " 121 closeConnection(conn); 122 } 123 return artifactsList; 124 } 125 126 /** 127"; 128 my $s1 = " 129 closeConnection(conn); 130 } 131 return artifactsList; 132 } 133 134 /** 135"; 136 137 my $indices = String::Ediff::ediff($s1, $s2); 138 if ($indices !~ /^0 75 0 7 0 77 0 7\s*$/) { 139 print $indices, "\n"; 140 return "FAILURE"; 141 } 142 return "SUCCESS"; 143} 144 145sub test9 { 146 { 147 my $s2 = " } 148 return artifactInfo; 149 150 } 151 152 /** 153 * "; 154 my $s1 = " } 155 return artifactInfo; 156 157 } 158 159 /** 160 * "; 161 my $indices = String::Ediff::ediff($s1, $s2); 162 if ($indices !~ /^0 52 0 6 0 56 0 6\s*$/) { 163 print length($s1), " ", length($s2), "\n"; 164 print $indices, "\n"; 165 return "FAILURE"; 166 } 167 } 168 { 169 my $s2 = " } 170 return artifactInfo; 171 172 } 173 174 /** 175"; 176 my $s1 = " } 177 return artifactInfo; 178 179 } 180 181 /** 182"; 183 184 my $indices = String::Ediff::ediff($s1, $s2); 185 if ($indices !~ /^0 47 0 6 0 51 0 6\s*$/) { 186 print length($s1), " ", length($s2), "\n"; 187 print $indices, "\n"; 188 return "FAILURE"; 189 } 190 } 191 return "SUCCESS"; 192} 193 194sub test10 { 195 my $s2 = " 196 static final long serialVersionUID = 647693002927539822L; 197 198 static final public String TYPE_SERVICE = \"Service\"; 199 static final public String TYPE_BUILDING_BLOCK = \"BuildingBlock\"; 200 static final public String TYPE_OTHER = \"Other\"; 201 202 static final public String STATUS_NOT_DEPLOYED = \"STATUS_NOT_DEPLOYED\"; 203 static final public String STATUS_DEPLOYED = \"STATUS_DEPLOYED\"; 204 static final public String STATUS_PARTIALLY_DEPLOYED = \"STATUS_PARTIALLY_DEPLOYED\"; 205 206 static final public String SERVICE_STATE_DISCARDED = \"SERVICE_STATE_DISCARDED\"; 207 static final public String SERVICE_STATE_ACTIVE = \"SERVICE_STATE_ACTIVE\"; 208 209 protected String name = \"\"; // maps DB field 210 protected String version = \"\"; // maps DB field"; 211 my $s1 = " 212 static final long serialVersionUID = 647693002927539822L; 213 214 static final public String TYPE_SERVICE = \"Service\"; 215 static final public String TYPE_BUILDING_BLOCK = \"BuildingBlock\"; 216 static final public String TYPE_OTHER = \"Other\"; 217 218 static final public String STATUS_NOT_DEPLOYED = \"STATUS_NOT_DEPLOYED\"; 219 static final public String STATUS_DEPLOYED = \"STATUS_DEPLOYED\"; 220 static final public String STATUS_PARTIALLY_DEPLOYED = \"STATUS_PARTIALLY_DEPLOYED\"; 221 222 static final public String SERVICE_STATE_DISCARDED = \"SERVICE_STATE_DISCARDED\"; 223 static final public String SERVICE_STATE_ACTIVE = \"SERVICE_STATE_ACTIVE\"; 224 225 protected String name = \"\"; // maps DB field 226 protected String version = \"\"; // maps DB field"; 227 228 my $indices = String::Ediff::ediff($s1, $s2); 229 if ($indices !~ /^0 117 0 3 0 113 0 3 107 252 3 5 107 243 3 5 240 321 5 7 236 310 5 7 315 401 7 8 306 387 7 8 391 571 8 11 380 556 8 11 391 660 8 12 380 642 8 12 650 843 12 15 635 825 12 15\s*$/) { 230 test_dump($indices, $s1, $s2); 231 return "FAILURE"; 232 } 233 return "SUCCESS"; 234} 235 236sub test_dump { 237 my ($indices, $s1, $s2) = @_; 238 print "\t", $indices, "\n"; 239 my @indices = split / /, $indices; 240 print "\t", scalar(@indices), "\n"; 241 for (my $i = 0; $i < @indices; $i+=8) { 242 my ($i1, $i2, undef, undef, $i3, $i4) = @indices[$i..$i+7]; 243 print "\t!$i1 $i2 ! $i3 $i4!\n"; 244 my $len1 = $i2-$i1; 245 my $len2 = $i4-$i3; 246 print "\t!$len1 ! $len2!\n"; 247 my ($val1) = ($s1 =~ /^.{$i1}(.{$len1})/s); 248 my ($val2) = ($s2 =~ /^.{$i3}(.{$len2})/s); 249 print "\t!$val1 ! $val2!\n"; 250 } 251} 252 253exit; 254 255__DATA__ 256test6 257 258 1 2 3 4 5 6 7 8 25901234567890123456789012345678901234567890123456789012345678901234567890123456789012 260for comp in *; do^ if [ -d $comp -a $comp != "build" ]; then^ cd $comp^ 261for comp in *; doif [ -d $comp -a $comp != "build" ]; thencd $comp 262 263 1 2 3 4 5 6 7 8 26401234567890123456789012345678901234567890123456789012345678901234567890123456789012 265^# Build the controller bean^cd controller^ 266# Build the controller beancd controller 267 26850 54 1 1 5 9 1 1 58 62 1 1 8 13 1 1 62 75 1 2 28 33 1 2 26945 49 3 7 53 57 7 11 57 61 26 30 # before adjust 270 271fixed! 27250 54 1 1 4 9 1 1 58 62 1 1 8 13 1 1 62 75 1 2 27 32 1 2 273