| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 import "package:expect/expect.dart"; | 5 import "package:expect/expect.dart"; |
| 6 | 6 |
| 7 // Test that optimized codeUnitAt and slow path codeUnitAt produce the same | 7 // Test that optimized codeUnitAt and slow path codeUnitAt produce the same |
| 8 // error. | 8 // error. |
| 9 | 9 |
| 10 @NoInline() | 10 @NoInline() |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 var s2 = '$e2'; | 26 var s2 = '$e2'; |
| 27 Expect.equals(s1, s2, '\n $name.$name1: "$s1"\n $name.$name2: "$s2"\n'); | 27 Expect.equals(s1, s2, '\n $name.$name1: "$s1"\n $name.$name2: "$s2"\n'); |
| 28 } | 28 } |
| 29 | 29 |
| 30 void check(String name, f1, f2, [f3, f4]) { | 30 void check(String name, f1, f2, [f3, f4]) { |
| 31 check2(name, 'f1', f1, 'f2', f2); | 31 check2(name, 'f1', f1, 'f2', f2); |
| 32 if (f3 != null) check2(name, 'f1', f1, 'f3', f3); | 32 if (f3 != null) check2(name, 'f1', f1, 'f3', f3); |
| 33 if (f4 != null) check2(name, 'f1', f1, 'f4', f4); | 33 if (f4 != null) check2(name, 'f1', f1, 'f4', f4); |
| 34 } | 34 } |
| 35 | 35 |
| 36 | |
| 37 class TooHigh { | 36 class TooHigh { |
| 38 static f1() { | 37 static f1() { |
| 39 return confuse('AB').codeUnitAt(3); // dynamic receiver. | 38 return confuse('AB').codeUnitAt(3); // dynamic receiver. |
| 40 } | 39 } |
| 41 | 40 |
| 42 static f2() { | 41 static f2() { |
| 43 var a = confuse(true) ? 'AB' : 'ABCDE'; // String with unknown length. | 42 var a = confuse(true) ? 'AB' : 'ABCDE'; // String with unknown length. |
| 44 var i = confuse(3); | 43 var i = confuse(3); |
| 45 return a.codeUnitAt(i); | 44 return a.codeUnitAt(i); |
| 46 } | 45 } |
| 47 | 46 |
| 48 static f3() { | 47 static f3() { |
| 49 var a = confuse(true) ? 'AB' : 'ABCDE'; // String with unknown length. | 48 var a = confuse(true) ? 'AB' : 'ABCDE'; // String with unknown length. |
| 50 return a.codeUnitAt(3); | 49 return a.codeUnitAt(3); |
| 51 } | 50 } |
| 52 | 51 |
| 53 static test() { | 52 static test() { |
| 54 check('TooHigh', f1, f2, f3); | 53 check('TooHigh', f1, f2, f3); |
| 55 } | 54 } |
| 56 } | 55 } |
| 57 | 56 |
| 58 class Negative { | 57 class Negative { |
| 59 static f1() { | 58 static f1() { |
| 60 return confuse('AB').codeUnitAt(-3); // dynamic receiver. | 59 return confuse('AB').codeUnitAt(-3); // dynamic receiver. |
| 61 } | 60 } |
| 62 | 61 |
| 63 static f2() { | 62 static f2() { |
| 64 var a = confuse(true) ? 'AB' : 'ABCDE'; // String with unknown length. | 63 var a = confuse(true) ? 'AB' : 'ABCDE'; // String with unknown length. |
| 65 var i = confuse(-3); | 64 var i = confuse(-3); |
| 66 return a.codeUnitAt(i); | 65 return a.codeUnitAt(i); |
| 67 } | 66 } |
| 68 | 67 |
| 69 static f3() { | 68 static f3() { |
| 70 var a = confuse(true) ? 'AB' : 'ABCDE'; // String with unknown length. | 69 var a = confuse(true) ? 'AB' : 'ABCDE'; // String with unknown length. |
| 71 var i = confuse(true) ? -3 : 0; | 70 var i = confuse(true) ? -3 : 0; |
| 72 return a.codeUnitAt(i); | 71 return a.codeUnitAt(i); |
| 73 } | 72 } |
| 74 | 73 |
| 75 static f4() { | 74 static f4() { |
| 76 var a = confuse(true) ? 'AB' : 'ABCDE'; // String with unknown length. | 75 var a = confuse(true) ? 'AB' : 'ABCDE'; // String with unknown length. |
| 77 return a.codeUnitAt(-3); | 76 return a.codeUnitAt(-3); |
| 78 } | 77 } |
| 79 | 78 |
| 80 static test() { | 79 static test() { |
| 81 check('Negative', f1, f2, f3, f4); | 80 check('Negative', f1, f2, f3, f4); |
| 82 } | 81 } |
| 83 } | 82 } |
| 84 | 83 |
| 85 class Empty { | 84 class Empty { |
| 86 static f1() { | 85 static f1() { |
| 87 return confuse('').codeUnitAt(0); // dynamic receiver. | 86 return confuse('').codeUnitAt(0); // dynamic receiver. |
| 88 } | 87 } |
| 89 | 88 |
| 90 static f2() { | 89 static f2() { |
| 91 var a = confuse(true) ? '' : 'ABCDE'; // Empty String with unknown length. | 90 var a = confuse(true) ? '' : 'ABCDE'; // Empty String with unknown length. |
| 92 var i = confuse(true) ? 0 : 1; | 91 var i = confuse(true) ? 0 : 1; |
| 93 return a.codeUnitAt(i); | 92 return a.codeUnitAt(i); |
| 94 } | 93 } |
| 95 | 94 |
| 96 static f3() { | 95 static f3() { |
| 97 var a = confuse(true) ? '' : 'ABCDE'; // Empty String with unknown length. | 96 var a = confuse(true) ? '' : 'ABCDE'; // Empty String with unknown length. |
| 98 return a.codeUnitAt(0); | 97 return a.codeUnitAt(0); |
| 99 } | 98 } |
| 100 | 99 |
| 101 static test() { | 100 static test() { |
| 102 check('Empty', f1, f2, f3); | 101 check('Empty', f1, f2, f3); |
| 103 } | 102 } |
| 104 } | 103 } |
| 105 | 104 |
| 106 class BadType { | 105 class BadType { |
| 107 static f1() { | 106 static f1() { |
| 108 return confuse('AB').codeUnitAt('a'); // dynamic receiver. | 107 return confuse('AB').codeUnitAt('a'); // dynamic receiver. |
| 109 } | 108 } |
| 110 | 109 |
| 111 static f2() { | 110 static f2() { |
| 112 var a = confuse(true) ? 'AB' : 'ABCDE'; // String with unknown length. | 111 var a = confuse(true) ? 'AB' : 'ABCDE'; // String with unknown length. |
| 113 var i = confuse('a'); | 112 var i = confuse('a'); |
| 114 return a.codeUnitAt(i); | 113 return a.codeUnitAt(i); |
| 115 } | 114 } |
| 116 | 115 |
| 117 static f3() { | 116 static f3() { |
| 118 var a = confuse(true) ? 'AB' : 'ABCDE'; // String with unknown length. | 117 var a = confuse(true) ? 'AB' : 'ABCDE'; // String with unknown length. |
| 119 return a.codeUnitAt('a'); | 118 return a.codeUnitAt('a'); |
| 120 } | 119 } |
| 121 | 120 |
| 122 static test() { | 121 static test() { |
| 123 check('BadType', f1, f2, f3); | 122 check('BadType', f1, f2, f3); |
| 124 } | 123 } |
| 125 } | 124 } |
| 126 | 125 |
| 127 main() { | 126 main() { |
| 128 TooHigh.test(); | 127 TooHigh.test(); |
| 129 Negative.test(); | 128 Negative.test(); |
| 130 Empty.test(); | 129 Empty.test(); |
| 131 BadType.test(); | 130 BadType.test(); |
| 132 } | 131 } |
| OLD | NEW |