| OLD | NEW |
| 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 /** Base class for unit test suites run in a browser. */ | 5 /** Base class for unit test suites run in a browser. */ |
| 6 class UnitTestSuite { | 6 class UnitTestSuite { |
| 7 | 7 |
| 8 /** Tests executed in this suite. */ | 8 /** Tests executed in this suite. */ |
| 9 List<TestCase> _tests; | 9 List<TestCase> _tests; |
| 10 | 10 |
| (...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 292 } | 292 } |
| 293 | 293 |
| 294 window.dynamic/*TODO(5389254)*/.postMessage('unittest-suite-done', '*'); | 294 window.dynamic/*TODO(5389254)*/.postMessage('unittest-suite-done', '*'); |
| 295 } | 295 } |
| 296 } | 296 } |
| 297 | 297 |
| 298 /** | 298 /** |
| 299 * Wraps an value and provides an "==" operator that can be used to verify that | 299 * Wraps an value and provides an "==" operator that can be used to verify that |
| 300 * the value matches a given expectation. | 300 * the value matches a given expectation. |
| 301 */ | 301 */ |
| 302 // TODO(rnystrom): Note that because Dart does not currently allow overloading | |
| 303 // != that this *cannot* be used with !=. If you do expect(1) != 2, it will do | |
| 304 // the exact wrong thing. (It will invoke == which validates that 1 *does* | |
| 305 // equal 2.) If we get an overloadable != operator, that can be fixed. | |
| 306 class Expectation { | 302 class Expectation { |
| 307 final _value; | 303 final _value; |
| 308 | 304 |
| 309 Expectation(this._value); | 305 Expectation(this._value); |
| 310 | 306 |
| 311 /** Asserts that the value is equivalent to the given expected value. */ | 307 /** Asserts that the value is equivalent to the given expected value. */ |
| 312 operator ==(expected) { | 308 bool equals(expected) { |
| 313 Expect.equals(expected, _value); | 309 Expect.equals(expected, _value); |
| 314 return _value == expected; | 310 return _value == expected; |
| 315 } | 311 } |
| 316 | 312 |
| 313 /** Asserts that the value is null. */ |
| 314 void isNull() { |
| 315 Expect.equals(null, _value); |
| 316 } |
| 317 |
| 317 /** Asserts that the value is not null. */ | 318 /** Asserts that the value is not null. */ |
| 318 void isNotNull() { | 319 void isNotNull() { |
| 319 Expect.notEquals(null, _value); | 320 Expect.notEquals(null, _value); |
| 320 } | 321 } |
| 321 | 322 |
| 323 /** Asserts that the value is true. */ |
| 324 void isTrue() { |
| 325 Expect.equals(true, _value); |
| 326 } |
| 327 |
| 328 /** Asserts that the value is null. */ |
| 329 void isFalse() { |
| 330 Expect.equals(false, _value); |
| 331 } |
| 332 |
| 322 /** Asserts that the value has the same elements as the given collection. */ | 333 /** Asserts that the value has the same elements as the given collection. */ |
| 323 void equalsCollection(Collection expected) { | 334 void equalsCollection(Collection expected) { |
| 324 Expect.listEquals(expected, _value); | 335 Expect.listEquals(expected, _value); |
| 325 } | 336 } |
| 326 } | 337 } |
| 327 | 338 |
| 328 /** | 339 /** |
| 329 * A TestSet lets you break a test suite down into a collection of classes to | 340 * A TestSet lets you break a test suite down into a collection of classes to |
| 330 * keep things manageable. It exposes the same interface as UnitTestSuite | 341 * keep things manageable. It exposes the same interface as UnitTestSuite |
| 331 * (test(), group(), expect(), etc.) but defers to a parent suite that owns it. | 342 * (test(), group(), expect(), etc.) but defers to a parent suite that owns it. |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 460 </tr>"""; | 471 </tr>"""; |
| 461 if (stackTrace != null) { | 472 if (stackTrace != null) { |
| 462 message += | 473 message += |
| 463 "<tr><td></td><td colspan='2'><pre>${stackTrace}</pre></td></tr>"; | 474 "<tr><td></td><td colspan='2'><pre>${stackTrace}</pre></td></tr>"; |
| 464 } | 475 } |
| 465 fail = true; | 476 fail = true; |
| 466 } | 477 } |
| 467 } | 478 } |
| 468 | 479 |
| 469 typedef void TestFunction(); | 480 typedef void TestFunction(); |
| OLD | NEW |