OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 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 | 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 library format_exception_test; | 5 library format_exception_test; |
| 6 |
6 import "package:expect/expect.dart"; | 7 import "package:expect/expect.dart"; |
7 | 8 |
8 test(exn, message, source, offset, toString) { | 9 test(exn, message, source, offset, toString) { |
9 Expect.equals(message, exn.message); | 10 Expect.equals(message, exn.message); |
10 Expect.equals(source, exn.source); | 11 Expect.equals(source, exn.source); |
11 Expect.equals(offset, exn.offset); | 12 Expect.equals(offset, exn.offset); |
12 Expect.equals(toString, exn.toString()); | 13 Expect.equals(toString, exn.toString()); |
13 } | 14 } |
14 | 15 |
15 main() { | 16 main() { |
16 var e; | 17 var e; |
17 e = new FormatException(); | 18 e = new FormatException(); |
18 test(e, "", null, null, "FormatException"); | 19 test(e, "", null, null, "FormatException"); |
19 e = new FormatException(""); | 20 e = new FormatException(""); |
20 test(e, "", null, null, "FormatException"); | 21 test(e, "", null, null, "FormatException"); |
21 e = new FormatException(null); | 22 e = new FormatException(null); |
22 test(e, null, null, null, "FormatException"); | 23 test(e, null, null, null, "FormatException"); |
23 | 24 |
24 e = new FormatException("message"); | 25 e = new FormatException("message"); |
25 test(e, "message", null, null, "FormatException: message"); | 26 test(e, "message", null, null, "FormatException: message"); |
26 | 27 |
27 e = new FormatException("message", "source"); | 28 e = new FormatException("message", "source"); |
28 test(e, "message", "source", null, "FormatException: message\nsource"); | 29 test(e, "message", "source", null, "FormatException: message\nsource"); |
29 | 30 |
30 e = new FormatException("message", "source" * 25); | 31 e = new FormatException("message", "source" * 25); |
31 test(e, "message", "source" * 25, null, "FormatException: message\n" + | 32 test(e, "message", "source" * 25, null, |
32 "source" * 12 + "sou..."); | 33 "FormatException: message\n" + "source" * 12 + "sou..."); |
33 e = new FormatException("message", "source" * 25); | 34 e = new FormatException("message", "source" * 25); |
34 test(e, "message", "source" * 25, null, "FormatException: message\n" + | 35 test(e, "message", "source" * 25, null, |
35 "source" * 12 + "sou..."); | 36 "FormatException: message\n" + "source" * 12 + "sou..."); |
36 e = new FormatException("message", "s1\nsource\ns2"); | 37 e = new FormatException("message", "s1\nsource\ns2"); |
37 test(e, "message", "s1\nsource\ns2", null, "FormatException: message\n" + | 38 test(e, "message", "s1\nsource\ns2", null, |
38 "s1\nsource\ns2"); | 39 "FormatException: message\n" + "s1\nsource\ns2"); |
39 | 40 |
40 var o = new Object(); | 41 var o = new Object(); |
41 e = new FormatException("message", o, 10); | 42 e = new FormatException("message", o, 10); |
42 test(e, "message", o, 10, "FormatException: message (at offset 10)"); | 43 test(e, "message", o, 10, "FormatException: message (at offset 10)"); |
43 | 44 |
44 e = new FormatException("message", "source", 3); | 45 e = new FormatException("message", "source", 3); |
45 test(e, "message", "source", 3, | 46 test(e, "message", "source", 3, |
46 "FormatException: message (at character 4)\nsource\n ^\n"); | 47 "FormatException: message (at character 4)\nsource\n ^\n"); |
47 | 48 |
48 e = new FormatException("message", "s1\nsource\ns2", 6); | 49 e = new FormatException("message", "s1\nsource\ns2", 6); |
49 test(e, "message", "s1\nsource\ns2", 6, | 50 test(e, "message", "s1\nsource\ns2", 6, |
50 "FormatException: message (at line 2, character 4)\nsource\n ^\n"); | 51 "FormatException: message (at line 2, character 4)\nsource\n ^\n"); |
51 | 52 |
52 var longline = "watermelon cantaloupe " * 8 + "watermelon"; // Length > 160. | 53 var longline = "watermelon cantaloupe " * 8 + "watermelon"; // Length > 160. |
53 var longsource = (longline + "\n") * 25; | 54 var longsource = (longline + "\n") * 25; |
54 var line10 = (longline.length + 1) * 9; | 55 var line10 = (longline.length + 1) * 9; |
55 e = new FormatException("message", longsource, line10); | 56 e = new FormatException("message", longsource, line10); |
56 test(e, "message", longsource, line10, | 57 test( |
57 "FormatException: message (at line 10, character 1)\n" | 58 e, |
58 "${longline.substring(0, 75)}...\n^\n"); | 59 "message", |
| 60 longsource, |
| 61 line10, |
| 62 "FormatException: message (at line 10, character 1)\n" |
| 63 "${longline.substring(0, 75)}...\n^\n"); |
59 | 64 |
60 e = new FormatException("message", longsource, line10 - 1); | 65 e = new FormatException("message", longsource, line10 - 1); |
61 test(e, "message", longsource, line10 - 1, | 66 test( |
62 "FormatException: message (at line 9, " | 67 e, |
63 "character ${longline.length + 1})\n" | 68 "message", |
64 "...${longline.substring(longline.length - 75)}\n" | 69 longsource, |
65 "${' ' * 78}^\n"); | 70 line10 - 1, |
| 71 "FormatException: message (at line 9, " |
| 72 "character ${longline.length + 1})\n" |
| 73 "...${longline.substring(longline.length - 75)}\n" |
| 74 "${' ' * 78}^\n"); |
66 | 75 |
67 var half = longline.length ~/ 2; | 76 var half = longline.length ~/ 2; |
68 e = new FormatException("message", longsource, line10 + half); | 77 e = new FormatException("message", longsource, line10 + half); |
69 test(e, "message", longsource, line10 + half, | 78 test( |
70 "FormatException: message (at line 10, character ${half + 1})\n" | 79 e, |
71 "...${longline.substring(half - 36, half + 36)}...\n" | 80 "message", |
72 "${' ' * 39}^\n"); | 81 longsource, |
| 82 line10 + half, |
| 83 "FormatException: message (at line 10, character ${half + 1})\n" |
| 84 "...${longline.substring(half - 36, half + 36)}...\n" |
| 85 "${' ' * 39}^\n"); |
73 } | 86 } |
OLD | NEW |