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

Side by Side Diff: tests/corelib/src/CollectionToStringTest.dart

Issue 9372094: Added special case code for translating null element to work around a frog bug. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « corelib/src/implementation/collections.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 /** 5 /**
6 * Tests for the toString methods on collections (including maps). 6 * Tests for the toString methods on collections (including maps).
7 */ 7 */
8 8
9 // TODO(jjb): seed random number generator when API allows it 9 // TODO(jjb): seed random number generator when API allows it
10 10
11 final int NUM_TESTS = 3000; 11 final int NUM_TESTS = 3000;
12 final int MAX_COLLECTION_SIZE = 7; 12 final int MAX_COLLECTION_SIZE = 7;
13 13
14 main() { 14 main() {
15 smokeTest(); 15 smokeTest();
16 exactTest(); 16 exactTest();
17 inexactTest(); 17 inexactTest();
18 } 18 }
19 19
20 20
21 /** 21 /**
22 * Test a few simple examples. 22 * Test a few simple examples.
23 */ 23 */
24 void smokeTest() { 24 void smokeTest() {
25 // Non-const lists 25 // Non-const lists
26 Expect.equals([].toString(), '[]'); 26 Expect.equals([].toString(), '[]');
27 Expect.equals([1].toString(), '[1]'); 27 Expect.equals([1].toString(), '[1]');
28 Expect.equals(['Elvis'].toString(), '[Elvis]'); 28 Expect.equals(['Elvis'].toString(), '[Elvis]');
29 Expect.equals([null].toString(), '[null]');
29 Expect.equals([1, 2].toString(), '[1, 2]'); 30 Expect.equals([1, 2].toString(), '[1, 2]');
30 Expect.equals(['I', 'II'].toString(), '[I, II]'); 31 Expect.equals(['I', 'II'].toString(), '[I, II]');
31 Expect.equals([[1, 2], [3, 4], [5, 6]].toString(), '[[1, 2], [3, 4], [5, 6]]') ; 32 Expect.equals([[1, 2], [3, 4], [5, 6]].toString(), '[[1, 2], [3, 4], [5, 6]]') ;
32 33
33 // Const lists 34 // Const lists
34 Expect.equals((const[]).toString(), '[]'); 35 Expect.equals((const[]).toString(), '[]');
35 Expect.equals((const[1]).toString(), '[1]'); 36 Expect.equals((const[1]).toString(), '[1]');
36 Expect.equals((const['Elvis']).toString(), '[Elvis]'); 37 Expect.equals((const['Elvis']).toString(), '[Elvis]');
38 Expect.equals((const[null]).toString(), '[null]');
37 Expect.equals((const[1, 2]).toString(), '[1, 2]'); 39 Expect.equals((const[1, 2]).toString(), '[1, 2]');
38 Expect.equals((const['I', 'II']).toString(), '[I, II]'); 40 Expect.equals((const['I', 'II']).toString(), '[I, II]');
39 Expect.equals((const[const[1, 2], const[3, 4], const[5, 6]]).toString(), 41 Expect.equals((const[const[1, 2], const[3, 4], const[5, 6]]).toString(),
40 '[[1, 2], [3, 4], [5, 6]]'); 42 '[[1, 2], [3, 4], [5, 6]]');
41 43
42 // Non-const maps - Note that all keys are strings; the spec currently demands this 44 // Non-const maps - Note that all keys are strings; the spec currently demands this
43 Expect.equals({}.toString(), '{}'); 45 Expect.equals({}.toString(), '{}');
44 Expect.equals({'Elvis': 'King'}.toString(), '{Elvis: King}'); 46 Expect.equals({'Elvis': 'King'}.toString(), '{Elvis: King}');
47 Expect.equals({'Elvis': null}.toString(), '{Elvis: null}');
45 Expect.equals({'I': 1, 'II': 2}.toString(), '{I: 1, II: 2}'); 48 Expect.equals({'I': 1, 'II': 2}.toString(), '{I: 1, II: 2}');
46 Expect.equals({'X':{'I':1, 'II':2}, 'Y':{'III':3, 'IV':4}, 'Z':{'V':5, 'VI':6} }.toString(), 49 Expect.equals({'X':{'I':1, 'II':2}, 'Y':{'III':3, 'IV':4}, 'Z':{'V':5, 'VI':6} }.toString(),
47 '{X: {I: 1, II: 2}, Y: {III: 3, IV: 4}, Z: {V: 5, VI: 6}}'); 50 '{X: {I: 1, II: 2}, Y: {III: 3, IV: 4}, Z: {V: 5, VI: 6}}');
48 51
49 // Const maps 52 // Const maps
50 Expect.equals(const{}.toString(), '{}'); 53 Expect.equals(const{}.toString(), '{}');
51 Expect.equals(const{'Elvis': 'King'}.toString(), '{Elvis: King}'); 54 Expect.equals(const{'Elvis': 'King'}.toString(), '{Elvis: King}');
55 Expect.equals({'Elvis': null}.toString(), '{Elvis: null}');
52 Expect.equals(const{'I': 1, 'II': 2}.toString(), '{I: 1, II: 2}'); 56 Expect.equals(const{'I': 1, 'II': 2}.toString(), '{I: 1, II: 2}');
53 Expect.equals(const{'X': const{'I': 1, 'II': 2}, 'Y': const{'III': 3, 'IV': 4} , 57 Expect.equals(const{'X': const{'I': 1, 'II': 2}, 'Y': const{'III': 3, 'IV': 4} ,
54 'Z': const{'V': 5, 'VI': 6}}.toString(), 58 'Z': const{'V': 5, 'VI': 6}}.toString(),
55 '{X: {I: 1, II: 2}, Y: {III: 3, IV: 4}, Z: {V: 5, VI: 6}}'); 59 '{X: {I: 1, II: 2}, Y: {III: 3, IV: 4}, Z: {V: 5, VI: 6}}');
56 } 60 }
57 61
58 // SERIOUS "BASHER" TESTS 62 // SERIOUS "BASHER" TESTS
59 63
60 /** 64 /**
61 * Generate a bunch of random collections (including Maps), and test that 65 * Generate a bunch of random collections (including Maps), and test that
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 bool randomBool() { 288 bool randomBool() {
285 return Math.random() < .5; 289 return Math.random() < .5;
286 } 290 }
287 291
288 /** Returns the alphabetized characters in a string. */ 292 /** Returns the alphabetized characters in a string. */
289 String alphagram(String s) { 293 String alphagram(String s) {
290 List<int> chars = s.charCodes(); 294 List<int> chars = s.charCodes();
291 chars.sort((int a, int b) => a - b); 295 chars.sort((int a, int b) => a - b);
292 return new String.fromCharCodes(chars); 296 return new String.fromCharCodes(chars);
293 } 297 }
OLDNEW
« no previous file with comments | « corelib/src/implementation/collections.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698