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

Side by Side Diff: pkg/unittest/unittest.dart

Issue 10944006: - Removed comment to Frog and eliminated usage of sentinel. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 3 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
« pkg/unittest/mock.dart ('K') | « pkg/unittest/mock.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) 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 /** 5 /**
6 * A library for writing dart unit tests. 6 * A library for writing dart unit tests.
7 * 7 *
8 * To import this library, specify the relative path to 8 * To import this library, specify the relative path to
9 * pkg/unittest/unittest.dart. 9 * pkg/unittest/unittest.dart.
10 * 10 *
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 if (_soloTest != null) { 286 if (_soloTest != null) {
287 throw new Exception('Only one test can be soloed right now.'); 287 throw new Exception('Only one test can be soloed right now.');
288 } 288 }
289 289
290 ensureInitialized(); 290 ensureInitialized();
291 291
292 _soloTest = new TestCase(_tests.length + 1, _fullSpec(spec), body, 0); 292 _soloTest = new TestCase(_tests.length + 1, _fullSpec(spec), body, 0);
293 _tests.add(_soloTest); 293 _tests.add(_soloTest);
294 } 294 }
295 295
296 /** Sentinel value for [_SpreadArgsHelper]. */
297 class _Sentinel {
298 const _Sentinel();
299 }
300
301 // TODO(sigmund): make a singleton const field when frog supports passing those
302 // as default values to named arguments.
303 const _sentinel = const _Sentinel();
304
305 /** Simulates spread arguments using named arguments. */ 296 /** Simulates spread arguments using named arguments. */
306 // TODO(sigmund): remove this class and simply use a closure with named 297 // TODO(sigmund): remove this class and simply use a closure with named
307 // arguments (if still applicable). 298 // arguments (if still applicable).
308 class _SpreadArgsHelper { 299 class _SpreadArgsHelper {
309 Function _callback; 300 Function _callback;
310 int _expectedCalls; 301 int _expectedCalls;
311 int _actualCalls = 0; 302 int _actualCalls = 0;
312 int _testNum; 303 int _testNum;
313 TestCase _testCase; 304 TestCase _testCase;
314 Function _shouldCallBack; 305 Function _shouldCallBack;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 if (_testCase.isComplete) { 349 if (_testCase.isComplete) {
359 _testCase.error( 350 _testCase.error(
360 'Callback called after already being marked as done ($_actualCalls).', 351 'Callback called after already being marked as done ($_actualCalls).',
361 ''); 352 '');
362 return false; 353 return false;
363 } else { 354 } else {
364 return true; 355 return true;
365 } 356 }
366 } 357 }
367 358
368 invoke([arg0 = _sentinel, arg1 = _sentinel, arg2 = _sentinel, 359 invoke([arg0, arg1, arg2, arg3, arg4]) {
369 arg3 = _sentinel, arg4 = _sentinel]) {
370 return guardAsync(() { 360 return guardAsync(() {
371 ++_actualCalls; 361 ++_actualCalls;
372 if (!_shouldCallBack()) { 362 if (!_shouldCallBack()) return;
373 return; 363 if (?arg0) return _callback();
kasperl 2012/09/18 10:52:25 !?arg0
374 } else if (arg0 == _sentinel) { 364 if (?arg1) return _callback(arg0);
375 return _callback(); 365 if (?arg2) return _callback(arg0, arg1);
376 } else if (arg1 == _sentinel) { 366 if (?arg3) return _callback(arg0, arg1, arg2);
377 return _callback(arg0); 367 if (?arg4) return _callback(arg0, arg1, arg2, arg3);
378 } else if (arg2 == _sentinel) { 368 _testCase.error(
379 return _callback(arg0, arg1); 369 'unittest lib does not support callbacks with more than'
380 } else if (arg3 == _sentinel) { 370 ' 4 arguments.',
381 return _callback(arg0, arg1, arg2); 371 '');
382 } else if (arg4 == _sentinel) { 372 },
383 return _callback(arg0, arg1, arg2, arg3); 373 _after, _testNum);
384 } else {
385 _testCase.error(
386 'unittest lib does not support callbacks with more than'
387 ' 4 arguments.',
388 '');
389 }
390 },
391 _after, _testNum);
392 } 374 }
393 375
394 invoke0() { 376 invoke0() {
395 return guardAsync( 377 return guardAsync(
396 () { 378 () {
397 ++_actualCalls; 379 ++_actualCalls;
398 if (_shouldCallBack()) { 380 if (_shouldCallBack()) {
399 return _callback(); 381 return _callback();
400 } 382 }
401 }, 383 },
(...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after
865 } 847 }
866 848
867 /** Enable a test by ID. */ 849 /** Enable a test by ID. */
868 void enableTest(int testId) => _setTestEnabledState(testId, true); 850 void enableTest(int testId) => _setTestEnabledState(testId, true);
869 851
870 /** Disable a test by ID. */ 852 /** Disable a test by ID. */
871 void disableTest(int testId) => _setTestEnabledState(testId, false); 853 void disableTest(int testId) => _setTestEnabledState(testId, false);
872 854
873 /** Signature for a test function. */ 855 /** Signature for a test function. */
874 typedef void TestFunction(); 856 typedef void TestFunction();
OLDNEW
« pkg/unittest/mock.dart ('K') | « pkg/unittest/mock.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698