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

Side by Side Diff: pkg/scheduled_test/test/scheduled_test/simple_test.dart

Issue 14070010: Refactor Future constructors. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Added co19 issue number. Created 7 years, 8 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
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 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 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 import 'dart:async'; 5 import 'dart:async';
6 import 'dart:io'; 6 import 'dart:io';
7 7
8 import 'package:scheduled_test/scheduled_test.dart'; 8 import 'package:scheduled_test/scheduled_test.dart';
9 9
10 import '../metatest.dart'; 10 import '../metatest.dart';
(...skipping 12 matching lines...) Expand all
23 expectTestsFail('a scheduled test with an incorrect synchronous expectation ' 23 expectTestsFail('a scheduled test with an incorrect synchronous expectation '
24 'should fail', () { 24 'should fail', () {
25 test('test', () { 25 test('test', () {
26 expect('foo', equals('bar')); 26 expect('foo', equals('bar'));
27 }); 27 });
28 }); 28 });
29 29
30 expectTestsPass('a scheduled test with a correct asynchronous expectation ' 30 expectTestsPass('a scheduled test with a correct asynchronous expectation '
31 'should pass', () { 31 'should pass', () {
32 test('test', () { 32 test('test', () {
33 expect(new Future.immediate('foo'), completion(equals('foo'))); 33 expect(new Future.value('foo'), completion(equals('foo')));
34 }); 34 });
35 }); 35 });
36 36
37 expectTestsFail('a scheduled test with an incorrect asynchronous expectation ' 37 expectTestsFail('a scheduled test with an incorrect asynchronous expectation '
38 'should fail', () { 38 'should fail', () {
39 test('test', () { 39 test('test', () {
40 expect(new Future.immediate('foo'), completion(equals('bar'))); 40 expect(new Future.value('foo'), completion(equals('bar')));
41 }); 41 });
42 }); 42 });
43 43
44 expectTestsPass('a passing scheduled synchronous expect should register', () { 44 expectTestsPass('a passing scheduled synchronous expect should register', () {
45 test('test', () { 45 test('test', () {
46 schedule(() => expect('foo', equals('foo'))); 46 schedule(() => expect('foo', equals('foo')));
47 }); 47 });
48 }); 48 });
49 49
50 expectTestsFail('a failing scheduled synchronous expect should register', () { 50 expectTestsFail('a failing scheduled synchronous expect should register', () {
51 test('test', () { 51 test('test', () {
52 schedule(() => expect('foo', equals('bar'))); 52 schedule(() => expect('foo', equals('bar')));
53 }); 53 });
54 }); 54 });
55 55
56 expectTestsPass('a passing scheduled asynchronous expect should ' 56 expectTestsPass('a passing scheduled asynchronous expect should '
57 'register', () { 57 'register', () {
58 test('test', () { 58 test('test', () {
59 schedule(() => 59 schedule(() =>
60 expect(new Future.immediate('foo'), completion(equals('foo')))); 60 expect(new Future.value('foo'), completion(equals('foo'))));
61 }); 61 });
62 }); 62 });
63 63
64 expectTestsFail('a failing scheduled synchronous expect should ' 64 expectTestsFail('a failing scheduled synchronous expect should '
65 'register', () { 65 'register', () {
66 test('test', () { 66 test('test', () {
67 schedule(() => 67 schedule(() =>
68 expect(new Future.immediate('foo'), completion(equals('bar')))); 68 expect(new Future.value('foo'), completion(equals('bar'))));
69 }); 69 });
70 }); 70 });
71 71
72 expectTestsPass('scheduled blocks should be run in order after the ' 72 expectTestsPass('scheduled blocks should be run in order after the '
73 'synchronous setup', () { 73 'synchronous setup', () {
74 test('test', () { 74 test('test', () {
75 var list = [1]; 75 var list = [1];
76 schedule(() => list.add(2)); 76 schedule(() => list.add(2));
77 list.add(3); 77 list.add(3);
78 schedule(() => expect(list, equals([1, 3, 4, 2]))); 78 schedule(() => expect(list, equals([1, 3, 4, 2])));
79 list.add(4); 79 list.add(4);
80 }); 80 });
81 }); 81 });
82 82
83 expectTestsPass('scheduled blocks should forward their return values as ' 83 expectTestsPass('scheduled blocks should forward their return values as '
84 'Futures', () { 84 'Futures', () {
85 test('synchronous value', () { 85 test('synchronous value', () {
86 var future = schedule(() => 'value'); 86 var future = schedule(() => 'value');
87 expect(future, completion(equals('value'))); 87 expect(future, completion(equals('value')));
88 }); 88 });
89 89
90 test('asynchronous value', () { 90 test('asynchronous value', () {
91 var future = schedule(() => new Future.immediate('value')); 91 var future = schedule(() => new Future.value('value'));
92 expect(future, completion(equals('value'))); 92 expect(future, completion(equals('value')));
93 }); 93 });
94 }); 94 });
95 95
96 expectTestsPass('scheduled blocks should wait for their Future return values ' 96 expectTestsPass('scheduled blocks should wait for their Future return values '
97 'to complete before proceeding', () { 97 'to complete before proceeding', () {
98 test('test', () { 98 test('test', () {
99 var value = 'unset'; 99 var value = 'unset';
100 schedule(() => pumpEventQueue().then((_) { 100 schedule(() => pumpEventQueue().then((_) {
101 value = 'set'; 101 value = 'set';
102 })); 102 }));
103 schedule(() => expect(value, equals('set'))); 103 schedule(() => expect(value, equals('set')));
104 }); 104 });
105 }); 105 });
106 106
107 expectTestsFail('a test failure in a chained future in a scheduled block ' 107 expectTestsFail('a test failure in a chained future in a scheduled block '
108 'should be registered', () { 108 'should be registered', () {
109 test('test', () { 109 test('test', () {
110 schedule(() => new Future.immediate('foo') 110 schedule(() => new Future.value('foo')
111 .then((v) => expect(v, equals('bar')))); 111 .then((v) => expect(v, equals('bar'))));
112 }); 112 });
113 }); 113 });
114 114
115 expectTestsFail('an error in a chained future in a scheduled block should be ' 115 expectTestsFail('an error in a chained future in a scheduled block should be '
116 'registered', () { 116 'registered', () {
117 test('test', () { 117 test('test', () {
118 schedule(() => new Future.immediate(null).then((_) { 118 schedule(() => new Future.value().then((_) {
119 throw 'error'; 119 throw 'error';
120 })); 120 }));
121 }); 121 });
122 }); 122 });
123 } 123 }
OLDNEW
« no previous file with comments | « pkg/scheduled_test/test/descriptor/async_test.dart ('k') | pkg/scheduled_test/test/substitute_future_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698