| 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 // TODO(rnystrom): This code is gradually moving from a Java/JUnit style to | 5 // TODO(rnystrom): This code is gradually moving from a Java/JUnit style to |
| 6 // something closer to JS/Jasmine. Eventually, the UnitTestSuite class can go | 6 // something closer to JS/Jasmine. Eventually, the UnitTestSuite class can go |
| 7 // away completely (or become private to this library) and the only exposed API | 7 // away completely (or become private to this library) and the only exposed API |
| 8 // will be group()/test()/expect(). Until then, both ways are supported, which | 8 // will be group()/test()/expect(). Until then, both ways are supported, which |
| 9 // is why things look a bit weird in here. | 9 // is why things look a bit weird in here. |
| 10 | 10 |
| (...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 351 | 351 |
| 352 /** | 352 /** |
| 353 * Wraps an value and provides an "==" operator that can be used to verify that | 353 * Wraps an value and provides an "==" operator that can be used to verify that |
| 354 * the value matches a given expectation. | 354 * the value matches a given expectation. |
| 355 */ | 355 */ |
| 356 class Expectation { | 356 class Expectation { |
| 357 final _value; | 357 final _value; |
| 358 | 358 |
| 359 Expectation(this._value); | 359 Expectation(this._value); |
| 360 | 360 |
| 361 // TODO(rnystrom): Get rid of this and use .equals(). After some discussion, | |
| 362 // we decided this is the wrong approach for a bunch of reasons, clever as it | |
| 363 // may be. | |
| 364 /** Asserts that the value is equivalent to the given expected value. */ | 361 /** Asserts that the value is equivalent to the given expected value. */ |
| 365 bool equals(expected) { | 362 void equals(expected) { |
| 366 Expect.equals(expected, _value); | 363 Expect.equals(expected, _value); |
| 367 return _value == expected; | 364 } |
| 365 |
| 366 /** |
| 367 * Failure if the difference between expected and actual is greater than the |
| 368 * given tolerance. If no tolerance is given, tolerance is assumed to be the |
| 369 * value 4 significant digits smaller than the value given for expected. |
| 370 */ |
| 371 void approxEquals(num expected, |
| 372 [num tolerance = null, String reason = null]) { |
| 373 Expect.approxEquals(expected, _value, tolerance: tolerance, reason: reason); |
| 368 } | 374 } |
| 369 | 375 |
| 370 /** Asserts that the value is null. */ | 376 /** Asserts that the value is null. */ |
| 371 void isNull() { | 377 void isNull() { |
| 372 Expect.equals(null, _value); | 378 Expect.equals(null, _value); |
| 373 } | 379 } |
| 374 | 380 |
| 375 /** Asserts that the value is not null. */ | 381 /** Asserts that the value is not null. */ |
| 376 void isNotNull() { | 382 void isNotNull() { |
| 377 Expect.notEquals(null, _value); | 383 Expect.notEquals(null, _value); |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 508 </tr>"""; | 514 </tr>"""; |
| 509 if (stackTrace != null) { | 515 if (stackTrace != null) { |
| 510 message += | 516 message += |
| 511 "<tr><td></td><td colspan='2'><pre>${stackTrace}</pre></td></tr>"; | 517 "<tr><td></td><td colspan='2'><pre>${stackTrace}</pre></td></tr>"; |
| 512 } | 518 } |
| 513 fail = true; | 519 fail = true; |
| 514 } | 520 } |
| 515 } | 521 } |
| 516 | 522 |
| 517 typedef void TestFunction(); | 523 typedef void TestFunction(); |
| OLD | NEW |