| OLD | NEW |
| 1 /* global self */ | 1 /* global self */ |
| 2 | 2 |
| 3 // testharness.js has the higher priority. | 3 // testharness.js has the higher priority. |
| 4 var TESTHARNESS = true; | 4 var TESTHARNESS = true; |
| 5 var JSTEST = false; | 5 var JSTEST = false; |
| 6 | 6 |
| 7 (function () { | 7 (function () { |
| 8 // Selected properies from testharness.js | 8 // Selected properies from testharness.js |
| 9 var testharnessProperties = [ | 9 var testharnessProperties = [ |
| 10 'test', 'async_test', 'promise_test', 'promise_rejects', | 10 'test', 'async_test', 'promise_test', 'promise_rejects', |
| (...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 484 | 484 |
| 485 // If true, verbose output for the failure case is printed, for methods
where this makes | 485 // If true, verbose output for the failure case is printed, for methods
where this makes |
| 486 // sense. | 486 // sense. |
| 487 this.verbose = !opts.brief; | 487 this.verbose = !opts.brief; |
| 488 | 488 |
| 489 // If set, this is the precision with which numbers will be printed. | 489 // If set, this is the precision with which numbers will be printed. |
| 490 this.PRINT_PRECISION = opts.precision; | 490 this.PRINT_PRECISION = opts.precision; |
| 491 } | 491 } |
| 492 | 492 |
| 493 // Internal methods starting with a underscore. | 493 // Internal methods starting with a underscore. |
| 494 ShouldModel.prototype._testPassed = function (msg) { | 494 ShouldModel.prototype._testPassed = function (msg, addNewline) { |
| 495 this._success = true; | 495 this._success = true; |
| 496 var newLine = addNewline ? '\n' : ''; |
| 496 if (TESTHARNESS) { | 497 if (TESTHARNESS) { |
| 497 // Using testharness.js | 498 // Using testharness.js |
| 498 test(function () { | 499 test(function () { |
| 499 assert_true(true); | 500 assert_true(true); |
| 500 }, this.desc + ' ' + msg + '.'); | 501 }, this.desc + ' ' + msg + '.' + newLine); |
| 501 } else { | 502 } else { |
| 502 // Using js-test.js | 503 // Using js-test.js |
| 503 testPassed(this.desc + ' ' + msg + '.'); | 504 testPassed(this.desc + ' ' + msg + '.' + newLine); |
| 504 } | 505 } |
| 505 }; | 506 }; |
| 506 | 507 |
| 507 ShouldModel.prototype._testFailed = function (msg) { | 508 ShouldModel.prototype._testFailed = function (msg, addNewline) { |
| 508 this._success = false; | 509 this._success = false; |
| 509 var that = this; | 510 var that = this; |
| 511 var newLine = addNewline ? '\n' : ''; |
| 510 if (TESTHARNESS) { | 512 if (TESTHARNESS) { |
| 511 test(function () { | 513 test(function () { |
| 512 assert_true(false, that.desc + ' ' + msg + '.'); | 514 assert_true(false, that.desc + ' ' + msg + '.' + newLine); |
| 513 }, this.desc); | 515 }, this.desc); |
| 514 } else { | 516 } else { |
| 515 testFailed(this.desc + ' ' + msg + '.'); | 517 testFailed(this.desc + ' ' + msg + '.' + newLine); |
| 516 } | 518 } |
| 517 }; | 519 }; |
| 518 | 520 |
| 519 ShouldModel.prototype._isArray = function (arg) { | 521 ShouldModel.prototype._isArray = function (arg) { |
| 520 return arg instanceof Array || arg instanceof Float32Array || arg instance
of Uint8Array || | 522 return arg instanceof Array || arg instanceof Float32Array || arg instance
of Uint8Array || |
| 521 arg instanceof Uint16Array || arg instanceof Uint32Array || arg instance
of Int8Array || | 523 arg instanceof Uint16Array || arg instanceof Uint32Array || arg instance
of Int8Array || |
| 522 arg instanceof Int16Array || arg instanceof Int32Array || arg instanceof
Uint8ClampedArray || | 524 arg instanceof Int16Array || arg instanceof Int32Array || arg instanceof
Uint8ClampedArray || |
| 523 arg instanceof Float64Array; | 525 arg instanceof Float64Array; |
| 524 }; | 526 }; |
| 525 | 527 |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 644 }; | 646 }; |
| 645 | 647 |
| 646 // Check if |target| is not equal to |value|. | 648 // Check if |target| is not equal to |value|. |
| 647 // | 649 // |
| 648 // Example: | 650 // Example: |
| 649 // Should('One', one).notBeEqualTo(0); | 651 // Should('One', one).notBeEqualTo(0); |
| 650 // Result: | 652 // Result: |
| 651 // "PASS One is not equal to 0." | 653 // "PASS One is not equal to 0." |
| 652 ShouldModel.prototype.notBeEqualTo = function (value) { | 654 ShouldModel.prototype.notBeEqualTo = function (value) { |
| 653 var type = typeof value; | 655 var type = typeof value; |
| 654 this._assert(type === 'number' || type === 'string', | 656 this._assert(type === 'number' || type === 'string' || type === "boolean
", |
| 655 'value should be number or string for', value); | 657 'value should be number, string, or boolean for', value); |
| 656 | 658 |
| 657 this._checkNaN(value, 'EXPECTED'); | 659 this._checkNaN(value, 'EXPECTED'); |
| 658 | 660 |
| 659 if (this.target === value) | 661 if (this.target === value) |
| 660 this._testFailed('should not be equal to ' + value); | 662 this._testFailed('should not be equal to ' + value); |
| 661 else | 663 else |
| 662 this._testPassed('is not equal to ' + value); | 664 this._testPassed('is not equal to ' + value); |
| 663 return this._success; | 665 return this._success; |
| 664 }; | 666 }; |
| 665 | 667 |
| (...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1159 // A summary message | 1161 // A summary message |
| 1160 // | 1162 // |
| 1161 // Example: | 1163 // Example: |
| 1162 // Should("Summary1", true).summarize("passed1", "failed1"); | 1164 // Should("Summary1", true).summarize("passed1", "failed1"); |
| 1163 // Should("Summary2", false).summarize("passed2", "failed2"); | 1165 // Should("Summary2", false).summarize("passed2", "failed2"); |
| 1164 // Result: | 1166 // Result: |
| 1165 // "PASS Summary1: passed1." | 1167 // "PASS Summary1: passed1." |
| 1166 // "FAIL Summary2: failed2." | 1168 // "FAIL Summary2: failed2." |
| 1167 ShouldModel.prototype.summarize = function (pass, fail) { | 1169 ShouldModel.prototype.summarize = function (pass, fail) { |
| 1168 if (this.target) | 1170 if (this.target) |
| 1169 this._testPassed(pass); | 1171 this._testPassed(pass, true); |
| 1170 else | 1172 else |
| 1171 this._testFailed(fail); | 1173 this._testFailed(fail, true); |
| 1172 return this._success; | 1174 return this._success; |
| 1173 } | 1175 } |
| 1174 | 1176 |
| 1175 // Should() method. | 1177 // Should() method. |
| 1176 // | 1178 // |
| 1177 // |desc| is the description of the task or check and |target| is a value | 1179 // |desc| is the description of the task or check and |target| is a value |
| 1178 // needs to be checked or a task to be performed. |opt| contains options for | 1180 // needs to be checked or a task to be performed. |opt| contains options for |
| 1179 // printing out log messages: options are |opt.numberOfErrorLog| and | 1181 // printing out log messages: options are |opt.numberOfErrorLog| and |
| 1180 // |opts.numberOfArrayLog|. | 1182 // |opts.numberOfArrayLog|. |
| 1181 return function (desc, target, opts) { | 1183 return function (desc, target, opts) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1193 if (opts.hasOwnProperty('brief')) | 1195 if (opts.hasOwnProperty('brief')) |
| 1194 _opts.brief = opts.brief; | 1196 _opts.brief = opts.brief; |
| 1195 if (opts.hasOwnProperty('precision')) | 1197 if (opts.hasOwnProperty('precision')) |
| 1196 _opts.precision = opts.precision; | 1198 _opts.precision = opts.precision; |
| 1197 } | 1199 } |
| 1198 | 1200 |
| 1199 return new ShouldModel(desc, target, _opts); | 1201 return new ShouldModel(desc, target, _opts); |
| 1200 }; | 1202 }; |
| 1201 | 1203 |
| 1202 })(); | 1204 })(); |
| OLD | NEW |