Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Side by Side Diff: test/codegen/corelib/iterable_tostring_test.dart

Issue 1945153002: Add corelib tests (Closed) Base URL: https://github.com/dart-lang/dev_compiler@master
Patch Set: error_test and range_error_test now pass Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « test/codegen/corelib/iterable_to_set_test.dart ('k') | test/codegen/corelib/json_map_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2013, 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 // Test the IterableBase/IterableMixin toString method.
6
7 import "package:expect/expect.dart";
8 import "dart:collection";
9
10 String mkIt(int len, [func]) {
11 var list;
12 if (func == null) {
13 list = new List.generate(len, (x) => x);
14 } else {
15 list = new List.generate(len, func);
16 }
17 return new MyIterable(list).toString();
18 }
19
20 class MyIterable extends IterableBase {
21 final Iterable _base;
22 MyIterable(this._base);
23 Iterator get iterator => _base.iterator;
24 }
25
26 void main() {
27 Expect.equals("()", mkIt(0));
28 Expect.equals("(0)", mkIt(1));
29 Expect.equals("(0, 1)", mkIt(2));
30 Expect.equals("(0, 1, 2, 3, 4, 5, 6, 7, 8)", mkIt(9));
31
32 // Builds string up to 60 characters, then finishes with last two
33 // elements.
34 Expect.equals(
35 //0123456789012345678901234567890123456789 - 40 characters
36 "(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 1"
37 "2, 13, 14, 15, 16, 17, 18, ..., 98, 99)",
38 mkIt(100));
39
40 Expect.equals(
41 //0123456789012345678901234567890123456789
42 "(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 1"
43 "2, 13, 14, 15, 16, 17, 18)",
44 mkIt(19));
45
46 Expect.equals(
47 //0123456789012345678901234567890123456789
48 "(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 1"
49 "2, 13, 14, 15, 16, 17, 18, 19)",
50 mkIt(20));
51
52 Expect.equals(
53 //0123456789012345678901234567890123456789
54 "(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 1"
55 "2, 13, 14, 15, 16, 17, 18, 19, 20)",
56 mkIt(21));
57
58 // Don't show last two elements if more than 100 elements total
59 // (can't be 100 elements in 80 characters including commas).
60 Expect.equals(
61 //0123456789012345678901234567890123456789
62 "(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 1"
63 "2, 13, 14, 15, 16, 17, 18, 19, 20, ...)",
64 mkIt(101));
65
66 // If last two elements bring total over 80 characters, drop some of
67 // the previous ones as well.
68
69 Expect.equals(
70 //0123456789012345678901234567890123456789
71 "(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 1"
72 "2, 13, ..., 18, xxxxxxxxxxxxxxxxxxxx)",
73 mkIt(20, (x) => x == 19 ? "xxxxxxxxxxxxxxxxxxxx": "$x"));
74
75 // Never drop the first three or the last two.
76 Expect.equals(
77 //0123456789012345678901234567890123456789
78 "(xxxxxxxxxxxxxxxxx, xxxxxxxxxxxxxxxxx, x"
79 "xxxxxxxxxxxxxxxx, ..., 18, xxxxxxxxxxxxx"
80 "xxxx)",
81 mkIt(20, (x) => (x < 3 || x == 19) ? "xxxxxxxxxxxxxxxxx": "$x"));
82
83 // Never drop the first three or the last two.
84 Expect.equals(
85 //0123456789012345678901234567890123456789
86 "(xxxxxxxxxxxxxxxxx, xxxxxxxxxxxxxxxxx, x"
87 "xxxxxxxxxxxxxxxx, ..., xxxxxxxxxxxxxxxxx"
88 ", 19)",
89 mkIt(20, (x) => (x < 3 || x == 18) ? "xxxxxxxxxxxxxxxxx": "$x"));
90
91 // If the first three are very long, always include them anyway.
92 Expect.equals(
93 //0123456789012345678901234567890123456789
94 "(xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx,"
95 " xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx,"
96 " xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx,"
97 " ..., 98, 99)",
98 mkIt(100, (x) =>
99 (x < 3 ) ? "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx": "$x"));
100
101 Expect.equals(
102 //0123456789012345678901234567890123456789
103 "(, , , , , , , , , , , , , , , , , , , ,"
104 " , , , , , , , , , , , , , , , ..., , )",
105 mkIt(100, (_) => ""));
106 }
OLDNEW
« no previous file with comments | « test/codegen/corelib/iterable_to_set_test.dart ('k') | test/codegen/corelib/json_map_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698