| OLD | NEW |
| 1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | 27 |
| 28 // Flags: --expose-debug-as debug | 28 // Flags: --expose-debug-as debug |
| 29 // Get the Debug object exposed from the debug context global object. | 29 // Get the Debug object exposed from the debug context global object. |
| 30 | 30 |
| 31 Debug = debug.Debug | 31 Debug = debug.Debug |
| 32 | 32 |
| 33 function CheckCompareOneWay(s1, s2) { | 33 function CheckCompareOneWay(s1, s2) { |
| 34 var diff_array = Debug.LiveEdit.TestApi.CompareStringsLinewise(s1, s2); | 34 var diff_array = Debug.LiveEdit.TestApi.CompareStrings(s1, s2); |
| 35 | 35 |
| 36 var pos1 = 0; | 36 var pos1 = 0; |
| 37 var pos2 = 0; | 37 var pos2 = 0; |
| 38 print("Compare:"); | 38 print("Compare:"); |
| 39 print("s1='" + s1 + "'"); |
| 40 print("s2='" + s2 + "'"); |
| 41 print("Diff:"); |
| 42 print("" + diff_array); |
| 39 for (var i = 0; i < diff_array.length; i += 3) { | 43 for (var i = 0; i < diff_array.length; i += 3) { |
| 40 var similar_length = diff_array[i] - pos1; | 44 var similar_length = diff_array[i] - pos1; |
| 41 assertEquals(s1.substring(pos1, pos1 + similar_length), | 45 assertEquals(s1.substring(pos1, pos1 + similar_length), |
| 42 s2.substring(pos2, pos2 + similar_length)); | 46 s2.substring(pos2, pos2 + similar_length)); |
| 43 | 47 |
| 44 print(s1.substring(pos1, pos1 + similar_length)); | 48 print(s1.substring(pos1, pos1 + similar_length)); |
| 45 pos1 += similar_length; | 49 pos1 += similar_length; |
| 46 pos2 += similar_length; | 50 pos2 += similar_length; |
| 47 print("<<< " + pos1 + " " + diff_array[i + 1]); | 51 print("<<< " + pos1 + " " + diff_array[i + 1]); |
| 48 print(s1.substring(pos1, pos1 + diff_array[i + 1])); | 52 print(s1.substring(pos1, diff_array[i + 1])); |
| 49 print("==="); | 53 print("==="); |
| 50 print(s2.substring(pos2, pos2 + diff_array[i + 2])); | 54 print(s2.substring(pos2, diff_array[i + 2])); |
| 51 print(">>> " + pos2 + " " + diff_array[i + 2]); | 55 print(">>> " + pos2 + " " + diff_array[i + 2]); |
| 52 pos1 += diff_array[i + 1]; | 56 pos1 = diff_array[i + 1]; |
| 53 pos2 += diff_array[i + 2]; | 57 pos2 = diff_array[i + 2]; |
| 54 } | 58 } |
| 55 { | 59 { |
| 56 // After last change | 60 // After last change |
| 57 var similar_length = s1.length - pos1; | 61 var similar_length = s1.length - pos1; |
| 58 assertEquals(similar_length, s2.length - pos2); | 62 assertEquals(similar_length, s2.length - pos2); |
| 59 assertEquals(s1.substring(pos1, pos1 + similar_length), | 63 assertEquals(s1.substring(pos1, pos1 + similar_length), |
| 60 s2.substring(pos2, pos2 + similar_length)); | 64 s2.substring(pos2, pos2 + similar_length)); |
| 61 | 65 |
| 62 print(s1.substring(pos1, pos1 + similar_length)); | 66 print(s1.substring(pos1, pos1 + similar_length)); |
| 63 } | 67 } |
| 64 print(""); | 68 print(""); |
| 65 } | 69 } |
| 66 | 70 |
| 71 function CheckCompareOneWayPlayWithLF(s1, s2) { |
| 72 var s1Oneliner = s1.replace(/\n/g, ' '); |
| 73 var s2Oneliner = s2.replace(/\n/g, ' '); |
| 74 CheckCompareOneWay(s1, s2); |
| 75 CheckCompareOneWay(s1Oneliner, s2); |
| 76 CheckCompareOneWay(s1, s2Oneliner); |
| 77 CheckCompareOneWay(s1Oneliner, s2Oneliner); |
| 78 } |
| 79 |
| 67 function CheckCompare(s1, s2) { | 80 function CheckCompare(s1, s2) { |
| 68 CheckCompareOneWay(s1, s2); | 81 CheckCompareOneWayPlayWithLF(s1, s2); |
| 69 CheckCompareOneWay(s2, s1); | 82 CheckCompareOneWayPlayWithLF(s2, s1); |
| 70 } | 83 } |
| 71 | 84 |
| 72 CheckCompare("", ""); | 85 CheckCompare("", ""); |
| 73 | 86 |
| 74 CheckCompare("a", "b"); | 87 CheckCompare("a", "b"); |
| 75 | 88 |
| 76 CheckCompare( | 89 CheckCompare( |
| 77 "yesterday\nall\nmy\ntroubles\nseemed\nso\nfar\naway", | 90 "yesterday\nall\nmy\ntroubles\nseemed\nso\nfar\naway", |
| 78 "yesterday\nall\nmy\ntroubles\nseem\nso\nfar\naway" | 91 "yesterday\nall\nmy\ntroubles\nseem\nso\nfar\naway" |
| 79 ); | 92 ); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 91 CheckCompare( | 104 CheckCompare( |
| 92 "yesterday\nall\nmy\ntroubles\nseemed\nso\nfar\naway", | 105 "yesterday\nall\nmy\ntroubles\nseemed\nso\nfar\naway", |
| 93 "yesterday\nall\nmy\ntroubles\nseemed\nso\nfar\naway\n" | 106 "yesterday\nall\nmy\ntroubles\nseemed\nso\nfar\naway\n" |
| 94 ); | 107 ); |
| 95 | 108 |
| 96 CheckCompare( | 109 CheckCompare( |
| 97 "yesterday\nall\nmy\ntroubles\nseemed\nso\nfar\naway", | 110 "yesterday\nall\nmy\ntroubles\nseemed\nso\nfar\naway", |
| 98 "yesterday\nall\nmy\ntroubles\nseemed\nso\n" | 111 "yesterday\nall\nmy\ntroubles\nseemed\nso\n" |
| 99 ); | 112 ); |
| 100 | 113 |
| OLD | NEW |