| OLD | NEW | 
|---|
|  | (Empty) | 
| 1 // Copyright (c) 2011, the Dart project authors.  Please see the AUTHORS file |  | 
| 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. |  | 
| 4 |  | 
| 5 import "package:expect/expect.dart"; |  | 
| 6 |  | 
| 7 // Dart test for testing out of range exceptions on arrays, and the content |  | 
| 8 // of range_error toString(). |  | 
| 9 |  | 
| 10 void main() { |  | 
| 11   testRead(); |  | 
| 12   testWrite(); |  | 
| 13   testToString(); |  | 
| 14 } |  | 
| 15 |  | 
| 16 void testRead() { |  | 
| 17   testListRead([], 0); |  | 
| 18   testListRead([], -1); |  | 
| 19   testListRead([], 1); |  | 
| 20 |  | 
| 21   var list = [1]; |  | 
| 22   testListRead(list, -1); |  | 
| 23   testListRead(list, 1); |  | 
| 24 |  | 
| 25   list = new List(1); |  | 
| 26   testListRead(list, -1); |  | 
| 27   testListRead(list, 1); |  | 
| 28 |  | 
| 29   list = new List(); |  | 
| 30   testListRead(list, -1); |  | 
| 31   testListRead(list, 0); |  | 
| 32   testListRead(list, 1); |  | 
| 33 } |  | 
| 34 |  | 
| 35 void testWrite() { |  | 
| 36   testListWrite([], 0); |  | 
| 37   testListWrite([], -1); |  | 
| 38   testListWrite([], 1); |  | 
| 39 |  | 
| 40   var list = [1]; |  | 
| 41   testListWrite(list, -1); |  | 
| 42   testListWrite(list, 1); |  | 
| 43 |  | 
| 44   list = new List(1); |  | 
| 45   testListWrite(list, -1); |  | 
| 46   testListWrite(list, 1); |  | 
| 47 |  | 
| 48   list = new List(); |  | 
| 49   testListWrite(list, -1); |  | 
| 50   testListWrite(list, 0); |  | 
| 51   testListWrite(list, 1); |  | 
| 52 } |  | 
| 53 |  | 
| 54 void testToString() { |  | 
| 55   for (var name in [null, "THENAME"]) { |  | 
| 56     for (var message in [null, "THEMESSAGE"]) { |  | 
| 57       var value = 37; |  | 
| 58       for (var re in [ |  | 
| 59         new ArgumentError.value(value, name, message), |  | 
| 60         new RangeError.value(value, name, message), |  | 
| 61         new RangeError.index(value, [], name, message), |  | 
| 62         new RangeError.range(value, 0, 24, name, message) |  | 
| 63       ]) { |  | 
| 64         var str = re.toString(); |  | 
| 65         if (name != null) Expect.isTrue(str.contains(name), "$name in $str"); |  | 
| 66         if (message != null) |  | 
| 67           Expect.isTrue(str.contains(message), "$message in $str"); |  | 
| 68         Expect.isTrue(str.contains("$value"), "$value in $str"); |  | 
| 69         // No empty ':' separated parts - in that case the colon is omitted too. |  | 
| 70         Expect.isFalse(str.contains(new RegExp(":\s*:"))); |  | 
| 71       } |  | 
| 72     } |  | 
| 73   } |  | 
| 74 } |  | 
| 75 |  | 
| 76 void testListRead(list, index) { |  | 
| 77   var exception = null; |  | 
| 78   try { |  | 
| 79     var e = list[index]; |  | 
| 80   } on RangeError catch (e) { |  | 
| 81     exception = e; |  | 
| 82   } |  | 
| 83   Expect.equals(true, exception != null); |  | 
| 84 } |  | 
| 85 |  | 
| 86 void testListWrite(list, index) { |  | 
| 87   var exception = null; |  | 
| 88   try { |  | 
| 89     list[index] = null; |  | 
| 90   } on RangeError catch (e) { |  | 
| 91     exception = e; |  | 
| 92   } |  | 
| 93   Expect.equals(true, exception != null); |  | 
| 94 } |  | 
| OLD | NEW | 
|---|