OLD | NEW |
1 // Copyright (c) 2015, the Fletch project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dartino 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.md file. | 3 // BSD-style license that can be found in the LICENSE.md file. |
4 | 4 |
5 import 'package:expect/expect.dart'; | 5 import 'package:expect/expect.dart'; |
6 | 6 |
7 Sting fromIterable(List list, int start, int end) { | 7 Sting fromIterable(List list, int start, int end) { |
8 return new String.fromCharCodes(list.where((_) => true), start, end); | 8 return new String.fromCharCodes(list.where((_) => true), start, end); |
9 } | 9 } |
10 | 10 |
11 bool isRangeError(e) => e is RangeError; | 11 bool isRangeError(e) => e is RangeError; |
12 | 12 |
13 main() { | 13 main() { |
14 Expect.equals("abc", fromIterable([97, 98, 99], 0, 3)); | 14 Expect.equals("abc", fromIterable([97, 98, 99], 0, 3)); |
15 Expect.equals("bc", fromIterable([97, 98, 99], 1, 3)); | 15 Expect.equals("bc", fromIterable([97, 98, 99], 1, 3)); |
16 Expect.equals("c", fromIterable([97, 98, 99], 2, 3)); | 16 Expect.equals("c", fromIterable([97, 98, 99], 2, 3)); |
17 Expect.equals("a", fromIterable([97, 98, 99], 0, 1)); | 17 Expect.equals("a", fromIterable([97, 98, 99], 0, 1)); |
18 Expect.equals("", fromIterable([97, 98, 99], 1, 1)); | 18 Expect.equals("", fromIterable([97, 98, 99], 1, 1)); |
19 Expect.equals("b", fromIterable([97, 98, 99], 1, 2)); | 19 Expect.equals("b", fromIterable([97, 98, 99], 1, 2)); |
20 | 20 |
21 Expect.throws(() => fromIterable([97, 98, 99], 1, 0), isRangeError); | 21 Expect.throws(() => fromIterable([97, 98, 99], 1, 0), isRangeError); |
22 Expect.throws(() => fromIterable([97, 98, 99], 2, 4), isRangeError); | 22 Expect.throws(() => fromIterable([97, 98, 99], 2, 4), isRangeError); |
23 Expect.throws(() => fromIterable([97, 98, 99], 4, 4), isRangeError); | 23 Expect.throws(() => fromIterable([97, 98, 99], 4, 4), isRangeError); |
24 Expect.throws(() => fromIterable([97, 98, 99], -1, 2), isRangeError); | 24 Expect.throws(() => fromIterable([97, 98, 99], -1, 2), isRangeError); |
25 } | 25 } |
OLD | NEW |