should.js-8.4.0~dfsg/000077500000000000000000000000001301217646700145055ustar00rootroot00000000000000should.js-8.4.0~dfsg/.eslintrc.yml000066400000000000000000000012261301217646700171320ustar00rootroot00000000000000 --- root: true extends: eslint:recommended env: node: true mocha: true browser: true rules: quotes: 0 indent: 0 require-jsdoc: 0 eqeqeq: 0 no-invalid-this: 0 default-case: 0 no-nested-ternary: 0 no-underscore-dangle: 0 func-style: 0 new-cap: 0 callback-return: 0 no-loop-func: 0 strict: 0 semi: [1, "always"] space-before-function-paren: [1, "never"] space-before-blocks: [1, "always"] keyword-spacing: [1, {"before": true, "after": true, "overrides": {}}] no-sequences: 2 dot-notation: 1 dot-location: [2, "property"] curly: 2 no-case-declarations: 0 no-console: 0 global-require: 2 no-path-concat: 2 should.js-8.4.0~dfsg/.github/000077500000000000000000000000001301217646700160455ustar00rootroot00000000000000should.js-8.4.0~dfsg/.github/ISSUE_TEMPLATE.md000066400000000000000000000001631301217646700205520ustar00rootroot00000000000000Hi. Answer several questions if it is a bug: ## Node.js version? ## Should.js version? ## How to reproduce it? should.js-8.4.0~dfsg/.gitignore000066400000000000000000000001211301217646700164670ustar00rootroot00000000000000node_modules .DS_Store desktop.ini .idea should.js.for-tests *.swp npm-debug.log should.js-8.4.0~dfsg/.npmignore000066400000000000000000000000231301217646700164770ustar00rootroot00000000000000examples test .ideashould.js-8.4.0~dfsg/.travis.yml000066400000000000000000000010021301217646700166070ustar00rootroot00000000000000language: node_js node_js: - '0.12' script: - test $SAUCE_USERNAME && npm run zuul || echo 'not running on saucelabs' - npm test env: global: - secure: aB4+vAj+mJHqQfnq9x10eZ5//erfxecs3l9u/oSJX1Ok+WLrpUW0x3qpaC1bEEPq4bkAuIifxohnPv0XTE3m8GyTfRHzqmeNnNQNsnex3IzunbU4aG7QyS3jFa6gjT5OrgPA+eHobNXBvwASZczighlWtoYKD5RW7Uak4E8EpPs= - secure: kJaOWFzFnSGEZ4keShHST18OC6z+rmvnnht0SwqmhPlBX4nBQ2bdBR09n0O/GVQ0uAzohn1oObouQH0yuXpbgmk4whMVZgt8RPztusLskt88fE9EOPFNA+YOWNpmcelDiXsMXv7vN2bBlZJSrILUgUppuHIqsdqTGWut08l3Zhg= should.js-8.4.0~dfsg/.zuul.yml000066400000000000000000000002671301217646700163120ustar00rootroot00000000000000ui: mocha-bdd browsers: - name: chrome version: 45..latest - name: ie version: 9..latest - name: firefox version: 40..latest - name: safari version: 6..latest should.js-8.4.0~dfsg/CONTRIBUTING.md000066400000000000000000000022541301217646700167410ustar00rootroot00000000000000Before contribute something: Follow simple rules: - Not violate [DRY](http://programmer.97things.oreilly.com/wiki/index.php/Don%27t_Repeat_Yourself). - [Boy Scout Rule](http://programmer.97things.oreilly.com/wiki/index.php/The_Boy_Scout_Rule) needs to have been applied. 1. Your code should look like all the other code - this project should look like it was written by one man, always. 2. If you want to propose something - just create an issue and describe your question with as much description as you can. 3. Please never send issues or pull requests about code style, jshint violations etc - I do not accept it (and you will spend your time for free). 4. If you think you have some general improvement, consider creating a pull request with it. 5. If you are not sure whether your improvement is general enough, just create your own plugin for should.js. (see should.use and Assertion.add usage). 6. If you add new code, it should be covered by tests. No tests - no code. 7. If you find a bug (or at least you think it is a bug), create an issue with the library version and test case that I can run and see what are you talking about, or at least full steps by which I can reproduce it. should.js-8.4.0~dfsg/History.md000066400000000000000000000315771301217646700165050ustar00rootroot000000000000008.4.0 / 2016-05-21 ================== * Add support for Symbols in .eql 8.3.2 / 2016-05-18 ================== * Fix for `should-equal` to do not call .toString when checking circular usage 8.3.1 / 2016-04-15 ================== * Fix browser script to again be UMD bundle 8.3.0 / 2016-03-23 ================== * .true() and .false() can accept optional message to be used in assertion Error * Add more useful messages to promise assertions 8.2.2 / 2016-02-09 ================== * Fix bug with .match when called primitive to match object * Various linting issues 8.2.1 / 2016-01-27 ================== * Fix bug with new option, thanks @VinGarcia 8.2.0 / 2016-01-24 ================== * Add option to should.equal to treat -0 and +0 as equals 8.1.1 / 2016-01-10 ================== * Fix browser build to do not loose window.Should 8.1.0 / 2016-01-10 ================== * Add .Date() assertion to test if given object is Date instance 8.0.2 / 2015-12-18 ================== * Update should-format to fix bug in formatting arrow functions 8.0.1 / 2015-12-11 ================== * Fix throwing TypeError in .match 8.0.0 / 2015-12-08 ================== * Move should-promised to main repo * Expose window.should as should function and not a getter 7.1.1 / 2015-10-20 ================== * Update format package to fix node 0.12 Symbol formatting 7.1.0 / 2015-08-28 ================== * Added .aboveOrEqual and .belowOrEqual for numbers (<= and >=) * Added .oneOf and .equalOneOf to check equality of one of values * Added 'browser' field to package.json 7.0.4 / 2015-08-14 ================== * Missing doc for .deepEqual * Fix .match and dependent assertions to check property in object-object matching 7.0.3 / 2015-08-09 ================== * Add alias .deepEqual for .eql 7.0.2 / 2015-07-09 ================== * Bug in browser script and build 7.0.1 / 2015-06-18 ================== * Fixes in should-type for dom nodes, host object and promises 7.0.0 / 2015-06-18 ================== * Added support to `.eql` es6 set, map and symbol (`should-type`, `should-format`, `should-equal`) * **Breaking Change** More accurate work with types (dom nodes, typed-arrays). * **Breaking Change** Change result of should-type to be more accurate and consistent. * Fixed should-equal options checks * Fixed should-format typed arrays (more then 8 bits) * Added aliases: .matchEach => .matchSome, .matchAny => .matchEvery (to be similar to array methods). See #65. * **Breaking Change (possibly)** .matchEach and .matchAny now uses internally .match. See #65. * **Breaking Change** No more getter assertions. No all assertions are functions. * **Breaking Change** No more proxy returning, to check property names. * **Breaking Change** `should-format` now looks more like chrome developer tools inpections. 6.0.3 / 2015-05-18 ================== * Replace rest of usage after 6.0.2 6.0.2 / 2015-05-18 ================== * Replace in all internal assertions `should` usage to non getter form 6.0.1 / 2015-04-15 ================== * Remove dummy debug messages 6.0.0 / 2015-04-15 ================== * From .containDeep* removed .indexOf checks for strings, now it is just equality checks (see #55) * Fix for .not.throws for generators 5.2.0 / 2015-03-12 ================== * Added `.matchAny`, like `.matchEach` but with `some` semantics 5.1.0 / 2015-03-05 ================== * Initial support of es6 generators, iterables, iterators and symbols * .throwError now support generator functions * Fix bug in .propertyByPath 5.0.1 / 2015-02-21 ================== * Export utils via should.util 5.0.0 / 2015-02-10 ================== * Remove old .eql implementation * Refactor nested errors * Added separate reporting message for false negative results like 10.should.not.equal(10) * Make error.message lazy fix old perfomance bottlenecks for constructing messages for big objects * Added .propertyWithDescriptor 4.6.5 / 2015-02-05 ================== * Fix perfomance degradation on large objects 4.6.4 / 2015-02-05 ================== * Fix end cases for .containDeep and .containDeepOrdered 4.6.3 / 2015-02-01 ================== * Added small check for .noConflict * Fix end cases for .containDeep and .containDeepOrdered 4.6.2 / 2015-01-28 ================== * Make assertion properties configurable 4.6.1 / 2015-01-18 ================== * Bump deps * Set showDiff only if the same types 4.6.0 / 2015-01-13 ================== * Wrap everywhere returned assertion with Proxy if available. 4.5.2 / 2015-01-13 ================== * Fixed null properties in .containDeep and .containDeepOrdered 4.5.1 / 2015-01-13 ================== * Fixed leaked \_eql 4.5.0 / 2015-01-11 ================== * Added config flag .useOldDeepEqual to use old .eql implementation 4.4.4 / 2015-01-08 ================== * Added .enumerables 4.4.3 / 2015-01-08 ================== * Bump dependencies to get more accurate format of promise * Added a lot of jsdocs 4.4.2 / 2014-12-27 ================== * Remove breaking change with should-equal that check also object prototypes. Instead document how get both behaviours in .eql docs. 4.4.1 / 2014-12-13 ================== * bump deps 4.4.0 / 2014-12-12 ================== * assert methods reimplemented via assertion, deepEqual done via should-equal. To avoid possible confusion between should.deepEqual and a.should.eql(b) * Possible fix for error tests 4.3.1 / 2014-12-08 ================== * `.throw()` check if given object is a function 4.3.0 / 2014-11-10 ================== * Remove node's version of .eql * Added reason why .eql failed 4.2.1 / 2014-11-07 ================== * Move inspection from .formattedObj to be in .getMessage - to make inspection as late as possible. 4.2.0 / 2014-11-06 ================== * Remove node util.inspect and use instead own inspection module with type detection and browser types compatibility 4.1.0 / 2014-10-19 ================== * As inspect function was moved to repo, refine how it show Dates (added millis via custom format) * Added warnings for potential shoot in the leg: eql non strict and should unwrapping primitive wrappers * Added possibility to disable any warnings via environment variable SHOULDJS_WARN and should.warn = false * Added new deep equality check function * Nested assertions can contribute to parent assertions own messages 4.0.4 / 2014-06-09 ================== * Make all assertions enumerable in Assertion.prototype 4.0.3 / 2014-06-09 ================== * Fix wrong/strange behaviour of .containDeep with equal keys. Now it check to contain element once. * Added util.formatProp to format properties more accurate 4.0.1 / 2014-06-04 ================== * Missing name in browser script 4.0.0 / 2014-05-29 ================== * Breaking change: Move non core assertions out * Added casting in properties assertions to String for all property names * Added .propertyByPath assertion * Breaking change: Remove deprecated .includeEql and .include * Breaking change: .containDeep now do not check order for 2 arrays case * Added .containDeepOrdered for old .containDeep * Added support of array-like objects * Added to .throw matching by error properties with .match 3.3.2 / 2014-05-23 ================== * Fix for should.format 3.3.1 / 2014-04-16 ================== * Added aliases for es reserved words * Fix bug with ownProperty alias * Fix bug with not function alias 3.3.0 / 2014-04-07 ================== * Added .enumerable(name, val) 3.2.0 / 2014-03-29 ================== * Added first version of .any modifier that affect assertions with multiple parameters * .header now have more nice message * assertion can now override how to show object 3.1.4 / 2014-03-18 ================== * .Error now do not throw assertion error for custom errors. 3.1.3 / 2014-02-25 ================== * Fix TypeError in .containEql 3.1.2 / 2014-01-28 ================== * Fix for adding .inspect for JQuery object only in case when it is exist 3.1.1 / 2014-01-28 ================== * Fix for HTMLElement in DOM less environments 3.1.0 / 2014-01-23 ================== * Added jquery based browser extension 3.0.1 / 2014-01-17 ================== * Fix: .lengthOf() 3.0.0 / 2014-01-17 ================== * Split everything to smaller files * Added huge extension to .match and .matchEach. Thanks @alsotang for initial code and idea. * Added .containDeep and .containEql * Separate build for browser and node.js * Basic plugin system * Breaking change: .Object now do not fail on arrays * Breaking change: Additional messages now replaces generated and do not added * Breaking change: .keys now check as is - no keys in args means no keys in object * Deprecated: assert extension * Deprecated: .include and .includeEql * Now all assertions define only positive cases, should.js take care about negations and chains 2.1.1 / 2013-12-05 ================== * Move date formatting out of should.inspect 2.1.0 / 2013-11-11 ================== * Override .inspect for Date's to convert them to ISOString 2.0.2 / 2013-10-21 ================== * Add '#of' as getter for chaining. * Exclude browser script for .npmignore. 2.0.1 / 2013-10-10 ================== * Fix wrong path in .npmignore. 2.0.0 / 2013-10-10 ================== * breaking change: #a now getter like #an. Was replaced with #type(str) * breaking change: #empty does not check length for objects. Now it check if object do not have own properties. * #properties check if object have some properties * util.inspect now exposed as should.inspect * assertions for NaN, Infinity, Array, Object, String, Boolean, Number, Error, Function * #equal got alias #exactly 1.3.0 / 2013-09-13 ================== * fix doc for .keys. Closes #108. * add #endWith() * add .startWith (#119) 1.2.2 / 2013-02-19 ================== * fix should.be.instanceOf() failure on Date 1.2.1 / 2012-11-02 ================== * add .showDiff * Make instanceOf and throwError be aliased like others [alFReD-NSH] * Fix should[.not].exist not having stack trace #84 [alFReD-NSH] 1.2.0 / 2012-09-21 ================== * Added #approximately(value, delta, description) for doing assertions on results of operations with numbers. [titarenko] 1.1.1 / 2012-09-19 ================== * add .type for eql()s assert 1.1.0 / 2012-07-30 ================== * add enclosing of failure message functions. Closes #81 * add mocha .actual / .expected string support for all assertion values 0.7.0 / 2012-07-17 ================== * add `.throw(Constructor)` support [snakamura] 0.6.3 / 2012-04-26 ================== * Added object inclusion support back 0.6.2 / 2012-04-26 ================== * Added homepage to package.json * Fixed .equal() with dates. Closes #63 0.6.1 / 2012-04-10 ================== * package: add "repository" section [TooTallNate] * use valueOf() to get the reference the object [TooTallNate] 0.6.0 / 2012-03-01 ================== * Added `err.actual` and `err.expected` for .{eql,equal}() * Added 'return this;' to 'get json' and 'get html' in order to provide chaining for should.be.json and should.be.html 0.5.1 / 2012-01-13 ================== * Added better `.json` * Added better `.html` 0.5.0 / 2012-01-12 ================== * Added string matching to `.throw()` [serby] * Added regexp matching to `.throw()` [serby] * Added `.includeEql()` [RubenVerborgh] * Added `.should.be.html` * Added `.should.be.json` * Added optional description args to most matchers [Mike Swift] 0.4.2 / 2011-12-17 ================== * Fixed .header() for realzzz 0.4.1 / 2011-12-16 ================== * Fixed: chain .header() to retain negation 0.4.0 / 2011-12-16 ================== * Added `.should.throw()` * Added `.include()` support for strings * Added `.include()` support for arrays * Removed `keys()` `.include` modifier support * Removed `.object()` * Removed `.string()` * Removed `.contain()` * Removed `.respondTo()` rubyism * expresso -> mocha 0.3.2 / 2011-10-24 ================== * Fixed tests for 0.5.x * Fixed sys warning 0.3.1 / 2011-08-22 ================== * configurable 0.3.0 / 2011-08-20 ================== * Added assertion for inclusion of an object: `foo.should.include.object({ foo: 'bar' })` 0.2.1 / 2011-05-13 ================== * Fixed .status(code). Closes #18 0.2.0 / 2011-04-17 ================== * Added `res.should.have.status(code)` method * Added `res.should.have.header(field, val)` method 0.1.0 / 2011-04-06 ================== * Added `should.exist(obj)` [aseemk] * Added `should.not.exist(obj)` [aseemk] 0.0.4 / 2010-11-24 ================== * Added `.ok` to assert truthfulness * Added `.arguments` * Fixed double required bug. [thanks dominictarr] 0.0.3 / 2010-11-19 ================== * Added `true` / `false` assertions 0.0.2 / 2010-11-19 ================== * Added chaining support 0.0.1 / 2010-11-19 ================== * Initial release should.js-8.4.0~dfsg/LICENSE000066400000000000000000000020731301217646700155140ustar00rootroot00000000000000Copyright (c) 2010-2014 TJ Holowaychuk Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.should.js-8.4.0~dfsg/Readme.md000066400000000000000000000154311301217646700162300ustar00rootroot00000000000000# should.js [![Join the chat at https://gitter.im/shouldjs/should.js](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/shouldjs/should.js) [![Build Status](https://travis-ci.org/shouldjs/should.js.svg?branch=master)](https://travis-ci.org/shouldjs/should.js) [![Selenium Test Status](https://saucelabs.com/browser-matrix/shouldjs.svg)](https://saucelabs.com/u/shouldjs) _should_ is an expressive, readable, framework-agnostic assertion library. The main goals of this library are __to be expressive__ and __to be helpful__. It keeps your test code clean, and your error messages helpful. By default (when you `require('should')`) _should_ extends the `Object.prototype` with a single non-enumerable getter that allows you to express how that object should behave. It also returns itself when required with `require`. It is also possible to use should.js without getter (it will not even try to extend Object.prototype), just `require('should/as-function')`. Or if you already use version that auto add getter, you can call `.noConflict` function. **Results of `(something).should` getter and `should(something)` in most situations are the same** ### Upgrading instructions Please check [wiki page](https://github.com/shouldjs/should.js/wiki/Breaking-changes) for upgrading instructions. ### FAQ You can take look in [FAQ](https://github.com/shouldjs/should.js/wiki/FAQ). ## Example ```javascript var should = require('should'); var user = { name: 'tj' , pets: ['tobi', 'loki', 'jane', 'bandit'] }; user.should.have.property('name', 'tj'); user.should.have.property('pets').with.lengthOf(4); // If the object was created with Object.create(null) // then it doesn't inherit `Object.prototype`, so it will not have `.should` getter // so you can do: should(user).have.property('name', 'tj'); // also you can test in that way for null's should(null).not.be.ok(); someAsyncTask(foo, function(err, result){ should.not.exist(err); should.exist(result); result.bar.should.equal(foo); }); ``` ## To begin 1. Install it: ```bash $ npm install should --save-dev ``` 2. Require it and use: ```js var should = require('should'); (5).should.be.exactly(5).and.be.a.Number(); ``` ```js var should = require('should/as-function'); should(10).be.exactly(5).and.be.a.Number(); ``` ## In browser Well, even when browsers by complaints of authors have 100% es5 support, it does not mean it has no bugs. Please see [wiki](https://github.com/shouldjs/should.js/wiki/Known-Bugs) for known bugs. If you want to use _should_ in browser, use the `should.js` file in the root of this repository, or build it yourself. To build a fresh version: ```bash $ npm install $ gulp script ``` The script is exported to `window.should`: ```js should(10).be.exactly(10) ``` You can easy install it with npm or bower: ```sh npm install should -D # or bower install shouldjs/should.js ``` ## API docs Actual api docs generated by jsdoc comments and available at [http://shouldjs.github.io](http://shouldjs.github.io). ## Usage examples Please look on usage in [examples](https://github.com/shouldjs/examples) ## .not `.not` negates the current assertion. ## .any `.any` allow for assertions with multiple parameters to assert any of the parameters (but not all). This is similar to the native JavaScript [array.some](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/some). # Assertions ## chaining assertions Every assertion will return a `should.js`-wrapped Object, so assertions can be chained. To help chained assertions read more clearly, you can use the following helpers anywhere in your chain: `.an`, `.of`, `.a`, `.and`, `.be`, `.have`, `.with`, `.is`, `.which`. Use them for better readability; they do nothing at all. For example: ```js user.should.be.an.instanceOf(Object).and.have.property('name', 'tj'); user.pets.should.be.instanceof(Array).and.have.lengthOf(4); ``` Almost all assertions return the same object - so you can easy chain them. But some (eg: `.length` and `.property`) move the assertion object to a property value, so be careful. ## Adding own assertions Adding own assertion is pretty easy. You need to call `should.Assertion.add` function. It accept 2 arguments: 1. name of assertion method (string) 2. assertion function (function) What assertion function should do. It should check only positive case. `should` will handle `.not` itself. `this` in assertion function will be instance of `should.Assertion` and you **must** define in any way this.params object in your assertion function call before assertion check happen. `params` object can contain several fields: - `operator` - it is string which describe your assertion - `actual` it is actual value, you can assume it is your own this.obj if you need to define you own - `expected` it is any value that expected to be matched this.obj You can assume its usage in generating AssertionError message like: expected `obj`? || this.obj not? `operator` `expected`? In `should` sources appeared 2 kinds of usage of this method. First not preferred and used **only** for shortcuts to other assertions, e.g how `.should.be.true()` defined: ```javascript Assertion.add('true', function() { this.is.exactly(true); }); ``` There you can see that assertion function do not define own `this.params` and instead call within the same assertion `.exactly` that will fill `this.params`. **You should use this way very carefully, but you can use it**. Second way preferred and i assume you will use it instead of first. ```javascript Assertion.add('true', function() { this.params = { operator: 'to be true', expected: true }; should(this.obj).be.exactly(true); }); ``` in this case this.params defined and then used new assertion context (because called `.should`). Internally this way does not create any edge cases as first. ```javascript Assertion.add('asset', function() { this.params = { operator: 'to be asset' }; this.obj.should.have.property('id').which.is.a.Number(); this.obj.should.have.property('path'); }) //then > ({ id: '10' }).should.be.an.asset(); AssertionError: expected { id: '10' } to be asset expected '10' to be a number > ({ id: 10 }).should.be.an.asset(); AssertionError: expected { id: 10 } to be asset expected { id: 10 } to have property path ``` ## Contributions [Actual list of contributors](https://github.com/visionmedia/should.js/graphs/contributors) if you want to show it your friends. To run the tests for _should_ simply run: $ npm test See also [CONTRIBUTING](./CONTRIBUTING.md). ## OMG IT EXTENDS OBJECT???!?!@ Yes, yes it does, with a single getter _should_, and no it won't break your code, because it does this **properly** with a non-enumerable property. Also it is possible use it without extension. ## License MIT © 2010-2014 TJ Holowaychuk should.js-8.4.0~dfsg/as-function.js000066400000000000000000000000521301217646700172660ustar00rootroot00000000000000module.exports = require('./lib/should'); should.js-8.4.0~dfsg/bower.json000066400000000000000000000010351301217646700165150ustar00rootroot00000000000000{ "name": "should", "main": "should.js", "homepage": "https://github.com/shouldjs/should.js", "repository": { "type": "git", "url": "git://github.com/shouldjs/should.js.git" }, "authors": [ "TJ Holowaychuk and contributors" ], "description": "test framework agnostic BDD-style assertions", "keywords": [ "test", "bdd", "assert", "should" ], "license": "MIT", "ignore": [ "**/.*", "node_modules", "test", "*.md", "LICENSE", "package.json" ] } should.js-8.4.0~dfsg/browser-entry.js000066400000000000000000000000351301217646700176630ustar00rootroot00000000000000should = require('./index'); should.js-8.4.0~dfsg/gulpfile.js000066400000000000000000000033501301217646700166530ustar00rootroot00000000000000'use strict'; const gulp = require('gulp'); const derequire = require('gulp-derequire'); const wrapper = require('gulp-wrapper'); const uglify = require('gulp-uglify'); const rename = require('gulp-rename'); const source = require('vinyl-source-stream'); const buffer = require('vinyl-buffer'); const browserify = require('browserify'); const collapse = require('bundle-collapser'); const pkg = require('./package.json'); const template = require('lodash.template') const header = template(` /*! * <%= pkg.name %> - <%= pkg.description %> * @version v<%= pkg.version %> * @author <%= pkg.author %> * @link <%= pkg.homepage %> * @license <%= pkg.license %> */ ;(function (root, factory) { if (typeof define === 'function' && define.amd) { define([], factory); } else if (typeof module === 'object' && module.exports) { module.exports = factory(); } else { root.Should = factory(); Object.defineProperty(root, 'should', { enumerable: false, configurable: true, value: root.Should }); } }(this, function () { var should, require = null; `, { variable: 'pkg' })(pkg); var footer = ` return should; })); `; gulp.task('script', () => { var bundleStream = browserify({ entries: './browser-entry', builtins: null, insertGlobals: false, detectGlobals: false, fullPaths: false, hasExports: false }) .plugin('bundle-collapser/plugin') .bundle(); return bundleStream .pipe(source('should.js')) .pipe(buffer()) .pipe(derequire()) .pipe(wrapper({ header, footer })) .pipe(gulp.dest('./')) .pipe(uglify({ preserveComments: 'some' })) .pipe(rename('should.min.js')) .pipe(gulp.dest('./')); }); gulp.task('default', ['script']); should.js-8.4.0~dfsg/index.js000066400000000000000000000004641301217646700161560ustar00rootroot00000000000000var should = require('./lib/should'); var defaultProto = Object.prototype; var defaultProperty = 'should'; //Expose api via `Object#should`. try { var prevShould = should.extend(defaultProperty, defaultProto); should._prevShould = prevShould; } catch(e) { //ignore errors } module.exports = should; should.js-8.4.0~dfsg/lib/000077500000000000000000000000001301217646700152535ustar00rootroot00000000000000should.js-8.4.0~dfsg/lib/assertion-error.js000066400000000000000000000045411301217646700207530ustar00rootroot00000000000000/* * should.js - assertion library * Copyright(c) 2010-2013 TJ Holowaychuk * Copyright(c) 2013-2016 Denis Bardadym * MIT Licensed */ var util = require('./util'); /** * should AssertionError * @param {Object} options * @constructor * @memberOf should * @static */ var AssertionError = function AssertionError(options) { util.merge(this, options); if (!options.message) { Object.defineProperty(this, 'message', { get: function() { if (!this._message) { this._message = this.generateMessage(); this.generatedMessage = true; } return this._message; }, configurable: true, enumerable: false } ); } if (Error.captureStackTrace) { Error.captureStackTrace(this, this.stackStartFunction); } else { // non v8 browsers so we can have a stacktrace var err = new Error(); if (err.stack) { var out = err.stack; if (this.stackStartFunction) { // try to strip useless frames var fn_name = util.functionName(this.stackStartFunction); var idx = out.indexOf('\n' + fn_name); if (idx >= 0) { // once we have located the function frame // we need to strip out everything before it (and its line) var next_line = out.indexOf('\n', idx + 1); out = out.substring(next_line + 1); } } this.stack = out; } } }; var indent = ' '; function prependIndent(line) { return indent + line; } function indentLines(text) { return text.split('\n').map(prependIndent).join('\n'); } // assert.AssertionError instanceof Error AssertionError.prototype = Object.create(Error.prototype, { name: { value: 'AssertionError' }, generateMessage: { value: function() { if (!this.operator && this.previous) { return this.previous.message; } var actual = util.format(this.actual); var expected = 'expected' in this ? ' ' + util.format(this.expected) : ''; var details = 'details' in this && this.details ? ' (' + this.details + ')' : ''; var previous = this.previous ? '\n' + indentLines(this.previous.message) : ''; return 'expected ' + actual + (this.negate ? ' not ' : ' ') + this.operator + expected + details + previous; } } }); module.exports = AssertionError; should.js-8.4.0~dfsg/lib/assertion.js000066400000000000000000000160601301217646700176230ustar00rootroot00000000000000/* * should.js - assertion library * Copyright(c) 2010-2013 TJ Holowaychuk * Copyright(c) 2013-2016 Denis Bardadym * MIT Licensed */ var AssertionError = require('./assertion-error'); /** * should Assertion * @param {*} obj Given object for assertion * @constructor * @memberOf should * @static */ function Assertion(obj) { this.obj = obj; this.anyOne = false; this.negate = false; this.params = {actual: obj}; } Assertion.prototype = { constructor: Assertion, /** * Base method for assertions. * * Before calling this method need to fill Assertion#params object. This method usually called from other assertion methods. * `Assertion#params` can contain such properties: * * `operator` - required string containing description of this assertion * * `obj` - optional replacement for this.obj, it usefull if you prepare more clear object then given * * `message` - if this property filled with string any others will be ignored and this one used as assertion message * * `expected` - any object used when you need to assert relation between given object and expected. Like given == expected (== is a relation) * * `details` - additional string with details to generated message * * @memberOf Assertion * @category assertion * @param {*} expr Any expression that will be used as a condition for asserting. * @example * * var a = new should.Assertion(42); * * a.params = { * operator: 'to be magic number', * } * * a.assert(false); * //throws AssertionError: expected 42 to be magic number */ assert: function(expr) { if (expr) { return this; } var params = this.params; if ('obj' in params && !('actual' in params)) { params.actual = params.obj; } else if (!('obj' in params) && !('actual' in params)) { params.actual = this.obj; } params.stackStartFunction = params.stackStartFunction || this.assert; params.negate = this.negate; params.assertion = this; throw new AssertionError(params); }, /** * Shortcut for `Assertion#assert(false)`. * * @memberOf Assertion * @category assertion * @example * * var a = new should.Assertion(42); * * a.params = { * operator: 'to be magic number', * } * * a.fail(); * //throws AssertionError: expected 42 to be magic number */ fail: function() { return this.assert(false); } }; /** * Assertion used to delegate calls of Assertion methods inside of Promise. * It has almost all methods of Assertion.prototype * * @param {Promise} obj */ function PromisedAssertion(/* obj */) { Assertion.apply(this, arguments); } /** * Make PromisedAssertion to look like promise. Delegate resolve and reject to given promise. * * @private * @returns {Promise} */ PromisedAssertion.prototype.then = function(resolve, reject) { return this.obj.then(resolve, reject); }; /** * Way to extend Assertion function. It uses some logic * to define only positive assertions and itself rule with negative assertion. * * All actions happen in subcontext and this method take care about negation. * Potentially we can add some more modifiers that does not depends from state of assertion. * * @memberOf Assertion * @static * @param {String} name Name of assertion. It will be used for defining method or getter on Assertion.prototype * @param {Function} func Function that will be called on executing assertion * @example * * Assertion.add('asset', function() { * this.params = { operator: 'to be asset' } * * this.obj.should.have.property('id').which.is.a.Number() * this.obj.should.have.property('path') * }) */ Assertion.add = function(name, func) { Object.defineProperty(Assertion.prototype, name, { enumerable: true, configurable: true, value: function() { var context = new Assertion(this.obj, this, name); context.anyOne = this.anyOne; try { func.apply(context, arguments); } catch (e) { // check for fail if (e instanceof AssertionError) { // negative fail if (this.negate) { this.obj = context.obj; this.negate = false; return this; } if (context !== e.assertion) { context.params.previous = e; } // positive fail context.negate = false; context.fail(); } // throw if it is another exception throw e; } // negative pass if (this.negate) { context.negate = true; // because .fail will set negate context.params.details = 'false negative fail'; context.fail(); } // positive pass if (!this.params.operator) { this.params = context.params; // shortcut } this.obj = context.obj; this.negate = false; return this; } }); Object.defineProperty(PromisedAssertion.prototype, name, { enumerable: true, configurable: true, value: function() { var args = arguments; this.obj = this.obj.then(function(a) { return a[name].apply(a, args); }); return this; } }); }; /** * Add chaining getter to Assertion like .a, .which etc * * @memberOf Assertion * @static * @param {string} name name of getter * @param {function} [onCall] optional function to call */ Assertion.addChain = function(name, onCall) { onCall = onCall || function() {}; Object.defineProperty(Assertion.prototype, name, { get: function() { onCall.call(this); return this; }, enumerable: true }); Object.defineProperty(PromisedAssertion.prototype, name, { enumerable: true, configurable: true, get: function() { this.obj = this.obj.then(function(a) { return a[name]; }); return this; } }); }; /** * Create alias for some `Assertion` property * * @memberOf Assertion * @static * @param {String} from Name of to map * @param {String} to Name of alias * @example * * Assertion.alias('true', 'True') */ Assertion.alias = function(from, to) { var desc = Object.getOwnPropertyDescriptor(Assertion.prototype, from); if (!desc) throw new Error('Alias ' + from + ' -> ' + to + ' could not be created as ' + from + ' not defined'); Object.defineProperty(Assertion.prototype, to, desc); var desc2 = Object.getOwnPropertyDescriptor(PromisedAssertion.prototype, from); if (desc2) { Object.defineProperty(PromisedAssertion.prototype, to, desc2); } }; /** * Negation modifier. Current assertion chain become negated. Each call invert negation on current assertion. * * @name not * @property * @memberOf Assertion * @category assertion */ Assertion.addChain('not', function() { this.negate = !this.negate; }); /** * Any modifier - it affect on execution of sequenced assertion to do not `check all`, but `check any of`. * * @name any * @property * @memberOf Assertion * @category assertion */ Assertion.addChain('any', function() { this.anyOne = true; }); module.exports = Assertion; module.exports.PromisedAssertion = PromisedAssertion; should.js-8.4.0~dfsg/lib/config.js000066400000000000000000000006021301217646700170540ustar00rootroot00000000000000/* * should.js - assertion library * Copyright(c) 2010-2013 TJ Holowaychuk * Copyright(c) 2013-2016 Denis Bardadym * MIT Licensed */ var Formatter = require('should-format').Formatter; var config = { checkProtoEql: false, getFormatter: function(opts) { return new Formatter(opts || config); } }; module.exports = config; should.js-8.4.0~dfsg/lib/ext/000077500000000000000000000000001301217646700160535ustar00rootroot00000000000000should.js-8.4.0~dfsg/lib/ext/_assert.js000066400000000000000000000221621301217646700200540ustar00rootroot00000000000000// implement assert interface using already written peaces of should.js // http://wiki.commonjs.org/wiki/Unit_Testing/1.0 // // THIS IS NOT TESTED NOR LIKELY TO WORK OUTSIDE V8! // // Originally from narwhal.js (http://narwhaljs.org) // Copyright (c) 2009 Thomas Robinson <280north.com> // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the 'Software'), to // deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or // sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // when used in node, this will actually load the util module we depend on // versus loading the builtin util module as happens otherwise // this is a bug in node module loading as far as I am concerned var Assertion = require('./../assertion'); var _deepEqual = require('should-equal'); var pSlice = Array.prototype.slice; // 1. The assert module provides functions that throw // AssertionError's when particular conditions are not met. The // assert module must conform to the following interface. var assert = module.exports = ok; // 3. All of the following functions must throw an AssertionError // when a corresponding condition is not met, with a message that // may be undefined if not provided. All assertion methods provide // both the actual and expected values to the assertion error for // display purposes. /** * Node.js standard [`assert.fail`](http://nodejs.org/api/assert.html#assert_assert_fail_actual_expected_message_operator). * @static * @memberOf should * @category assertion assert * @param {*} actual Actual object * @param {*} expected Expected object * @param {string} message Message for assertion * @param {string} operator Operator text */ function fail(actual, expected, message, operator, stackStartFunction) { var a = new Assertion(actual); a.params = { operator: operator, expected: expected, message: message, stackStartFunction: stackStartFunction || fail }; a.fail(); } // EXTENSION! allows for well behaved errors defined elsewhere. assert.fail = fail; // 4. Pure assertion tests whether a value is truthy, as determined // by !!guard. // assert.ok(guard, message_opt); // This statement is equivalent to assert.equal(true, !!guard, // message_opt);. To test strictly for the value true, use // assert.strictEqual(true, guard, message_opt);. /** * Node.js standard [`assert.ok`](http://nodejs.org/api/assert.html#assert_assert_value_message_assert_ok_value_message). * @static * @memberOf should * @category assertion assert * @param {*} value * @param {string} [message] */ function ok(value, message) { if (!value) fail(value, true, message, '==', assert.ok); } assert.ok = ok; // 5. The equality assertion tests shallow, coercive equality with // ==. // assert.equal(actual, expected, message_opt); /** * Node.js standard [`assert.equal`](http://nodejs.org/api/assert.html#assert_assert_equal_actual_expected_message). * @static * @memberOf should * @category assertion assert * @param {*} actual * @param {*} expected * @param {string} [message] */ assert.equal = function equal(actual, expected, message) { if (actual != expected) fail(actual, expected, message, '==', assert.equal); }; // 6. The non-equality assertion tests for whether two objects are not equal // with != assert.notEqual(actual, expected, message_opt); /** * Node.js standard [`assert.notEqual`](http://nodejs.org/api/assert.html#assert_assert_notequal_actual_expected_message). * @static * @memberOf should * @category assertion assert * @param {*} actual * @param {*} expected * @param {string} [message] */ assert.notEqual = function notEqual(actual, expected, message) { if (actual == expected) { fail(actual, expected, message, '!=', assert.notEqual); } }; // 7. The equivalence assertion tests a deep equality relation. // assert.deepEqual(actual, expected, message_opt); /** * Node.js standard [`assert.deepEqual`](http://nodejs.org/api/assert.html#assert_assert_deepequal_actual_expected_message). * But uses should.js .eql implementation instead of Node.js own deepEqual. * * @static * @memberOf should * @category assertion assert * @param {*} actual * @param {*} expected * @param {string} [message] */ assert.deepEqual = function deepEqual(actual, expected, message) { if (!_deepEqual(actual, expected).result) { fail(actual, expected, message, 'deepEqual', assert.deepEqual); } }; // 8. The non-equivalence assertion tests for any deep inequality. // assert.notDeepEqual(actual, expected, message_opt); /** * Node.js standard [`assert.notDeepEqual`](http://nodejs.org/api/assert.html#assert_assert_notdeepequal_actual_expected_message). * But uses should.js .eql implementation instead of Node.js own deepEqual. * * @static * @memberOf should * @category assertion assert * @param {*} actual * @param {*} expected * @param {string} [message] */ assert.notDeepEqual = function notDeepEqual(actual, expected, message) { if (_deepEqual(actual, expected).result) { fail(actual, expected, message, 'notDeepEqual', assert.notDeepEqual); } }; // 9. The strict equality assertion tests strict equality, as determined by ===. // assert.strictEqual(actual, expected, message_opt); /** * Node.js standard [`assert.strictEqual`](http://nodejs.org/api/assert.html#assert_assert_strictequal_actual_expected_message). * @static * @memberOf should * @category assertion assert * @param {*} actual * @param {*} expected * @param {string} [message] */ assert.strictEqual = function strictEqual(actual, expected, message) { if (actual !== expected) { fail(actual, expected, message, '===', assert.strictEqual); } }; // 10. The strict non-equality assertion tests for strict inequality, as // determined by !==. assert.notStrictEqual(actual, expected, message_opt); /** * Node.js standard [`assert.notStrictEqual`](http://nodejs.org/api/assert.html#assert_assert_notstrictequal_actual_expected_message). * @static * @memberOf should * @category assertion assert * @param {*} actual * @param {*} expected * @param {string} [message] */ assert.notStrictEqual = function notStrictEqual(actual, expected, message) { if (actual === expected) { fail(actual, expected, message, '!==', assert.notStrictEqual); } }; function expectedException(actual, expected) { if (!actual || !expected) { return false; } if (Object.prototype.toString.call(expected) == '[object RegExp]') { return expected.test(actual); } else if (actual instanceof expected) { return true; } else if (expected.call({}, actual) === true) { return true; } return false; } function _throws(shouldThrow, block, expected, message) { var actual; if (typeof expected == 'string') { message = expected; expected = null; } try { block(); } catch (e) { actual = e; } message = (expected && expected.name ? ' (' + expected.name + ')' : '.') + (message ? ' ' + message : '.'); if (shouldThrow && !actual) { fail(actual, expected, 'Missing expected exception' + message); } if (!shouldThrow && expectedException(actual, expected)) { fail(actual, expected, 'Got unwanted exception' + message); } if ((shouldThrow && actual && expected && !expectedException(actual, expected)) || (!shouldThrow && actual)) { throw actual; } } // 11. Expected to throw an error: // assert.throws(block, Error_opt, message_opt); /** * Node.js standard [`assert.throws`](http://nodejs.org/api/assert.html#assert_assert_throws_block_error_message). * @static * @memberOf should * @category assertion assert * @param {Function} block * @param {Function} [error] * @param {String} [message] */ assert.throws = function(/*block, error, message*/) { _throws.apply(this, [true].concat(pSlice.call(arguments))); }; // EXTENSION! This is annoying to write outside this module. /** * Node.js standard [`assert.doesNotThrow`](http://nodejs.org/api/assert.html#assert_assert_doesnotthrow_block_message). * @static * @memberOf should * @category assertion assert * @param {Function} block * @param {String} [message] */ assert.doesNotThrow = function(/*block, message*/) { _throws.apply(this, [false].concat(pSlice.call(arguments))); }; /** * Node.js standard [`assert.ifError`](http://nodejs.org/api/assert.html#assert_assert_iferror_value). * @static * @memberOf should * @category assertion assert * @param {Error} err */ assert.ifError = function(err) { if (err) { throw err; } }; should.js-8.4.0~dfsg/lib/ext/assert.js000066400000000000000000000032101301217646700177060ustar00rootroot00000000000000/* * should.js - assertion library * Copyright(c) 2010-2013 TJ Holowaychuk * Copyright(c) 2013-2016 Denis Bardadym * MIT Licensed */ var util = require('../util'); var assert = require('./_assert'); var AssertionError = require('../assertion-error'); module.exports = function(should) { var i = should.format; /* * Expose assert to should * * This allows you to do things like below * without require()ing the assert module. * * should.equal(foo.bar, undefined); * */ util.merge(should, assert); /** * Assert _obj_ exists, with optional message. * * @static * @memberOf should * @category assertion assert * @alias should.exists * @param {*} obj * @param {String} [msg] * @example * * should.exist(1); * should.exist(new Date()); */ should.exist = should.exists = function(obj, msg) { if (null == obj) { throw new AssertionError({ message: msg || ('expected ' + i(obj) + ' to exist'), stackStartFunction: should.exist }); } }; should.not = {}; /** * Asserts _obj_ does not exist, with optional message. * * @name not.exist * @static * @memberOf should * @category assertion assert * @alias should.not.exists * @param {*} obj * @param {String} [msg] * @example * * should.not.exist(null); * should.not.exist(void 0); */ should.not.exist = should.not.exists = function(obj, msg) { if (null != obj) { throw new AssertionError({ message: msg || ('expected ' + i(obj) + ' to not exist'), stackStartFunction: should.not.exist }); } }; }; should.js-8.4.0~dfsg/lib/ext/bool.js000066400000000000000000000030631301217646700173460ustar00rootroot00000000000000/* * should.js - assertion library * Copyright(c) 2010-2013 TJ Holowaychuk * Copyright(c) 2013-2016 Denis Bardadym * MIT Licensed */ module.exports = function(should, Assertion) { /** * Assert given object is exactly `true`. * * @name true * @memberOf Assertion * @category assertion bool * @alias Assertion#True * @param {string} [message] Optional message * @example * * (true).should.be.true(); * false.should.not.be.true(); * * ({ a: 10}).should.not.be.true(); */ Assertion.add('true', function(message) { this.is.exactly(true, message); }); Assertion.alias('true', 'True'); /** * Assert given object is exactly `false`. * * @name false * @memberOf Assertion * @category assertion bool * @alias Assertion#False * @param {string} [message] Optional message * @example * * (true).should.not.be.false(); * false.should.be.false(); */ Assertion.add('false', function(message) { this.is.exactly(false, message); }); Assertion.alias('false', 'False'); /** * Assert given object is thuthy according javascript type conversions. * * @name ok * @memberOf Assertion * @category assertion bool * @example * * (true).should.be.ok(); * ''.should.not.be.ok(); * should(null).not.be.ok(); * should(void 0).not.be.ok(); * * (10).should.be.ok(); * (0).should.not.be.ok(); */ Assertion.add('ok', function() { this.params = { operator: 'to be truthy' }; this.assert(this.obj); }); }; should.js-8.4.0~dfsg/lib/ext/chain.js000066400000000000000000000015051301217646700174740ustar00rootroot00000000000000/* * should.js - assertion library * Copyright(c) 2010-2013 TJ Holowaychuk * Copyright(c) 2013-2016 Denis Bardadym * MIT Licensed */ module.exports = function(should, Assertion) { /** * Simple chaining. It actually do nothing. * * @memberOf Assertion * @name be * @property {should.Assertion} be * @alias Assertion#an * @alias Assertion#of * @alias Assertion#a * @alias Assertion#and * @alias Assertion#have * @alias Assertion#has * @alias Assertion#with * @alias Assertion#is * @alias Assertion#which * @alias Assertion#the * @alias Assertion#it * @category assertion chaining */ ['an', 'of', 'a', 'and', 'be', 'has', 'have', 'with', 'is', 'which', 'the', 'it'].forEach(function(name) { Assertion.addChain(name); }); }; should.js-8.4.0~dfsg/lib/ext/contain.js000066400000000000000000000127431301217646700200530ustar00rootroot00000000000000/* * should.js - assertion library * Copyright(c) 2010-2013 TJ Holowaychuk * Copyright(c) 2013-2016 Denis Bardadym * MIT Licensed */ var util = require('../util'); var eql = require('should-equal'); module.exports = function(should, Assertion) { var i = should.format; /** * Assert that given object contain something that equal to `other`. It uses `should-equal` for equality checks. * If given object is array it search that one of elements was equal to `other`. * If given object is string it checks if `other` is a substring - expected that `other` is a string. * If given object is Object it checks that `other` is a subobject - expected that `other` is a object. * * @name containEql * @memberOf Assertion * @category assertion contain * @param {*} other Nested object * @example * * [1, 2, 3].should.containEql(1); * [{ a: 1 }, 'a', 10].should.containEql({ a: 1 }); * * 'abc'.should.containEql('b'); * 'ab1c'.should.containEql(1); * * ({ a: 10, c: { d: 10 }}).should.containEql({ a: 10 }); * ({ a: 10, c: { d: 10 }}).should.containEql({ c: { d: 10 }}); * ({ a: 10, c: { d: 10 }}).should.containEql({ b: 10 }); * // throws AssertionError: expected { a: 10, c: { d: 10 } } to contain { b: 10 } * // expected { a: 10, c: { d: 10 } } to have property b */ Assertion.add('containEql', function(other) { this.params = {operator: 'to contain ' + i(other)}; this.is.not.null().and.not.undefined(); var obj = this.obj; if (typeof obj == 'string') { this.assert(obj.indexOf(String(other)) >= 0); } else if (util.isIndexable(obj)) { this.assert(util.some(obj, function(v) { return eql(v, other).result; })); } else { this.have.properties(other); } }); /** * Assert that given object is contain equally structured object on the same depth level. * If given object is an array and `other` is an array it checks that the eql elements is going in the same sequence in given array (recursive) * If given object is an object it checks that the same keys contain deep equal values (recursive) * On other cases it try to check with `.eql` * * @name containDeepOrdered * @memberOf Assertion * @category assertion contain * @param {*} other Nested object * @example * * [ 1, 2, 3].should.containDeepOrdered([1, 2]); * [ 1, 2, [ 1, 2, 3 ]].should.containDeepOrdered([ 1, [ 2, 3 ]]); * * ({ a: 10, b: { c: 10, d: [1, 2, 3] }}).should.containDeepOrdered({a: 10}); * ({ a: 10, b: { c: 10, d: [1, 2, 3] }}).should.containDeepOrdered({b: {c: 10}}); * ({ a: 10, b: { c: 10, d: [1, 2, 3] }}).should.containDeepOrdered({b: {d: [1, 3]}}); */ Assertion.add('containDeepOrdered', function(other) { this.params = {operator: 'to contain ' + i(other)}; var obj = this.obj; if (typeof obj == 'string') {// expect other to be string this.is.equal(String(other)); } else if (util.isIndexable(obj) && util.isIndexable(other)) { for (var objIdx = 0, otherIdx = 0, objLength = util.length(obj), otherLength = util.length(other); objIdx < objLength && otherIdx < otherLength; objIdx++) { try { should(obj[objIdx]).containDeepOrdered(other[otherIdx]); otherIdx++; } catch (e) { if (e instanceof should.AssertionError) { continue; } throw e; } } this.assert(otherIdx === otherLength); } else if (obj != null && other != null && typeof obj == 'object' && typeof other == 'object') {// object contains object case util.forEach(other, function(value, key) { should(obj[key]).containDeepOrdered(value); }); // if both objects is empty means we finish traversing - and we need to compare for hidden values if (util.isEmptyObject(other)) { this.eql(other); } } else { this.eql(other); } }); /** * The same like `Assertion#containDeepOrdered` but all checks on arrays without order. * * @name containDeep * @memberOf Assertion * @category assertion contain * @param {*} other Nested object * @example * * [ 1, 2, 3].should.containDeep([2, 1]); * [ 1, 2, [ 1, 2, 3 ]].should.containDeep([ 1, [ 3, 1 ]]); */ Assertion.add('containDeep', function(other) { this.params = {operator: 'to contain ' + i(other)}; var obj = this.obj; if (typeof obj == 'string') {// expect other to be string this.is.equal(String(other)); } else if (util.isIndexable(obj) && util.isIndexable(other)) { var usedKeys = {}; util.forEach(other, function(otherItem) { this.assert(util.some(obj, function(item, index) { if (index in usedKeys) return false; try { should(item).containDeep(otherItem); usedKeys[index] = true; return true; } catch (e) { if (e instanceof should.AssertionError) { return false; } throw e; } })); }, this); } else if (obj != null && other != null && typeof obj == 'object' && typeof other == 'object') {// object contains object case util.forEach(other, function(value, key) { should(obj[key]).containDeep(value); }); // if both objects is empty means we finish traversing - and we need to compare for hidden values if (util.isEmptyObject(other)) { this.eql(other); } } else { this.eql(other); } }); }; should.js-8.4.0~dfsg/lib/ext/eql.js000066400000000000000000000072031301217646700171740ustar00rootroot00000000000000/* * should.js - assertion library * Copyright(c) 2010-2013 TJ Holowaychuk * Copyright(c) 2013-2016 Denis Bardadym * MIT Licensed */ var eql = require('should-equal'); var type = require('should-type'); var util = require('../util'); function formatEqlResult(r, a, b) { return ((r.path.length > 0 ? 'at ' + r.path.map(util.formatProp).join(' -> ') : '') + (r.a === a ? '' : ', A has ' + util.format(r.a)) + (r.b === b ? '' : ' and B has ' + util.format(r.b)) + (r.showReason ? ' because ' + r.reason : '')).trim(); } module.exports = function(should, Assertion) { /** * Deep object equality comparison. For full spec see [`should-equal tests`](https://github.com/shouldjs/equal/blob/master/test.js). * * @name eql * @memberOf Assertion * @category assertion equality * @alias Assertion#deepEqual * @param {*} val Expected value * @param {string} [description] Optional message * @example * * (10).should.be.eql(10); * ('10').should.not.be.eql(10); * (-0).should.not.be.eql(+0); * * NaN.should.be.eql(NaN); * * ({ a: 10}).should.be.eql({ a: 10 }); * [ 'a' ].should.not.be.eql({ '0': 'a' }); */ Assertion.add('eql', function(val, description) { this.params = {operator: 'to equal', expected: val, message: description}; var result = eql(this.obj, val, should.config); this.params.details = result.result ? '' : formatEqlResult(result, this.obj, val); this.params.showDiff = eql(type(this.obj), type(val)).result; this.assert(result.result); }); /** * Exact comparison using ===. * * @name equal * @memberOf Assertion * @category assertion equality * @alias Assertion#exactly * @param {*} val Expected value * @param {string} [description] Optional message * @example * * 10.should.be.equal(10); * 'a'.should.be.exactly('a'); * * should(null).be.exactly(null); */ Assertion.add('equal', function(val, description) { this.params = {operator: 'to be', expected: val, message: description}; this.params.showDiff = eql(type(this.obj), type(val)).result; this.assert(val === this.obj); }); Assertion.alias('equal', 'exactly'); Assertion.alias('eql', 'deepEqual'); function addOneOf(name, message, method) { Assertion.add(name, function(vals) { if (arguments.length !== 1) { vals = Array.prototype.slice.call(arguments); } else { should(vals).be.Array(); } this.params = {operator: message, expected: vals}; var obj = this.obj; var found = false; util.forEach(vals, function(val) { try { should(val)[method](obj); found = true; return false; } catch (e) { if (e instanceof should.AssertionError) { return;//do nothing } throw e; } }); this.assert(found); }); } /** * Exact comparison using === to be one of supplied objects. * * @name equalOneOf * @memberOf Assertion * @category assertion equality * @param {Array|*} vals Expected values * @example * * 'ab'.should.be.equalOneOf('a', 10, 'ab'); * 'ab'.should.be.equalOneOf(['a', 10, 'ab']); */ addOneOf('equalOneOf', 'to be equals one of', 'equal'); /** * Exact comparison using .eql to be one of supplied objects. * * @name oneOf * @memberOf Assertion * @category assertion equality * @param {Array|*} vals Expected values * @example * * ({a: 10}).should.be.oneOf('a', 10, 'ab', {a: 10}); * ({a: 10}).should.be.oneOf(['a', 10, 'ab', {a: 10}]); */ addOneOf('oneOf', 'to be one of', 'eql'); }; should.js-8.4.0~dfsg/lib/ext/error.js000066400000000000000000000064551301217646700175540ustar00rootroot00000000000000/* * should.js - assertion library * Copyright(c) 2010-2013 TJ Holowaychuk * Copyright(c) 2013-2016 Denis Bardadym * MIT Licensed */ var util = require('../util'); module.exports = function(should, Assertion) { var i = should.format; /** * Assert given function throws error with such message. * * @name throw * @memberOf Assertion * @category assertion errors * @alias Assertion#throwError * @param {string|RegExp|Function|Object|GeneratorFunction|GeneratorObject} [message] Message to match or properties * @param {Object} [properties] Optional properties that will be matched to thrown error * @example * * (function(){ throw new Error('fail') }).should.throw(); * (function(){ throw new Error('fail') }).should.throw('fail'); * (function(){ throw new Error('fail') }).should.throw(/fail/); * * (function(){ throw new Error('fail') }).should.throw(Error); * var error = new Error(); * error.a = 10; * (function(){ throw error; }).should.throw(Error, { a: 10 }); * (function(){ throw error; }).should.throw({ a: 10 }); * (function*() { * yield throwError(); * }).should.throw(); */ Assertion.add('throw', function(message, properties) { var fn = this.obj; var err = {}; var errorInfo = ''; var thrown = false; if (util.isGeneratorFunction(fn)) { return should(fn()).throw(message, properties); } else if (util.isGeneratorObject(fn)) { return should(fn.next.bind(fn)).throw(message, properties); } this.is.a.Function(); var errorMatched = true; try { fn(); } catch (e) { thrown = true; err = e; } if (thrown) { if (message) { if ('string' == typeof message) { errorMatched = message == err.message; } else if (message instanceof RegExp) { errorMatched = message.test(err.message); } else if ('function' == typeof message) { errorMatched = err instanceof message; } else if (null != message) { try { should(err).match(message); } catch (e) { if (e instanceof should.AssertionError) { errorInfo = ": " + e.message; errorMatched = false; } else { throw e; } } } if (!errorMatched) { if ('string' == typeof message || message instanceof RegExp) { errorInfo = " with a message matching " + i(message) + ", but got '" + err.message + "'"; } else if ('function' == typeof message) { errorInfo = " of type " + util.functionName(message) + ", but got " + util.functionName(err.constructor); } } else if ('function' == typeof message && properties) { try { should(err).match(properties); } catch (e) { if (e instanceof should.AssertionError) { errorInfo = ": " + e.message; errorMatched = false; } else { throw e; } } } } else { errorInfo = " (got " + i(err) + ")"; } } this.params = { operator: 'to throw exception' + errorInfo }; this.assert(thrown); this.assert(errorMatched); }); Assertion.alias('throw', 'throwError'); }; should.js-8.4.0~dfsg/lib/ext/match.js000066400000000000000000000175731301217646700175220ustar00rootroot00000000000000/* * should.js - assertion library * Copyright(c) 2010-2013 TJ Holowaychuk * Copyright(c) 2013-2016 Denis Bardadym * MIT Licensed */ var util = require('../util'); var eql = require('should-equal'); module.exports = function(should, Assertion) { var i = should.format; /** * Asserts if given object match `other` object, using some assumptions: * First object matched if they are equal, * If `other` is a regexp and given object is a string check on matching with regexp * If `other` is a regexp and given object is an array check if all elements matched regexp * If `other` is a regexp and given object is an object check values on matching regexp * If `other` is a function check if this function throws AssertionError on given object or return false - it will be assumed as not matched * If `other` is an object check if the same keys matched with above rules * All other cases failed. * * Usually it is right idea to add pre type assertions, like `.String()` or `.Object()` to be sure assertions will do what you are expecting. * Object iteration happen by keys (properties with enumerable: true), thus some objects can cause small pain. Typical example is js * Error - it by default has 2 properties `name` and `message`, but they both non-enumerable. In this case make sure you specify checking props (see examples). * * @name match * @memberOf Assertion * @category assertion matching * @param {*} other Object to match * @param {string} [description] Optional message * @example * 'foobar'.should.match(/^foo/); * 'foobar'.should.not.match(/^bar/); * * ({ a: 'foo', c: 'barfoo' }).should.match(/foo$/); * * ['a', 'b', 'c'].should.match(/[a-z]/); * * (5).should.not.match(function(n) { * return n < 0; * }); * (5).should.not.match(function(it) { * it.should.be.an.Array(); * }); * ({ a: 10, b: 'abc', c: { d: 10 }, d: 0 }).should * .match({ a: 10, b: /c$/, c: function(it) { * return it.should.have.property('d', 10); * }}); * * [10, 'abc', { d: 10 }, 0].should * .match({ '0': 10, '1': /c$/, '2': function(it) { * return it.should.have.property('d', 10); * }}); * * var myString = 'abc'; * * myString.should.be.a.String().and.match(/abc/); * * myString = {}; * * myString.should.match(/abc/); //yes this will pass * //better to do * myString.should.be.an.Object().and.not.empty().and.match(/abc/);//fixed * * (new Error('boom')).should.match(/abc/);//passed because no keys * (new Error('boom')).should.not.match({ message: /abc/ });//check specified property */ Assertion.add('match', function(other, description) { this.params = {operator: 'to match ' + i(other), message: description}; if (!eql(this.obj, other).result) { if (other instanceof RegExp) { // something - regex if (typeof this.obj == 'string') { this.assert(other.exec(this.obj)); } else if (util.isIndexable(this.obj)) { util.forEach(this.obj, function(item) { this.assert(other.exec(item));// should we try to convert to String and exec? }, this); } else if (null != this.obj && typeof this.obj == 'object') { var notMatchedProps = [], matchedProps = []; util.forEach(this.obj, function(value, name) { if (other.exec(value)) matchedProps.push(util.formatProp(name)); else notMatchedProps.push(util.formatProp(name) + ' (' + i(value) + ')'); }, this); if (notMatchedProps.length) this.params.operator += '\n not matched properties: ' + notMatchedProps.join(', '); if (matchedProps.length) this.params.operator += '\n matched properties: ' + matchedProps.join(', '); this.assert(notMatchedProps.length === 0); } // should we try to convert to String and exec? } else if (typeof other == 'function') { var res; res = other(this.obj); //if(res instanceof Assertion) { // this.params.operator += '\n ' + res.getMessage(); //} //if we throw exception ok - it is used .should inside if (typeof res == 'boolean') { this.assert(res); // if it is just boolean function assert on it } } else if (other != null && this.obj != null && typeof other == 'object' && typeof this.obj == 'object') { // try to match properties (for Object and Array) notMatchedProps = []; matchedProps = []; util.forEach(other, function(value, key) { try { should(this.obj).have.property(key).which.match(value); matchedProps.push(util.formatProp(key)); } catch (e) { if (e instanceof should.AssertionError) { notMatchedProps.push(util.formatProp(key) + ' (' + i(this.obj[key]) + ')'); } else { throw e; } } }, this); if (notMatchedProps.length) this.params.operator += '\n not matched properties: ' + notMatchedProps.join(', '); if (matchedProps.length) this.params.operator += '\n matched properties: ' + matchedProps.join(', '); this.assert(notMatchedProps.length === 0); } else { this.assert(false); } } }); /** * Asserts if given object values or array elements all match `other` object, using some assumptions: * First object matched if they are equal, * If `other` is a regexp - matching with regexp * If `other` is a function check if this function throws AssertionError on given object or return false - it will be assumed as not matched * All other cases check if this `other` equal to each element * * @name matchEach * @memberOf Assertion * @category assertion matching * @alias Assertion#matchEvery * @param {*} other Object to match * @param {string} [description] Optional message * @example * [ 'a', 'b', 'c'].should.matchEach(/\w+/); * [ 'a', 'a', 'a'].should.matchEach('a'); * * [ 'a', 'a', 'a'].should.matchEach(function(value) { value.should.be.eql('a') }); * * { a: 'a', b: 'a', c: 'a' }.should.matchEach(function(value) { value.should.be.eql('a') }); */ Assertion.add('matchEach', function(other, description) { this.params = {operator: 'to match each ' + i(other), message: description}; util.forEach(this.obj, function(value) { should(value).match(other); }, this); }); /** * Asserts if any of given object values or array elements match `other` object, using some assumptions: * First object matched if they are equal, * If `other` is a regexp - matching with regexp * If `other` is a function check if this function throws AssertionError on given object or return false - it will be assumed as not matched * All other cases check if this `other` equal to each element * * @name matchAny * @memberOf Assertion * @category assertion matching * @param {*} other Object to match * @alias Assertion#matchSome * @param {string} [description] Optional message * @example * [ 'a', 'b', 'c'].should.matchAny(/\w+/); * [ 'a', 'b', 'c'].should.matchAny('a'); * * [ 'a', 'b', 'c'].should.matchAny(function(value) { value.should.be.eql('a') }); * * { a: 'a', b: 'b', c: 'c' }.should.matchAny(function(value) { value.should.be.eql('a') }); */ Assertion.add('matchAny', function(other, description) { this.params = {operator: 'to match any ' + i(other), message: description}; this.assert(util.some(this.obj, function(value) { try { should(value).match(other); return true; } catch (e) { if (e instanceof should.AssertionError) { // Caught an AssertionError, return false to the iterator return false; } throw e; } })); }); Assertion.alias('matchAny', 'matchSome'); Assertion.alias('matchEach', 'matchEvery'); }; should.js-8.4.0~dfsg/lib/ext/number.js000066400000000000000000000104121301217646700176770ustar00rootroot00000000000000/* * should.js - assertion library * Copyright(c) 2010-2013 TJ Holowaychuk * Copyright(c) 2013-2016 Denis Bardadym * MIT Licensed */ module.exports = function(should, Assertion) { /** * Assert given object is NaN * @name NaN * @memberOf Assertion * @category assertion numbers * @example * * (10).should.not.be.NaN(); * NaN.should.be.NaN(); */ Assertion.add('NaN', function() { this.params = { operator: 'to be NaN' }; this.assert(this.obj !== this.obj); }); /** * Assert given object is not finite (positive or negative) * * @name Infinity * @memberOf Assertion * @category assertion numbers * @example * * (10).should.not.be.Infinity(); * NaN.should.not.be.Infinity(); */ Assertion.add('Infinity', function() { this.params = { operator: 'to be Infinity' }; this.is.a.Number() .and.not.a.NaN() .and.assert(!isFinite(this.obj)); }); /** * Assert given number between `start` and `finish` or equal one of them. * * @name within * @memberOf Assertion * @category assertion numbers * @param {number} start Start number * @param {number} finish Finish number * @param {string} [description] Optional message * @example * * (10).should.be.within(0, 20); */ Assertion.add('within', function(start, finish, description) { this.params = { operator: 'to be within ' + start + '..' + finish, message: description }; this.assert(this.obj >= start && this.obj <= finish); }); /** * Assert given number near some other `value` within `delta` * * @name approximately * @memberOf Assertion * @category assertion numbers * @param {number} value Center number * @param {number} delta Radius * @param {string} [description] Optional message * @example * * (9.99).should.be.approximately(10, 0.1); */ Assertion.add('approximately', function(value, delta, description) { this.params = { operator: 'to be approximately ' + value + ' ±' + delta, message: description }; this.assert(Math.abs(this.obj - value) <= delta); }); /** * Assert given number above `n`. * * @name above * @alias Assertion#greaterThan * @memberOf Assertion * @category assertion numbers * @param {number} n Margin number * @param {string} [description] Optional message * @example * * (10).should.be.above(0); */ Assertion.add('above', function(n, description) { this.params = { operator: 'to be above ' + n, message: description }; this.assert(this.obj > n); }); /** * Assert given number below `n`. * * @name below * @alias Assertion#lessThan * @memberOf Assertion * @category assertion numbers * @param {number} n Margin number * @param {string} [description] Optional message * @example * * (0).should.be.below(10); */ Assertion.add('below', function(n, description) { this.params = { operator: 'to be below ' + n, message: description }; this.assert(this.obj < n); }); Assertion.alias('above', 'greaterThan'); Assertion.alias('below', 'lessThan'); /** * Assert given number above `n`. * * @name aboveOrEqual * @alias Assertion#greaterThanOrEqual * @memberOf Assertion * @category assertion numbers * @param {number} n Margin number * @param {string} [description] Optional message * @example * * (10).should.be.aboveOrEqual(0); * (10).should.be.aboveOrEqual(10); */ Assertion.add('aboveOrEqual', function(n, description) { this.params = { operator: 'to be above or equal' + n, message: description }; this.assert(this.obj >= n); }); /** * Assert given number below `n`. * * @name belowOrEqual * @alias Assertion#lessThanOrEqual * @memberOf Assertion * @category assertion numbers * @param {number} n Margin number * @param {string} [description] Optional message * @example * * (0).should.be.belowOrEqual(10); * (0).should.be.belowOrEqual(0); */ Assertion.add('belowOrEqual', function(n, description) { this.params = { operator: 'to be below or equal' + n, message: description }; this.assert(this.obj <= n); }); Assertion.alias('aboveOrEqual', 'greaterThanOrEqual'); Assertion.alias('belowOrEqual', 'lessThanOrEqual'); }; should.js-8.4.0~dfsg/lib/ext/promise.js000066400000000000000000000203241301217646700200700ustar00rootroot00000000000000/* * should.js - assertion library * Copyright(c) 2010-2013 TJ Holowaychuk * Copyright(c) 2013-2016 Denis Bardadym * MIT Licensed */ var util = require('../util'); var PromisedAssertion = require('../assertion').PromisedAssertion; var Assertion = require('../assertion'); module.exports = function(should) { /** * Assert given object is a Promise * * @name Promise * @memberOf Assertion * @category assertion promises * @example * * promise.should.be.Promise() * (new Promise(function(resolve, reject) { resolve(10); })).should.be.a.Promise() * (10).should.not.be.a.Promise() */ Assertion.add('Promise', function() { this.params = {operator: 'to be promise'}; var obj = this.obj; should(obj).have.property('then') .which.is.a.Function(); }); /** * Assert given promise will be fulfilled. Result of assertion is still .thenable and should be handled accordingly. * * @name fulfilled * @memberOf Assertion * @returns {Promise} * @category assertion promises * @example * * // don't forget to handle async nature * (new Promise(function(resolve, reject) { resolve(10); })).should.be.fulfilled(); * * // test example with mocha it is possible to return promise * it('is async', () => { * return new Promise(resolve => resolve(10)) * .should.be.fulfilled(); * }); */ Assertion.prototype.fulfilled = function Assertion$fulfilled() { this.params = {operator: 'to be fulfilled'}; should(this.obj).be.a.Promise(); var that = this; return this.obj.then(function next$onResolve(value) { if (that.negate) { that.fail(); } return value; }, function next$onReject(err) { if (!that.negate) { that.params.operator += ', but it was rejected with ' + should.format(err); that.fail(); } return err; }); }; /** * Assert given promise will be rejected. Result of assertion is still .thenable and should be handled accordingly. * * @name rejected * @memberOf Assertion * @category assertion promises * @returns {Promise} * @example * * // don't forget to handle async nature * (new Promise(function(resolve, reject) { resolve(10); })) * .should.not.be.rejected(); * * // test example with mocha it is possible to return promise * it('is async', () => { * return new Promise((resolve, reject) => reject(new Error('boom'))) * .should.be.rejected(); * }); */ Assertion.prototype.rejected = function() { this.params = {operator: 'to be rejected'}; should(this.obj).be.a.Promise(); var that = this; return this.obj.then(function(value) { if (!that.negate) { that.params.operator += ', but it was fulfilled'; if (arguments.length != 0) { that.params.operator += ' with ' + should.format(value); } that.fail(); } return value; }, function next$onError(err) { if (that.negate) { that.fail(); } return err; }); }; /** * Assert given promise will be fulfilled with some expected value (value compared using .eql). * Result of assertion is still .thenable and should be handled accordingly. * * @name fulfilledWith * @memberOf Assertion * @category assertion promises * @returns {Promise} * @example * * // don't forget to handle async nature * (new Promise(function(resolve, reject) { resolve(10); })) * .should.be.fulfilledWith(10); * * // test example with mocha it is possible to return promise * it('is async', () => { * return new Promise((resolve, reject) => resolve(10)) * .should.be.fulfilledWith(10); * }); */ Assertion.prototype.fulfilledWith = function(expectedValue) { this.params = {operator: 'to be fulfilled with ' + should.format(expectedValue)}; should(this.obj).be.a.Promise(); var that = this; return this.obj.then(function(value) { if (that.negate) { that.fail(); } should(value).eql(expectedValue); return value; }, function next$onError(err) { if (!that.negate) { that.params.operator += ', but it was rejected with ' + should.format(err); that.fail(); } return err; }); }; /** * Assert given promise will be rejected with some sort of error. Arguments is the same for Assertion#throw. * Result of assertion is still .thenable and should be handled accordingly. * * @name rejectedWith * @memberOf Assertion * @category assertion promises * @returns {Promise} * @example * * function failedPromise() { * return new Promise(function(resolve, reject) { * reject(new Error('boom')) * }) * } * failedPromise().should.be.rejectedWith(Error); * failedPromise().should.be.rejectedWith('boom'); * failedPromise().should.be.rejectedWith(/boom/); * failedPromise().should.be.rejectedWith(Error, { message: 'boom' }); * failedPromise().should.be.rejectedWith({ message: 'boom' }); * * // test example with mocha it is possible to return promise * it('is async', () => { * return failedPromise().should.be.rejectedWith({ message: 'boom' }); * }); */ Assertion.prototype.rejectedWith = function(message, properties) { this.params = {operator: 'to be rejected'}; should(this.obj).be.a.Promise(); var that = this; return this.obj.then(function(value) { if (!that.negate) { that.fail(); } return value; }, function next$onError(err) { if (that.negate) { that.fail(); } var errorMatched = true; var errorInfo = ''; if ('string' === typeof message) { errorMatched = message === err.message; } else if (message instanceof RegExp) { errorMatched = message.test(err.message); } else if ('function' === typeof message) { errorMatched = err instanceof message; } else if (message !== null && typeof message === 'object') { try { should(err).match(message); } catch (e) { if (e instanceof should.AssertionError) { errorInfo = ': ' + e.message; errorMatched = false; } else { throw e; } } } if (!errorMatched) { if ( typeof message === 'string' || message instanceof RegExp) { errorInfo = ' with a message matching ' + should.format(message) + ", but got '" + err.message + "'"; } else if ('function' === typeof message) { errorInfo = ' of type ' + util.functionName(message) + ', but got ' + util.functionName(err.constructor); } } else if ('function' === typeof message && properties) { try { should(err).match(properties); } catch (e) { if (e instanceof should.AssertionError) { errorInfo = ': ' + e.message; errorMatched = false; } else { throw e; } } } that.params.operator += errorInfo; that.assert(errorMatched); return err; }); }; /** * Assert given object is promise and wrap it in PromisedAssertion, which has all properties of Assertion. * That means you can chain as with usual Assertion. * Result of assertion is still .thenable and should be handled accordingly. * * @name finally * @memberOf Assertion * @alias Assertion#eventually * @category assertion promises * @returns {PromisedAssertion} Like Assertion, but .then this.obj in Assertion * @example * * (new Promise(function(resolve, reject) { resolve(10); })) * .should.be.eventually.equal(10); * * // test example with mocha it is possible to return promise * it('is async', () => { * return new Promise(resolve => resolve(10)) * .should.be.finally.equal(10); * }); */ Object.defineProperty(Assertion.prototype, 'finally', { get: function() { should(this.obj).be.a.Promise(); var that = this; return new PromisedAssertion(this.obj.then(function(obj) { var a = should(obj); a.negate = that.negate; a.anyOne = that.anyOne; return a; })); } }); Assertion.alias('finally', 'eventually'); }; should.js-8.4.0~dfsg/lib/ext/property.js000066400000000000000000000264651301217646700203120ustar00rootroot00000000000000/* * should.js - assertion library * Copyright(c) 2010-2013 TJ Holowaychuk * Copyright(c) 2013-2016 Denis Bardadym * MIT Licensed */ var util = require('../util'); var eql = require('should-equal'); var aSlice = Array.prototype.slice; module.exports = function(should, Assertion) { var i = should.format; /** * Asserts given object has some descriptor. **On success it change given object to be value of property**. * * @name propertyWithDescriptor * @memberOf Assertion * @category assertion property * @param {string} name Name of property * @param {Object} desc Descriptor like used in Object.defineProperty (not required to add all properties) * @example * * ({ a: 10 }).should.have.propertyWithDescriptor('a', { enumerable: true }); */ Assertion.add('propertyWithDescriptor', function(name, desc) { this.params = {actual: this.obj, operator: 'to have own property with descriptor ' + i(desc)}; var obj = this.obj; this.have.ownProperty(name); should(Object.getOwnPropertyDescriptor(Object(obj), name)).have.properties(desc); }); function processPropsArgs() { var args = {}; if (arguments.length > 1) { args.names = aSlice.call(arguments); } else { var arg = arguments[0]; if (typeof arg === 'string') { args.names = [arg]; } else if (util.isIndexable(arg)) { args.names = arg; } else { args.names = Object.keys(arg); args.values = arg; } } return args; } /** * Asserts given object has enumerable property with optionally value. **On success it change given object to be value of property**. * * @name enumerable * @memberOf Assertion * @category assertion property * @param {string} name Name of property * @param {*} [val] Optional property value to check * @example * * ({ a: 10 }).should.have.enumerable('a'); */ Assertion.add('enumerable', function(name, val) { name = util.convertPropertyName(name); this.params = { operator: "to have enumerable property " + util.formatProp(name) + (arguments.length > 1 ? " equal to " + i(val): "") }; var desc = { enumerable: true }; if (arguments.length > 1) desc.value = val; this.have.propertyWithDescriptor(name, desc); }); /** * Asserts given object has enumerable properties * * @name enumerables * @memberOf Assertion * @category assertion property * @param {Array|...string|Object} names Names of property * @example * * ({ a: 10, b: 10 }).should.have.enumerables('a'); */ Assertion.add('enumerables', function(/*names*/) { var args = processPropsArgs.apply(null, arguments); this.params = { operator: "to have enumerables " + args.names.map(util.formatProp) }; var obj = this.obj; args.names.forEach(function(name) { should(obj).have.enumerable(name); }); }); /** * Asserts given object has property with optionally value. **On success it change given object to be value of property**. * * @name property * @memberOf Assertion * @category assertion property * @param {string} name Name of property * @param {*} [val] Optional property value to check * @example * * ({ a: 10 }).should.have.property('a'); */ Assertion.add('property', function(name, val) { name = util.convertPropertyName(name); if (arguments.length > 1) { var p = {}; p[name] = val; this.have.properties(p); } else { this.have.properties(name); } this.obj = this.obj[name]; }); /** * Asserts given object has properties. On this method affect .any modifier, which allow to check not all properties. * * @name properties * @memberOf Assertion * @category assertion property * @param {Array|...string|Object} names Names of property * @example * * ({ a: 10 }).should.have.properties('a'); * ({ a: 10, b: 20 }).should.have.properties([ 'a' ]); * ({ a: 10, b: 20 }).should.have.properties({ b: 20 }); */ Assertion.add('properties', function(names) { var values = {}; if (arguments.length > 1) { names = aSlice.call(arguments); } else if (!Array.isArray(names)) { if (typeof names == 'string' || typeof names == 'symbol') { names = [names]; } else { values = names; names = Object.keys(names); } } var obj = Object(this.obj), missingProperties = []; //just enumerate properties and check if they all present names.forEach(function(name) { if (!(name in obj)) missingProperties.push(util.formatProp(name)); }); var props = missingProperties; if (props.length === 0) { props = names.map(util.formatProp); } else if (this.anyOne) { props = names.filter(function(name) { return missingProperties.indexOf(util.formatProp(name)) < 0; }).map(util.formatProp); } var operator = (props.length === 1 ? 'to have property ' : 'to have ' + (this.anyOne ? 'any of ' : '') + 'properties ') + props.join(', '); this.params = {obj: this.obj, operator: operator}; //check that all properties presented //or if we request one of them that at least one them presented this.assert(missingProperties.length === 0 || (this.anyOne && missingProperties.length != names.length)); // check if values in object matched expected var valueCheckNames = Object.keys(values); if (valueCheckNames.length) { var wrongValues = []; props = []; // now check values, as there we have all properties valueCheckNames.forEach(function(name) { var value = values[name]; if (!eql(obj[name], value).result) { wrongValues.push(util.formatProp(name) + ' of ' + i(value) + ' (got ' + i(obj[name]) + ')'); } else { props.push(util.formatProp(name) + ' of ' + i(value)); } }); if ((wrongValues.length !== 0 && !this.anyOne) || (this.anyOne && props.length === 0)) { props = wrongValues; } operator = (props.length === 1 ? 'to have property ' : 'to have ' + (this.anyOne ? 'any of ' : '') + 'properties ') + props.join(', '); this.params = {obj: this.obj, operator: operator}; //if there is no not matched values //or there is at least one matched this.assert(wrongValues.length === 0 || (this.anyOne && wrongValues.length != valueCheckNames.length)); } }); /** * Asserts given object has property `length` with given value `n` * * @name length * @alias Assertion#lengthOf * @memberOf Assertion * @category assertion property * @param {number} n Expected length * @param {string} [description] Optional message * @example * * [1, 2].should.have.length(2); */ Assertion.add('length', function(n, description) { this.have.property('length', n, description); }); Assertion.alias('length', 'lengthOf'); var hasOwnProperty = Object.prototype.hasOwnProperty; /** * Asserts given object has own property. **On success it change given object to be value of property**. * * @name ownProperty * @alias Assertion#hasOwnProperty * @memberOf Assertion * @category assertion property * @param {string} name Name of property * @param {string} [description] Optional message * @example * * ({ a: 10 }).should.have.ownProperty('a'); */ Assertion.add('ownProperty', function(name, description) { name = util.convertPropertyName(name); this.params = { actual: this.obj, operator: 'to have own property ' + util.formatProp(name), message: description }; this.assert(hasOwnProperty.call(this.obj, name)); this.obj = this.obj[name]; }); Assertion.alias('ownProperty', 'hasOwnProperty'); /** * Asserts given object is empty. For strings, arrays and arguments it checks .length property, for objects it checks keys. * * @name empty * @memberOf Assertion * @category assertion property * @example * * ''.should.be.empty(); * [].should.be.empty(); * ({}).should.be.empty(); */ Assertion.add('empty', function() { this.params = {operator: 'to be empty'}; if (util.length(this.obj) !== void 0) { should(this.obj).have.property('length', 0); } else { var obj = Object(this.obj); // wrap to reference for booleans and numbers for (var prop in obj) { should(this.obj).not.have.ownProperty(prop); } } }, true); /** * Asserts given object has exact keys. Compared to `properties`, `keys` does not accept Object as a argument. * * @name keys * @alias Assertion#key * @memberOf Assertion * @category assertion property * @param {Array|...string} [keys] Keys to check * @example * * ({ a: 10 }).should.have.keys('a'); * ({ a: 10, b: 20 }).should.have.keys('a', 'b'); * ({ a: 10, b: 20 }).should.have.keys([ 'a', 'b' ]); * ({}).should.have.keys(); */ Assertion.add('keys', function(keys) { if (arguments.length > 1) keys = aSlice.call(arguments); else if (arguments.length === 1 && typeof keys === 'string') keys = [keys]; else if (arguments.length === 0) keys = []; keys = keys.map(String); var obj = Object(this.obj); // first check if some keys are missing var missingKeys = []; keys.forEach(function(key) { if (!hasOwnProperty.call(this.obj, key)) missingKeys.push(util.formatProp(key)); }, this); // second check for extra keys var extraKeys = []; Object.keys(obj).forEach(function(key) { if (keys.indexOf(key) < 0) { extraKeys.push(util.formatProp(key)); } }); var verb = keys.length === 0 ? 'to be empty' : 'to have ' + (keys.length === 1 ? 'key ' : 'keys '); this.params = {operator: verb + keys.map(util.formatProp).join(', ')}; if (missingKeys.length > 0) this.params.operator += '\n\tmissing keys: ' + missingKeys.join(', '); if (extraKeys.length > 0) this.params.operator += '\n\textra keys: ' + extraKeys.join(', '); this.assert(missingKeys.length === 0 && extraKeys.length === 0); }); Assertion.alias("keys", "key"); /** * Asserts given object has nested property in depth by path. **On success it change given object to be value of final property**. * * @name propertyByPath * @memberOf Assertion * @category assertion property * @param {Array|...string} properties Properties path to search * @example * * ({ a: {b: 10}}).should.have.propertyByPath('a', 'b').eql(10); */ Assertion.add('propertyByPath', function(properties) { if (arguments.length > 1) properties = aSlice.call(arguments); else if (arguments.length === 1 && typeof properties == 'string') properties = [properties]; else if (arguments.length === 0) properties = []; var allProps = properties.map(util.formatProp); properties = properties.map(String); var obj = should(Object(this.obj)); var foundProperties = []; var currentProperty; while (properties.length) { currentProperty = properties.shift(); this.params = {operator: 'to have property by path ' + allProps.join(', ') + ' - failed on ' + util.formatProp(currentProperty)}; obj = obj.have.property(currentProperty); foundProperties.push(currentProperty); } this.params = {obj: this.obj, operator: 'to have property by path ' + allProps.join(', ')}; this.obj = obj.obj; }); }; should.js-8.4.0~dfsg/lib/ext/string.js000066400000000000000000000022701301217646700177200ustar00rootroot00000000000000/* * should.js - assertion library * Copyright(c) 2010-2013 TJ Holowaychuk * Copyright(c) 2013-2016 Denis Bardadym * MIT Licensed */ module.exports = function(should, Assertion) { /** * Assert given string starts with prefix * @name startWith * @memberOf Assertion * @category assertion strings * @param {string} str Prefix * @param {string} [description] Optional message * @example * * 'abc'.should.startWith('a'); */ Assertion.add('startWith', function(str, description) { this.params = { operator: 'to start with ' + should.format(str), message: description }; this.assert(0 === this.obj.indexOf(str)); }); /** * Assert given string ends with prefix * @name endWith * @memberOf Assertion * @category assertion strings * @param {string} str Prefix * @param {string} [description] Optional message * @example * * 'abca'.should.endWith('a'); */ Assertion.add('endWith', function(str, description) { this.params = { operator: 'to end with ' + should.format(str), message: description }; this.assert(this.obj.indexOf(str, this.obj.length - str.length) >= 0); }); }; should.js-8.4.0~dfsg/lib/ext/type.js000066400000000000000000000132141301217646700173730ustar00rootroot00000000000000/* * should.js - assertion library * Copyright(c) 2010-2013 TJ Holowaychuk * Copyright(c) 2013-2016 Denis Bardadym * MIT Licensed */ var util = require('../util'); module.exports = function(should, Assertion) { /** * Assert given object is number * @name Number * @memberOf Assertion * @category assertion types */ Assertion.add('Number', function() { this.params = {operator: 'to be a number'}; this.have.type('number'); }); /** * Assert given object is arguments * @name arguments * @alias Assertion#Arguments * @memberOf Assertion * @category assertion types */ Assertion.add('arguments', function() { this.params = {operator: 'to be arguments'}; this.have.class('Arguments'); }); Assertion.alias('arguments', 'Arguments'); /** * Assert given object has some type using `typeof` * @name type * @memberOf Assertion * @param {string} type Type name * @param {string} [description] Optional message * @category assertion types */ Assertion.add('type', function(type, description) { this.params = {operator: 'to have type ' + type, message: description}; should(typeof this.obj).be.exactly(type); }); /** * Assert given object is instance of `constructor` * @name instanceof * @alias Assertion#instanceOf * @memberOf Assertion * @param {Function} constructor Constructor function * @param {string} [description] Optional message * @category assertion types */ Assertion.add('instanceof', function(constructor, description) { this.params = {operator: 'to be an instance of ' + util.functionName(constructor), message: description}; this.assert(Object(this.obj) instanceof constructor); }); Assertion.alias('instanceof', 'instanceOf'); /** * Assert given object is function * @name Function * @memberOf Assertion * @category assertion types */ Assertion.add('Function', function() { this.params = {operator: 'to be a function'}; this.have.type('function'); }); /** * Assert given object is object * @name Object * @memberOf Assertion * @category assertion types */ Assertion.add('Object', function() { this.params = {operator: 'to be an object'}; this.is.not.null().and.have.type('object'); }); /** * Assert given object is string * @name String * @memberOf Assertion * @category assertion types */ Assertion.add('String', function() { this.params = {operator: 'to be a string'}; this.have.type('string'); }); /** * Assert given object is array * @name Array * @memberOf Assertion * @category assertion types */ Assertion.add('Array', function() { this.params = {operator: 'to be an array'}; this.have.class('Array'); }); /** * Assert given object is boolean * @name Boolean * @memberOf Assertion * @category assertion types */ Assertion.add('Boolean', function() { this.params = {operator: 'to be a boolean'}; this.have.type('boolean'); }); /** * Assert given object is error * @name Error * @memberOf Assertion * @category assertion types */ Assertion.add('Error', function() { this.params = {operator: 'to be an error'}; this.have.instanceOf(Error); }); /** * Assert given object is a date * @name Date * @memberOf Assertion * @category assertion types */ Assertion.add('Date', function() { this.params = {operator: 'to be a date'}; this.have.instanceOf(Date); }); /** * Assert given object is null * @name null * @alias Assertion#Null * @memberOf Assertion * @category assertion types */ Assertion.add('null', function() { this.params = {operator: 'to be null'}; this.assert(this.obj === null); }); Assertion.alias('null', 'Null'); /** * Assert given object has some internal [[Class]], via Object.prototype.toString call * @name class * @alias Assertion#Class * @memberOf Assertion * @category assertion types */ Assertion.add('class', function(cls) { this.params = {operator: 'to have [[Class]] ' + cls}; this.assert(Object.prototype.toString.call(this.obj) === '[object ' + cls + ']'); }); Assertion.alias('class', 'Class'); /** * Assert given object is undefined * @name undefined * @alias Assertion#Undefined * @memberOf Assertion * @category assertion types */ Assertion.add('undefined', function() { this.params = {operator: 'to be undefined'}; this.assert(this.obj === void 0); }); Assertion.alias('undefined', 'Undefined'); /** * Assert given object supports es6 iterable protocol (just check * that object has property Symbol.iterator, which is a function) * @name iterable * @memberOf Assertion * @category assertion es6 */ Assertion.add('iterable', function() { this.params = {operator: 'to be iterable'}; should(this.obj).have.property(Symbol.iterator).which.is.a.Function(); }); /** * Assert given object supports es6 iterator protocol (just check * that object has property next, which is a function) * @name iterator * @memberOf Assertion * @category assertion es6 */ Assertion.add('iterator', function() { this.params = {operator: 'to be iterator'}; should(this.obj).have.property('next').which.is.a.Function(); }); /** * Assert given object is a generator object * @name generator * @memberOf Assertion * @category assertion es6 */ Assertion.add('generator', function() { this.params = {operator: 'to be generator'}; should(this.obj).be.iterable .and.iterator .and.it.is.equal(this.obj[Symbol.iterator]()); }); }; should.js-8.4.0~dfsg/lib/should.js000066400000000000000000000110331301217646700171050ustar00rootroot00000000000000/* * should.js - assertion library * Copyright(c) 2010-2013 TJ Holowaychuk * Copyright(c) 2013-2016 Denis Bardadym * MIT Licensed */ var util = require('./util'); /** * Our function should * * @param {*} obj Object to assert * @returns {should.Assertion} Returns new Assertion for beginning assertion chain * @example * * var should = require('should'); * should('abc').be.a.String(); */ function should(obj) { return (new should.Assertion(obj)); } should.AssertionError = require('./assertion-error'); should.Assertion = require('./assertion'); should.format = util.format; should.type = require('should-type'); should.util = util; /** * Object with configuration. * It contains such properties: * * `checkProtoEql` boolean - Affect if `.eql` will check objects prototypes * * `plusZeroAndMinusZeroEqual` boolean - Affect if `.eql` will treat +0 and -0 as equal * Also it can contain options for should-format. * * @type {Object} * @memberOf should * @static * @example * * var a = { a: 10 }, b = Object.create(null); * b.a = 10; * * a.should.be.eql(b); * //not throws * * should.config.checkProtoEql = true; * a.should.be.eql(b); * //throws AssertionError: expected { a: 10 } to equal { a: 10 } (because A and B have different prototypes) */ should.config = require('./config'); // Expose should to external world. exports = module.exports = should; /** * Allow to extend given prototype with should property using given name. This getter will **unwrap** all standard wrappers like `Number`, `Boolean`, `String`. * Using `should(obj)` is the equivalent of using `obj.should` with known issues (like nulls and method calls etc). * * To add new assertions, need to use Assertion.add method. * * @param {string} [propertyName] Name of property to add. Default is `'should'`. * @param {Object} [proto] Prototype to extend with. Default is `Object.prototype`. * @memberOf should * @returns {{ name: string, descriptor: Object, proto: Object }} Descriptor enough to return all back * @static * @example * * var prev = should.extend('must', Object.prototype); * * 'abc'.must.startWith('a'); * * var should = should.noConflict(prev); * should.not.exist(Object.prototype.must); */ should.extend = function(propertyName, proto) { propertyName = propertyName || 'should'; proto = proto || Object.prototype; var prevDescriptor = Object.getOwnPropertyDescriptor(proto, propertyName); Object.defineProperty(proto, propertyName, { set: function() { }, get: function() { return should(util.isWrapperType(this) ? this.valueOf() : this); }, configurable: true }); return { name: propertyName, descriptor: prevDescriptor, proto: proto }; }; /** * Delete previous extension. If `desc` missing it will remove default extension. * * @param {{ name: string, descriptor: Object, proto: Object }} [desc] Returned from `should.extend` object * @memberOf should * @returns {Function} Returns should function * @static * @example * * var should = require('should').noConflict(); * * should(Object.prototype).not.have.property('should'); * * var prev = should.extend('must', Object.prototype); * 'abc'.must.startWith('a'); * should.noConflict(prev); * * should(Object.prototype).not.have.property('must'); */ should.noConflict = function(desc) { desc = desc || should._prevShould; if (desc) { delete desc.proto[desc.name]; if (desc.descriptor) { Object.defineProperty(desc.proto, desc.name, desc.descriptor); } } return should; }; /** * Simple utility function for a bit more easier should assertion extension * @param {Function} f So called plugin function. It should accept 2 arguments: `should` function and `Assertion` constructor * @memberOf should * @returns {Function} Returns `should` function * @static * @example * * should.use(function(should, Assertion) { * Assertion.add('asset', function() { * this.params = { operator: 'to be asset' }; * * this.obj.should.have.property('id').which.is.a.Number(); * this.obj.should.have.property('path'); * }) * }) */ should.use = function(f) { f(should, should.Assertion); return this; }; should .use(require('./ext/assert')) .use(require('./ext/chain')) .use(require('./ext/bool')) .use(require('./ext/number')) .use(require('./ext/eql')) .use(require('./ext/type')) .use(require('./ext/string')) .use(require('./ext/property')) .use(require('./ext/error')) .use(require('./ext/match')) .use(require('./ext/contain')) .use(require('./ext/promise')); should.js-8.4.0~dfsg/lib/util.js000066400000000000000000000064161301217646700165750ustar00rootroot00000000000000/* * should.js - assertion library * Copyright(c) 2010-2013 TJ Holowaychuk * Copyright(c) 2013-2016 Denis Bardadym * MIT Licensed */ var type = require('should-type'); var config = require('./config'); /** * Check if given obj just a primitive type wrapper * @param {Object} obj * @returns {boolean} * @private */ exports.isWrapperType = function(obj) { return obj instanceof Number || obj instanceof String || obj instanceof Boolean; }; exports.merge = function(a, b) { if (a && b) { for (var key in b) { a[key] = b[key]; } } return a; }; var hasOwnProperty = Object.prototype.hasOwnProperty; exports.forEach = function forEach(obj, f, context) { if (exports.isGeneratorFunction(obj)) { return forEach(obj(), f, context); } else if (exports.isGeneratorObject(obj)) { var value = obj.next(); while (!value.done) { if (f.call(context, value.value, 'value', obj) === false) return; value = obj.next(); } } else { for (var prop in obj) { if (hasOwnProperty.call(obj, prop)) { if (f.call(context, obj[prop], prop, obj) === false) return; } } } }; exports.some = function(obj, f, context) { var res = false; exports.forEach(obj, function(value, key) { if (f.call(context, value, key, obj)) { res = true; return false; } }, context); return res; }; exports.isEmptyObject = function(obj) { for (var prop in obj) { if (hasOwnProperty.call(obj, prop)) { return false; } } return true; }; exports.isIndexable = function(obj) { var t = type(obj); return (t.type === type.OBJECT && t.cls === type.ARRAY) || (t.type === type.OBJECT && t.cls === type.BUFFER) || (t.type === type.OBJECT && t.cls === type.ARGUMENTS) || (t.type === type.OBJECT && t.cls === type.ARRAY_BUFFER) || (t.type === type.OBJECT && t.cls === type.TYPED_ARRAY) || (t.type === type.OBJECT && t.cls === type.DATA_VIEW) || (t.type === type.OBJECT && t.cls === type.STRING) || (t.type === type.STRING); }; exports.length = function(obj) { var t = type(obj); switch (t.type) { case type.STRING: return obj.length; case type.OBJECT: switch (t.cls) { case type.ARRAY_BUFFER: case type.TYPED_ARRAY: case type.DATA_VIEW: return obj.byteLength; case type.ARRAY: case type.BUFFER: case type.ARGUMENTS: case type.FUNCTION: return obj.length; } } }; exports.convertPropertyName = function(name) { if (typeof name == 'symbol') { return name; } else { return String(name); } }; exports.isGeneratorObject = function(obj) { if (!obj) return false; return typeof obj.next == 'function' && typeof obj[Symbol.iterator] == 'function' && obj[Symbol.iterator]() === obj; }; //TODO find better way exports.isGeneratorFunction = function(f) { if (typeof f != 'function') return false; return /^function\s*\*\s*/.test(f.toString()); }; exports.format = function(value, opts) { return config.getFormatter(opts).format(value); }; exports.functionName = require('should-format').Formatter.functionName; exports.formatProp = function(value) { return config.getFormatter().formatPropertyName(String(value)); }; should.js-8.4.0~dfsg/package.json000066400000000000000000000024051301217646700167740ustar00rootroot00000000000000{ "name": "should", "description": "test framework agnostic BDD-style assertions", "version": "8.4.0", "author": "TJ Holowaychuk , Denis Bardadym and other contributors", "repository": { "type": "git", "url": "https://github.com/shouldjs/should.js.git" }, "homepage": "https://github.com/shouldjs/should.js", "scripts": { "test": "mocha -R mocha-better-spec-reporter --check-leaks ./test/*.test.js ./test/**/*.test.js", "zuul": "zuul -- ./test/**/*.test.js ./test/*.test.js", "browser": "gulp script" }, "devDependencies": { "bluebird": "^3.0.6", "browserify": "latest", "bundle-collapser": "^1.2.1", "eslint": "^2.4.0", "gulp": "^3.8.10", "gulp-derequire": "^2.1.0", "gulp-rename": "^1.2.0", "gulp-uglify": "^1.0.1", "gulp-wrapper": "^1.0.0", "lodash.template": "^4.2.4", "mocha": "latest", "mocha-better-spec-reporter": "latest", "vinyl-buffer": "^1.0.0", "vinyl-source-stream": "^1.1.0", "zuul": "latest" }, "keywords": [ "test", "bdd", "assert", "should" ], "main": "./index.js", "license": "MIT", "dependencies": { "should-equal": "0.8.0", "should-format": "0.3.2", "should-type": "0.2.0" } } should.js-8.4.0~dfsg/test/000077500000000000000000000000001301217646700154645ustar00rootroot00000000000000should.js-8.4.0~dfsg/test/exist.test.js000066400000000000000000000040201301217646700201300ustar00rootroot00000000000000/** * Module dependencies. */ var should = require('../'); function err(fn, msg) { try { fn(); should.fail('expected an error'); } catch (err) { should.equal(msg, err.message); } } function err_should_exist(obj) { err(function() { should.exist(obj); }, 'expected ' + should.format(obj) + ' to exist'); } function err_should_not_exist(obj) { err(function() { should.not.exist(obj); }, 'expected ' + should.format(obj) + ' to not exist'); } describe('exist', function() { // static should.exist() pass, it('test static should.exist() pass w/ bool', function() { should.exist(false); }); it('test static should.exist() pass w/ number', function() { should.exist(0); }); it('test static should.exist() pass w/ string', function() { should.exist(''); }); it('test static should.exist() pass w/ object', function() { should.exist({}); }); it('test static should.exist() pass w/ array', function() { should.exist([]); }); // static should.exist() fail, it('test static should.exist() fail w/ null', function() { err_should_exist(null); }); it('test static should.exist() fail w/ undefined', function() { err_should_exist(undefined); }); // static should.not.exist() pass, it('test static should.not.exist() pass w/ null', function() { should.not.exist(null); }); it('test static should.not.exist() pass w/ undefined', function() { should.not.exist(undefined); }); // static should.not.exist() fail, it('test static should.not.exist() fail w/ bool', function() { err_should_not_exist(false); }); it('test static should.not.exist() fail w/ number', function() { err_should_not_exist(0); }); it('test static should.not.exist() fail w/ string', function() { err_should_not_exist(''); }); it('test static should.not.exist() fail w/ object', function() { err_should_not_exist({}); }); it('test static should.not.exist() fail w/ array', function() { err_should_not_exist([]); }); }); should.js-8.4.0~dfsg/test/ext/000077500000000000000000000000001301217646700162645ustar00rootroot00000000000000should.js-8.4.0~dfsg/test/ext/assert.test.js000066400000000000000000000253351301217646700211110ustar00rootroot00000000000000// Copyright Joyent, Inc. and other Node contributors. // // Permission is hereby granted, free of charge, to any person obtaining a // copy of this software and associated documentation files (the // "Software"), to deal in the Software without restriction, including // without limitation the rights to use, copy, modify, merge, publish, // distribute, sublicense, and/or sell copies of the Software, and to permit // persons to whom the Software is furnished to do so, subject to the // following conditions: // // The above copyright notice and this permission notice shall be included // in all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE // USE OR OTHER DEALINGS IN THE SOFTWARE. var assert = require('../../'); var keys = Object.keys; function makeBlock(f) { var args = Array.prototype.slice.call(arguments, 1); return function() { return f.apply(this, args); }; } describe('assert', function() { it('.ok', function() { assert.throws(makeBlock(assert.ok, false), assert.AssertionError, 'ok(false)'); assert.doesNotThrow(makeBlock(assert.ok, true), assert.AssertionError, 'ok(true)'); assert.doesNotThrow(makeBlock(assert.ok, 'test', 'ok(\'test\')')); assert.throws(makeBlock(assert.ok, false), assert.AssertionError, 'ok(false)'); assert.doesNotThrow(makeBlock(assert.ok, true), assert.AssertionError, 'ok(true)'); assert.doesNotThrow(makeBlock(assert.ok, 'test'), 'ok(\'test\')'); }); it('.equal', function() { assert.throws(makeBlock(assert.equal, true, false), assert.AssertionError, 'equal'); assert.doesNotThrow(makeBlock(assert.equal, null, null), 'equal'); assert.doesNotThrow(makeBlock(assert.equal, undefined, undefined), 'equal'); assert.doesNotThrow(makeBlock(assert.equal, null, undefined), 'equal'); assert.doesNotThrow(makeBlock(assert.equal, true, true), 'equal'); assert.doesNotThrow(makeBlock(assert.equal, 2, '2'), 'equal'); assert.doesNotThrow(makeBlock(assert.notEqual, true, false), 'notEqual'); assert.throws(makeBlock(assert.notEqual, true, true), assert.AssertionError, 'notEqual'); }); it('.strictEqual', function() { assert.throws(makeBlock(assert.strictEqual, 2, '2'), assert.AssertionError, 'strictEqual'); assert.throws(makeBlock(assert.strictEqual, null, undefined), assert.AssertionError, 'strictEqual'); assert.doesNotThrow(makeBlock(assert.notStrictEqual, 2, '2'), 'notStrictEqual'); }); it('.deepEqual - 7.2', function() { assert.doesNotThrow(makeBlock(assert.deepEqual, new Date(2000, 3, 14), new Date(2000, 3, 14)), 'deepEqual date'); assert.throws(makeBlock(assert.deepEqual, new Date(), new Date(2000, 3, 14)), assert.AssertionError, 'deepEqual date'); }); it('.deepEqual - 7.3', function() { assert.doesNotThrow(makeBlock(assert.deepEqual, /a/, /a/)); assert.doesNotThrow(makeBlock(assert.deepEqual, /a/g, /a/g)); assert.doesNotThrow(makeBlock(assert.deepEqual, /a/i, /a/i)); assert.doesNotThrow(makeBlock(assert.deepEqual, /a/m, /a/m)); assert.doesNotThrow(makeBlock(assert.deepEqual, /a/igm, /a/igm)); assert.throws(makeBlock(assert.deepEqual, /ab/, /a/)); assert.throws(makeBlock(assert.deepEqual, /a/g, /a/)); assert.throws(makeBlock(assert.deepEqual, /a/i, /a/)); assert.throws(makeBlock(assert.deepEqual, /a/m, /a/)); assert.throws(makeBlock(assert.deepEqual, /a/igm, /a/im)); var re1 = /a/; re1.lastIndex = 3; assert.throws(makeBlock(assert.deepEqual, re1, /a/)); }); it('.deepEqual - 7.4', function() { assert.throws(makeBlock(assert.deepEqual, 4, '4'), 'deepEqual == check'); assert.throws(makeBlock(assert.deepEqual, true, 1), 'deepEqual == check'); assert.throws(makeBlock(assert.deepEqual, 4, '5'), assert.AssertionError, 'deepEqual == check'); }); it('.deepEqual - 7.5', function() { // having the same number of owned properties && the same set of keys assert.doesNotThrow(makeBlock(assert.deepEqual, {a: 4}, {a: 4})); assert.doesNotThrow(makeBlock(assert.deepEqual, {a: 4, b: '2'}, {a: 4, b: '2'})); assert.throws(makeBlock(assert.deepEqual, [4], ['4'])); assert.throws(makeBlock(assert.deepEqual, {a: 4}, {a: 4, b: true}), assert.AssertionError); assert.throws(makeBlock(assert.deepEqual, ['a'], {0: 'a'})); //(although not necessarily the same order), assert.doesNotThrow(makeBlock(assert.deepEqual, {a: 4, b: '1'}, {b: '1', a: 4})); var a1 = [1, 2, 3]; var a2 = [1, 2, 3]; a1.a = 'test'; a1.b = true; a2.b = true; a2.a = 'test'; assert.throws(makeBlock(assert.deepEqual, keys(a1), keys(a2)), assert.AssertionError); assert.doesNotThrow(makeBlock(assert.deepEqual, a1, a2)); }); it('.deepEqual - instances', function() { // having an identical prototype property var nbRoot = { toString: function() { return this.first + ' ' + this.last; } }; function nameBuilder(first, last) { this.first = first; this.last = last; return this; } nameBuilder.prototype = nbRoot; function nameBuilder2(first, last) { this.first = first; this.last = last; return this; } nameBuilder2.prototype = nbRoot; var nb1 = new nameBuilder('Ryan', 'Dahl'); var nb2 = new nameBuilder2('Ryan', 'Dahl'); assert.doesNotThrow(makeBlock(assert.deepEqual, nb1, nb2)); // assert working there only because nb2 prototype is Function - it really does not check prototypes nameBuilder2.prototype = Object; nb2 = new nameBuilder2('Ryan', 'Dahl'); assert.throws(makeBlock(assert.deepEqual, nb1, nb2), assert.AssertionError); // String literal + object blew up my implementation... assert.throws(makeBlock(assert.deepEqual, 'a', {}), assert.AssertionError); }); function thrower(errorConstructor) { throw new errorConstructor('test'); } it('Testing the throwing', function() { makeBlock(thrower, assert.AssertionError); // the basic calls work assert.throws(makeBlock(thrower, assert.AssertionError), assert.AssertionError, 'message'); assert.throws(makeBlock(thrower, assert.AssertionError), assert.AssertionError); assert.throws(makeBlock(thrower, assert.AssertionError)); // if not passing an error, catch all. assert.throws(makeBlock(thrower, TypeError)); // when passing a type, only catch errors of the appropriate type var threw = false; try { assert.throws(makeBlock(thrower, TypeError), assert.AssertionError); } catch (e) { threw = true; assert.ok(e instanceof TypeError, 'type'); } assert.equal(true, threw, 'a.throws with an explicit error is eating extra errors', assert.AssertionError); threw = false; // doesNotThrow should pass through all errors try { assert.doesNotThrow(makeBlock(thrower, TypeError), assert.AssertionError); } catch (e) { threw = true; assert.ok(e instanceof TypeError); } assert.equal(true, threw, 'a.doesNotThrow with an explicit error is eating extra errors'); // key difference is that throwing our correct error makes an assertion error try { assert.doesNotThrow(makeBlock(thrower, TypeError), TypeError); } catch (e) { threw = true; assert.ok(e instanceof assert.AssertionError); } assert.equal(true, threw, 'a.doesNotThrow is not catching type matching errors'); }); it('.ifError', function() { assert.throws(function() { assert.ifError(new Error('test error')); }); assert.doesNotThrow(function() { assert.ifError(null); }); assert.doesNotThrow(function() { assert.ifError(); }); }); it('make sure that validating using constructor really works', function() { var threw = false; try { assert.throws( function() { throw ({}); }, Array ); } catch (e) { threw = true; } assert.ok(threw, 'wrong constructor validation'); }); it(' use a RegExp to validate error message', function() { assert.throws(makeBlock(thrower, TypeError), /test/); }); it('se a fn to validate error object', function() { assert.throws(makeBlock(thrower, TypeError), function(err) { if ((err instanceof TypeError) && /test/.test(err)) { return true; } }); }); it('Make sure deepEqual doesn\'t loop forever on circular refs', function() { var b = {}; b.b = b; var c = {}; c.b = c; var gotError = false; try { assert.deepEqual(b, c); } catch (e) { gotError = true; } assert.ok(!gotError); }); it('test assertion message', function() { function testAssertionMessage(actual, expected) { try { assert.equal(actual, ''); } catch (e) { assert.equal(e.toString(), ['AssertionError: expected', expected, '==', "''"].join(' ')); } } testAssertionMessage(undefined, 'undefined'); testAssertionMessage(null, 'null'); testAssertionMessage(true, 'true'); testAssertionMessage(false, 'false'); testAssertionMessage(0, '0'); testAssertionMessage(100, '100'); testAssertionMessage(NaN, 'NaN'); testAssertionMessage(Infinity, 'Infinity'); testAssertionMessage(-Infinity, '-Infinity'); testAssertionMessage('', '""'); testAssertionMessage('foo', "'foo'"); testAssertionMessage([], 'Array []'); testAssertionMessage([1, 2, 3], 'Array [ 1, 2, 3 ]'); testAssertionMessage(/a/, '/a/'); testAssertionMessage(function f() { }, 'Function { name: \'f\' }'); testAssertionMessage({}, 'Object {}'); testAssertionMessage({a: undefined, b: null}, 'Object { a: undefined, b: null }'); testAssertionMessage({a: NaN, b: Infinity, c: -Infinity}, 'Object { a: NaN, b: Infinity, c: -Infinity }'); }); it('regressions from node.js testcase', function() { var threw = false; try { assert.throws(function() { assert.ifError(null); }); } catch (e) { threw = true; assert.equal(e.message, 'Missing expected exception..'); } assert.ok(threw); try { assert.equal(1, 2); } catch (e) { assert.equal(e.toString().split('\n')[0], 'AssertionError: expected 1 == 2'); } try { assert.equal(1, 2, 'oh no'); } catch (e) { assert.equal(e.toString().split('\n')[0], 'AssertionError: oh no'); } }); }); should.js-8.4.0~dfsg/test/ext/bool.test.js000066400000000000000000000023661301217646700205420ustar00rootroot00000000000000var err = require('../util').err; require('../../'); describe('bool', function() { it('test true', function() { true.should.be.true(); false.should.not.be.true(); (1).should.not.be.true(); err(function() { 'test'.should.be.true(); }, "expected 'test' to be true"); err(function() { true.should.not.be.true(); }, "expected true not to be true (false negative fail)"); err(function() { (false).should.be.true('My text'); }, 'My text'); }); it('test false', function() { false.should.be.false(); true.should.not.be.false(); (0).should.not.be.false(); err(function() { ''.should.be.false(); }, "expected '' to be false"); err(function() { false.should.not.be.false(); }, "expected false not to be false (false negative fail)"); err(function() { (true).should.be.false('My text'); }, 'My text'); }); it('test ok', function() { true.should.be.ok(); false.should.not.be.ok(); (1).should.be.ok(); (0).should.not.be.ok(); err(function() { ''.should.be.ok(); }, "expected '' to be truthy"); err(function() { 'test'.should.not.be.ok(); }, "expected 'test' not to be truthy (false negative fail)"); }); }); should.js-8.4.0~dfsg/test/ext/contain.test.js000066400000000000000000000101471301217646700212360ustar00rootroot00000000000000var err = require('../util').err; require('../../'); describe('contain*', function() { it('test containEql', function() { 'hello boy'.should.containEql('boy'); [1, 2, 3].should.containEql(3); [ [1], [2], [3] ].should.containEql([3]); [ [1], [2], [3, 4] ].should.not.containEql([3]); [ {a: 'a'}, {b: 'b', c: 'c'} ].should.containEql({a: 'a'}); [ {a: 'a'}, {b: 'b', c: 'c'} ].should.not.containEql({b: 'b'}); ({}).should.not.containEql({ a: 10 }); ({ b: 10 }).should.containEql({ b: 10 }); [1, 2, 3].should.containEql(1); ([1, 2, { a: 10 }]).should.containEql({ a: 10 }); [1, 2, 3].should.not.containEql({ a: 1 }); err(function() { [1, 2, 3].should.not.containEql(3); }, 'expected Array [ 1, 2, 3 ] not to contain 3 (false negative fail)'); err(function() { [1, 2, 3].should.containEql(4); }, 'expected Array [ 1, 2, 3 ] to contain 4'); }); it('test containDeep', function() { ({ a: { b: 10 }, b: { c: 10, d: 11, a: { b: 10, c: 11} }}).should .containDeep({ a: { b: 10 }, b: { c: 10, a: { c: 11 }}}); [1, 2, 3, { a: { b: { d: 12 }}}].should.containDeep([ { a: { b: {d: 12}}} ]); [ [1, [2, 3], 3], [2] ].should.not.containDeep([1, 2]); [ [1], [2], [3] ].should.containDeep([ [3] ]); [ [1], [2], [3, 4] ].should.containDeep([ [3] ]); [ [1], [2], [3, 4] ].should.containDeep([ [1], [3] ]); [ [1], [2], [3, 4] ].should.containDeep([ [3], [1] ]); [1, 2, 3].should.not.containDeep([3, 3, 3]); [1, 2, 3].should.containDeep([3]); [ {a: 'a'}, {b: 'b', c: 'c'} ].should.containDeep([ {a: 'a'} ]); [ {a: 'a'}, {b: 'b', c: 'c'} ].should.containDeep([ {b: 'b'} ]); [1, 2, 3].should.containDeep([3, 2]); ['code-for-days', 'code'].should.containDeep(['code', 'code-for-days']); ['code-for-days', 'code-fast'].should.containDeep(['code-fast', 'code-for-days']); err(function() { [ {a: 'a'}, {b: 'b', c: 'c'} ].should.not.containDeep([ {b: 'b'} ]); }, "expected Array [ Object { a: 'a' }, Object { b: 'b', c: 'c' } ] not to contain Array [ Object { b: 'b' } ] (false negative fail)"); ({hi: null}).should.containEql({hi: null}); var firstDec = [{date: (new Date('2014-12-01 00:00:00'))}]; var secondDec = [{date: (new Date('2014-12-02 00:00:00'))}]; firstDec.should.not.containDeep(secondDec); [{date: { d: (new Date('2014-12-01 00:00:00'))}}].should.not.containDeep([{date: (new Date('2014-12-02 00:00:00'))}]); }); it('test containDeepOrdered', function() { ({ a: { b: 10 }, b: { c: 10, d: 11, a: { b: 10, c: 11} }}).should .containDeepOrdered({ a: { b: 10 }, b: { c: 10, a: { c: 11 }}}); [1, 2, 3, { a: { b: { d: 12 }}}].should.containDeepOrdered([ { a: { b: {d: 12}}} ]); [ [1, [2, 3], 3], [2] ].should.not.containDeepOrdered([1, 2]); [ [1], [2], [3] ].should.containDeepOrdered([ [3] ]); [ [1], [2], [3, 4] ].should.containDeepOrdered([ [3] ]); [ [1], [2], [3, 4] ].should.containDeepOrdered([ [1], [3] ]); [ [1], [2], [3, 4] ].should.not.containDeepOrdered([ [3], [1] ]); [ {a: 'a'}, {b: 'b', c: 'c'} ].should.containDeepOrdered([ {a: 'a'} ]); [ {a: 'a'}, {b: 'b', c: 'c'} ].should.containDeepOrdered([ {b: 'b'} ]); err(function() { [ {a: 'a'}, {b: 'b', c: 'c'} ].should.not.containDeepOrdered([ {b: 'b'} ]); }, "expected Array [ Object { a: 'a' }, Object { b: 'b', c: 'c' } ] not to contain Array [ Object { b: 'b' } ] (false negative fail)"); ({hi: null}).should.containEql({hi: null}); }); }); should.js-8.4.0~dfsg/test/ext/eql.test.js000066400000000000000000000034241301217646700203640ustar00rootroot00000000000000var err = require('../util').err, should = require('../../'); describe('eql', function() { it('test eql(val)', function() { 'test'.should.eql('test'); ({foo: 'bar'}).should.eql({foo: 'bar'}); (1).should.eql(1); var memo = []; function memorize() { memo.push(arguments); } memorize('a', [1, 2]); memorize('a', [1, 2]); memo[0].should.eql(memo[1]); err(function() { (4).should.eql(3); }, 'expected 4 to equal 3'); }); it('test equal(val)', function() { 'test'.should.equal('test'); (1).should.equal(1); err(function() { (4).should.equal(3); }, 'expected 4 to be 3'); err(function() { '4'.should.equal(4); }, "expected '4' to be 4"); var date = new Date; date.should.equal(date); }); it('test .equal()', function() { var foo; should.equal(undefined, foo); }); it('should allow to test with prototypes', function() { var b = {a: 2}; var a = Object.create(null); a.a = 2; b.should.be.eql(a); should.config.checkProtoEql = true; err(function() { b.should.be.eql(a); }, 'expected Object { a: 2 } to equal { a: 2 } (because A and B have different prototypes)'); should.config.checkProtoEql = false; }); it('should check one of equal', function() { 'ab'.should.be.equalOneOf('a', 10, 'ab'); 'ab'.should.be.equalOneOf(['a', 10, 'ab']); 'ab'.should.not.be.equalOneOf(['a', 10]); 'ab'.should.not.be.equalOneOf('a', 10); }); it('should check one of deep equal', function() { ({ a: 'ab' }).should.not.be.oneOf('a', 10, 'ab'); ({ a: 'ab' }).should.not.be.oneOf(['a', 10, 'ab']); ({ a: 'ab' }).should.be.oneOf('a', 10, 'ab', { a: 'ab' }); ({ a: 'ab' }).should.be.oneOf(['a', 10, 'ab', { a: 'ab' }]); }); }); should.js-8.4.0~dfsg/test/ext/error.test.js000066400000000000000000000130031301217646700207260ustar00rootroot00000000000000var err = require('../util').err; require('../../'); describe('error', function() { it('test throw()', function() { err(function() { 'a'.should.throw(); }, 'expected \'a\' to be a function\n expected \'a\' to have type function\n expected \'string\' to be \'function\''); (function() {}).should.not.throw(); (function() { throw new Error('fail'); }).should.throw(); err(function() { (function() {}).should.throw(); }, 'expected Function { name: \'\' } to throw exception'); err(function() { (function() { throw new Error('fail'); }).should.not.throw(); }, /expected Function \{ name: '' \} not to throw exception \(got Error \{[\s\S]*message: 'fail'[\s\S]*\}\)/); }); it('test throw() with regex message', function() { (function() { throw new Error('fail'); }).should.throw(/fail/); err(function() { (function() {}).should.throw(/fail/); }, 'expected Function { name: \'\' } to throw exception'); err(function() { (function() { throw new Error('error'); }).should.throw(/fail/); }, "expected Function { name: \'\' } to throw exception with a message matching /fail/, but got 'error'"); }); it('test throw() with string message', function() { (function() { throw new Error('fail'); }).should.throw('fail'); err(function() { (function() {}).should.throw('fail'); }, 'expected Function { name: \'\' } to throw exception'); err(function() { (function() { throw new Error('error'); }).should.throw('fail'); }, "expected Function { name: \'\' } to throw exception with a message matching 'fail', but got 'error'"); }); it('test throw() with type', function() { (function() { throw new Error('fail'); }).should.throw(Error); err(function() { (function() {}).should.throw(Error); }, 'expected Function { name: \'\' } to throw exception'); err(function() { (function() { throw 'error'; }).should.throw(Error); }, 'expected Function { name: \'\' } to throw exception of type Error, but got String'); }); it('test throwError()', function() { (function() {}).should.not.throwError(); (function() { throw new Error('fail'); }).should.throwError(); err(function() { (function() {}).should.throwError(); }, 'expected Function { name: \'\' } to throw exception'); err(function() { (function() { throw new Error('fail'); }).should.not.throwError(); }, /expected Function \{ name: '' \} not to throw exception \(got Error \{[\s\S]*message: 'fail'[\s\S]*\}\)/); }); it('test throwError() with regex message', function() { (function() { throw new Error('fail'); }).should.throwError(/fail/); err(function() { (function() {}).should.throwError(/fail/); }, 'expected Function { name: \'\' } to throw exception'); err(function() { (function() { throw new Error('error'); }).should.throwError(/fail/); }, "expected Function { name: \'\' } to throw exception with a message matching /fail/, but got 'error'"); }); it('test throwError() with string message', function() { (function() { throw new Error('fail'); }).should.throwError('fail'); err(function() { (function() {}).should.throwError('fail'); }, 'expected Function { name: \'\' } to throw exception'); err(function() { (function() { throw new Error('error'); }).should.throwError('fail'); }, "expected Function { name: \'\' } to throw exception with a message matching 'fail', but got 'error'"); }); it('test throwError() with type', function() { (function() { throw new Error('fail'); }).should.throw(Error); err(function() { (function() {}).should.throw(Error); }, 'expected Function { name: \'\' } to throw exception'); err(function() { (function() { throw 'error'; }).should.throw(Error); }, "expected Function { name: '' } to throw exception of type Error, but got String"); }); it('test .throw(err, properties) with matching error', function() { var error = new Error(); error.a = 10; (function() { throw error; }).should.throw(Error, { a: 10 }); err(function() { (function() { throw error; }).should.throw(Error, { a: 11 }); }, /expected Function \{ name: '' \} to throw exception: expected Error \{[\s\S]*a: 10,[\s\S]*message: ''[\s\S]*\} to match Object \{ a: 11 \}\n\s{4}not matched properties: a \(10\)/); }); it('test .throw(properties) with matching error', function() { var error = new Error(); error.a = 10; (function() { throw error; }).should.throw({ a: 10 }); err(function() { (function() { throw error; }).should.throw({ a: 11 }); }, /expected Function \{ name: '' \} to throw exception: expected Error \{[\s\S]*a: 10,[\s\S]*message: ''[\s\S]*\} to match Object \{ a: 11 \}\n\s{4}not matched properties: a \(10\)/); }); /* TODO find a way to write tests with es6 features it('should support to catch errors from generators', function() { if(generatorSupported) { var throwsError = function*() { throw new Error(); } (function * () { yield throwsError(); }).should.throw(); var throwsError1 = function*() { throw new Error(); yield console.log('hello'); } (function * () { yield throwsError1(); }).should.throw(); var noError = function * () { yield console.log('no error') }; err(function(){ (function * () {yield noError();}).should.throw(); }, 'expected Function { name: \'\' } to throw exception'); } });*/ }); should.js-8.4.0~dfsg/test/ext/match.test.js000066400000000000000000000140651301217646700207020ustar00rootroot00000000000000var err = require('../util').err; require('../../'); describe('match', function() { it('test string match(regexp)', function() { 'foobar'.should.match(/^foo/); 'foobar'.should.not.match(/^bar/); err(function() { 'foobar'.should.match(/^bar/i); }, "expected 'foobar' to match /^bar/i"); err(function() { 'foobar'.should.not.match(/^foo/i); }, "expected 'foobar' not to match /^foo/i (false negative fail)"); err(function() { 'foobar'.should.match(/^bar/i, 'foo'); }, "foo"); err(function() { 'foobar'.should.not.match(/^foo/i, 'foo'); }, "foo"); }); it('test object match(regexp)', function() { ({ a: 'foo', c: 'barfoo' }).should.match(/foo$/); ({ a: 'a' }).should.not.match(/^http/); // positive false err(function() { ({ a: 'foo', c: 'barfoo' }).should.not.match(/foo$/); }, "expected Object { a: 'foo', c: 'barfoo' } not to match /foo$/\n matched properties: a, c (false negative fail)"); // negative true err(function() { ({ a: 'foo', c: 'barfoo' }).should.match(/^foo$/); }, "expected Object { a: 'foo', c: 'barfoo' } to match /^foo$/\n not matched properties: c ('barfoo')\n matched properties: a"); }); it('test array match(regexp)', function() { ['a', 'b', 'c'].should.match(/[a-z]/); ['a', 'b', 'c'].should.not.match(/[d-z]/); err(function() { ['a', 'b', 'c'].should.not.match(/[a-z]/); }, "expected Array [ 'a', 'b', 'c' ] not to match /[a-z]/ (false negative fail)"); err(function() { ['a', 'b', 'c'].should.match(/[d-z]/); }, "expected Array [ 'a', 'b', 'c' ] to match /[d-z]/"); }); it('test match(function)', function() { (5).should.match(function(n) { return n > 0; }); (5).should.not.match(function(n) { return n < 0; }); (5).should.not.match(function(it) { it.should.be.an.Array(); }); (5).should.match(function(it) { it.should.be.a.Number(); }); err(function() { (5).should.match(function(n) { return n < 0; }); }, "expected 5 to match Function { name: '' }"); err(function() { (5).should.match(function(it) { it.should.be.an.Array(); }); }, "expected 5 to match Function { name: '' }\n expected 5 to be an array\n expected 5 to have [[Class]] Array"); err(function() { (5).should.not.match(function(it) { return it.should.be.a.Number(); }); }, "expected 5 not to match Function { name: '' } (false negative fail)"); err(function() { (5).should.not.match(function(n) { return n > 0; }); }, "expected 5 not to match Function { name: '' } (false negative fail)"); }); it('test match(object)', function() { ({ a: 10, b: 'abc', c: { d: 10 }, d: 0 }).should .match({ a: 10, b: /c$/, c: function(it) { return it.should.have.property('d', 10); }}); ({ nested: null }).should.not.match( { nested: { prop: /foo/ }} ); [10, 'abc', { d: 10 }, 0].should .match({ '0': 10, '1': /c$/, '2': function(it) { return it.should.have.property('d', 10); } }); [10, 'abc', { d: 10 }, 0].should .match([10, /c$/, function(it) { return it.should.have.property('d', 10); }]); var d = new Date(); var ds = d.toString(); d.should.not.match(ds); ds.should.not.match(d); err(function() { ({ a: 10, b: 'abc', c: { d: 10 }, d: 0 }).should .match({ a: 11, b: /c$/, c: function(it) { return it.should.have.property('d', 10); }}); }, "expected Object { a: 10, b: 'abc', c: Object { d: 10 }, d: 0 } to match Object { a: 11, b: /c$/, c: Function { name: '' } }\n not matched properties: a (10)\n matched properties: b, c"); err(function() { ({ a: 10, b: 'abc', c: { d: 10 }, d: 0 }).should.not .match({ a: 10, b: /c$/, c: function(it) { return it.should.have.property('d', 10); }}); }, "expected Object { a: 10, b: 'abc', c: Object { d: 10 }, d: 0 } not to match Object { a: 10, b: /c$/, c: Function { name: '' } }\n matched properties: a, b, c (false negative fail)"); }); it('test each property match(function)', function() { [10, 11, 12].should.matchEach(function(it) { return it >= 10; }); [10, 10].should.matchEach(10); ({ a: 10, b: 11, c: 12}).should.matchEach(function(value) { value.should.be.a.Number(); }); (['a', 'b', 'c']).should.matchEach(/[a-c]/); err(function() { (['a', 'b', 'c']).should.not.matchEach(/[a-c]/); }, "expected Array [ 'a', 'b', 'c' ] not to match each /[a-c]/ (false negative fail)"); err(function() { [10, 11].should.matchEach(10); }, 'expected Array [ 10, 11 ] to match each 10\n expected 11 to match 10'); }); it('test matchAny(obj)', function() { [{}, {nested: {prop: 'foo'}}].should.matchAny( {nested: {prop: 'foo'}} ); [ { nested: undefined }, { nested: { prop: 'foo' } } ].should.matchAny({ nested: { prop: /foo/ } }); }); it('test matchAny(function)', function() { [9, 10, 11].should.matchAny(function(it) { return it >= 10; }); [9, 10, 11].should.not.matchAny(function(it) { return it == 2; }); ({ a: 10, b: 11, c: 12}).should.matchAny(function(value) { value.should.be.a.Number(); }); ({ a: 10, b: 'eleven', c: 'twelve'}).should.matchAny(function(value) { value.should.be.a.Number(); }); }); it('test matchAny(number)', function() { [10, 11, 12].should.matchAny(10); [10, 10].should.matchAny(10); [10, 11, 12].should.not.matchAny(2); }); it('test matchAny(regexp)', function() { (['a', 'b', 'c']).should.matchAny(/[a-b]/); (['a', 'b', 'c']).should.not.matchAny(/[d-f]/); err(function() { (['a', 'b', 'c']).should.not.matchAny(/[a-c]/); }, "expected Array [ 'a', 'b', 'c' ] not to match any /[a-c]/ (false negative fail)"); err(function() { [8, 9].should.matchAny(10); }, "expected Array [ 8, 9 ] to match any 10"); }); }); should.js-8.4.0~dfsg/test/ext/number.test.js000066400000000000000000000070661301217646700211010ustar00rootroot00000000000000var err = require('../util').err; require('../../'); describe('number', function() { it('test NaN', function() { NaN.should.be.NaN(); Infinity.should.not.be.NaN(); (0).should.not.be.NaN(); false.should.not.be.NaN(); ({}).should.not.be.NaN(); ''.should.not.be.NaN(); 'foo'.should.not.be.NaN(); /^$/.should.not.be.NaN(); err(function() { Infinity.should.be.NaN(); }, "expected Infinity to be NaN"); err(function() { NaN.should.not.be.NaN(); }, "expected NaN not to be NaN (false negative fail)"); }); it('test Infinity', function() { NaN.should.not.be.Infinity(); (1/0).should.be.Infinity(); Infinity.should.be.Infinity(); (0).should.not.be.Infinity(); false.should.not.be.Infinity(); ({}).should.not.be.Infinity(); ''.should.not.be.Infinity(); 'foo'.should.not.be.Infinity(); /^$/.should.not.be.Infinity(); err(function() { NaN.should.be.Infinity(); }, "expected NaN to be Infinity\n expected NaN not to be NaN (false negative fail)"); err(function() { Infinity.should.not.be.Infinity(); }, "expected Infinity not to be Infinity (false negative fail)"); }); it('test within(start, finish)', function() { (5).should.be.within(5, 10); (5).should.be.within(3,6); (5).should.be.within(3,5); (5).should.not.be.within(1,3); err(function() { (5).should.not.be.within(4,6); }, "expected 5 not to be within 4..6 (false negative fail)"); err(function() { (10).should.be.within(50,100); }, "expected 10 to be within 50..100"); err(function() { (5).should.not.be.within(4,6, 'foo'); }, "foo"); err(function() { (10).should.be.within(50,100, 'foo'); }, "foo"); }); it('test approximately(number, delta)', function() { (1.5).should.be.approximately(1.4, 0.2); (1.5).should.be.approximately(1.5, 10E-10); (1.5).should.not.be.approximately(1.4, 1E-2); err(function() { (99.99).should.not.be.approximately(100, 0.1); }, "expected 99.99 not to be approximately 100 ±0.1 (false negative fail)"); err(function() { (99.99).should.be.approximately(105, 0.1); }, "expected 99.99 to be approximately 105 ±0.1"); }); it('test above(n)', function() { (5).should.be.above(2); (5).should.be.greaterThan(2); (5).should.not.be.above(5); (5).should.not.be.above(6); err(function() { (5).should.be.above(6); }, "expected 5 to be above 6"); err(function() { (10).should.not.be.above(6); }, "expected 10 not to be above 6 (false negative fail)"); err(function() { (5).should.be.above(6, 'foo'); }, "foo"); err(function() { (10).should.not.be.above(6, 'foo'); }, "foo"); }); it('test below(n)', function() { (2).should.be.below(5); (2).should.be.lessThan(5); (5).should.not.be.below(5); (6).should.not.be.below(5); err(function() { (6).should.be.below(5); }, "expected 6 to be below 5"); err(function() { (6).should.not.be.below(10); }, "expected 6 not to be below 10 (false negative fail)"); err(function() { (6).should.be.below(5, 'foo'); }, "foo"); err(function() { (6).should.not.be.below(10, 'foo'); }, "foo"); }); it('test aboveOrEqual(n)', function() { (5).should.be.aboveOrEqual(2); (5).should.be.aboveOrEqual(5); (5).should.not.be.aboveOrEqual(6); }); it('test belowOrEqual(n)', function() { (2).should.be.belowOrEqual(5); (5).should.be.belowOrEqual(5); (6).should.not.be.belowOrEqual(5); }); }); should.js-8.4.0~dfsg/test/ext/promise.test.js000066400000000000000000000117461301217646700212670ustar00rootroot00000000000000var should = require('../../'); var Promise = require('bluebird'); function promised(value) { return new Promise(function(resolve) { resolve(value); }); } function promiseFail() { return new Promise(function(resolve, reject) { reject(new Error('boom')); }); } function promiseFailTimeout() { return new Promise(function(resolve, reject) { setTimeout(function() { reject(new Error('boom')); }, 1000); }); } it('should return new assertion to hold promise', function() { var a = promised('abc').should.finally; return a.then.should.be.a.Function(); }); it('should determine if it is Promise', function() { promised('a').should.be.a.Promise(); }); it('should allow to chain calls like with usual assertion', function() { return promised('abc').should.finally.be.exactly('abc') .and.be.a.String(); }); it('should allow to use .not and .any', function() { return promised({a: 10, b: 'abc'}).should.finally.not.have.any.of.properties('c', 'd') .and.have.property('a', 10); }); it('should treat assertion like promise', function() { return Promise.all([ promised(10).should.finally.be.a.Number(), promised('abc').should.finally.be.a.String() ]); }); it('should propagate .not before .finally', function() { return promised(10).should.not.finally.be.a.String(); }); it('should be possible to use .eventually as an alias for .finally', function() { return promised(10).should.eventually.be.a.Number(); }); it('should allow to check if promise fulfilled', function() { return Promise.all([ promised(10).should.be.fulfilled(), //positive promiseFail().should.be.fulfilled().then(function() {//negative should.fail(); }, function(err) { err.should.be.Error().and.match({message: /expected \[Promise\] to be fulfilled, but it was rejected with Error \{[\s\S]*message: 'boom'[\s\S]*\}/}); }), promised(10).should.not.be.fulfilled().then(function() {//positive fail should.fail(); }, function(err) { err.should.be.Error().and.match({message: 'expected [Promise] not to be fulfilled'}); }), promiseFail().should.not.be.fulfilled()//negative fail ]); }); it('should be allow to check if promise is fulfilledWith a value', function() { return Promise.all([ promised(10).should.be.fulfilledWith(10), //positive promiseFail().should.be.fulfilledWith(10).then(function() {//negative should.fail(); }, function(err) { err.should.be.Error().and.match({message: /expected \[Promise\] to be fulfilled with 10, but it was rejected with Error \{[\s\S]*message: 'boom\'[\s\S]*\}/}); }), promised(10).should.not.be.fulfilledWith(10).then(function() {//positive fail should.fail(); }, function(err) { err.should.be.Error().and.match({message: 'expected [Promise] not to be fulfilled with 10'}); }), promiseFail().should.not.be.fulfilledWith(10)//negative fail ]); }); it('should be allow to check if promise rejected', function() { return Promise.all([ promiseFail().should.be.rejected(), //positive promised(10).should.be.rejected().then(function() {//negative should.fail(); }, function(err) { err.should.be.Error().and.match({message: 'expected [Promise] to be rejected, but it was fulfilled with 10'}); }), promiseFail().should.not.be.rejected().then(function() {//positive fail should.fail(); }, function(err) { err.should.be.Error().and.match({message: 'expected [Promise] not to be rejected'}); }), promised(10).should.not.be.rejected()//negative fail ]); }); it('should allow to match rejected error', function() { return Promise.all([ promiseFail().should.be.rejectedWith(Error), promiseFail().should.be.rejectedWith('boom'), promiseFail().should.be.rejectedWith('boom1').then(function() { return should.fail(); }, function(err) { return err.should.be.Error().and.match({ message: 'expected [Promise] to be rejected with a message matching \'boom1\', but got \'boom\''}); }), promiseFail().should.be.rejectedWith(/boom/), promiseFail().should.be.rejectedWith(Error, { message: 'boom' }), promiseFail().should.be.rejectedWith({ message: 'boom' }), promiseFail().should.not.be.rejectedWith().then(function() {//positive fail return should.fail(); }, function(err) { return err.should.be.Error().and.match({message: 'expected [Promise] not to be rejected'}); }), promised(10).should.be.rejectedWith().then(function() {//negative fail return should.fail(); }, function(err) { return err.should.be.Error().and.match({message: 'expected [Promise] to be rejected'}); }), promiseFail().should.not.be.rejectedWith(Error).then(function() {//negative fail return should.fail(); }, function(err) { return err.should.be.Error().and.match({message: 'expected [Promise] not to be rejected'}); }) ]); }); it('should properly check async promise', function() { return promiseFailTimeout().should.be.rejectedWith(Error, { message: 'boom' }); }); should.js-8.4.0~dfsg/test/ext/property.test.js000066400000000000000000000220501301217646700214630ustar00rootroot00000000000000var err = require('../util').err; require('../../'); describe('property', function() { it('test enumerable(name)', function() { ({'length': 5}).should.have.enumerable('length'); (4).should.not.have.enumerable('length'); err(function() { 'asd'.should.have.enumerable('length'); }, "expected 'asd' to have enumerable property length", " expected 'asd' to have own property with descriptor Object { enumerable: true }", " expected Object { configurable: false, enumerable: false, value: 3, writable: false } to have property enumerable of true (got false)"); }); it('test enumerable(name, val)', function() { ({'length': 5}).should.have.enumerable('length', 5); err(function() { ({'length': 3}).should.have.enumerable('length', 5); }, "expected Object { length: 3 } to have enumerable property length equal to 5", " expected Object { length: 3 } to have own property with descriptor Object { enumerable: true, value: 5 }", " expected Object { configurable: true, enumerable: true, value: 3, writable: true } to have property value of 5 (got 3)"); }); it('test enumerables(names)', function() { var obj = { a: 'a', b: 'b', c: 'c'}; obj.should.have.enumerables('a', 'b'); obj.should.have.enumerables(['a', 'b']); }); it('test property(name)', function() { 'test'.should.have.property('length'); (4).should.not.have.property('length'); err(function() { 'asd'.should.have.property('foo'); }, "expected 'asd' to have property foo"); }); it('test property(name, val)', function() { 'test'.should.have.property('length', 4); 'asd'.should.have.property('constructor', String); err(function() { 'asd'.should.have.property('length', 4); }, "expected 'asd' to have property length of 4 (got 3)"); err(function() { 'asd'.should.not.have.property('length', 3); }, "expected 'asd' not to have property length of 3 (false negative fail)"); err(function() { var obj = { f: function() {} }; var f1 = function() {}; f1.a = 1; obj.should.have.property('f', f1); }, "expected Object { f: Function { name: '' } } to have property f of Function { a: 1, name: '' } (got Function { name: '' })"); err(function() { ({a: {b: 1}}).should.have.property('a') .and.have.property('b', 100); }, "expected Object { b: 1 } to have property b of 100 (got 1)"); err(function() { ({a: {b: 1}}).should.have.property('a') .and.have.property('c', 100); }, "expected Object { b: 1 } to have property c"); err(function() { ({a: {b: 1}}).should.have.property('a') .and.have.property('c'); }, "expected Object { b: 1 } to have property c"); }); it('test length(n)', function() { 'test'.should.have.length(4); 'test'.should.have.lengthOf(4); 'test'.should.not.have.length(3); [1, 2, 3].should.have.length(3); ({ length: 10}).should.have.length(10); err(function() { (4).should.have.length(3); }, "expected 4 to have property length"); err(function() { 'asd'.should.not.have.length(3); }, "expected 'asd' not to have property length of 3 (false negative fail)"); }); it('test ownProperty(name)', function() { 'test'.should.have.ownProperty('length'); ({ length: 12 }).should.have.ownProperty('length'); err(function() { ({ length: 12 }).should.not.have.ownProperty('length'); }, "expected Object { length: 12 } not to have own property length (false negative fail)"); err(function() { ({ length: 12 }).should.not.have.ownProperty('length', 'foo'); }, "foo"); err(function() { ({ length: 12 }).should.have.ownProperty('foo', 'foo'); }, "foo"); }); it('test ownProperty(name).equal(val)', function() { ({length: 10}).should.have.ownProperty('length').equal(10); }); it('test properties(name1, name2, ...)', function() { 'test'.should.have.properties('length', 'indexOf'); (4).should.not.have.properties('length'); err(function() { 'asd'.should.have.properties('foo'); }, "expected 'asd' to have property foo"); err(function() { 'asd'.should.not.have.properties('length', 'indexOf'); }, "expected 'asd' not to have properties length, indexOf (false negative fail)"); }); it('test properties([names])', function() { 'test'.should.have.properties(['length', 'indexOf']); (4).should.not.have.properties(['length']); err(function() { 'asd'.should.have.properties(['foo']); }, "expected 'asd' to have property foo"); }); it('test any of properties', function() { 'test'.should.have.any.of.properties('length', 'a', 'b'); 'test'.should.have.any.of.properties('length'); ({ a: 10 }).should.have.any.of.properties('a', 'b'); ({ a: 10 }).should.have.any.of.properties({ a: 10, b: 12 }); ({ a: 10 }).should.not.have.any.of.properties('b', 'c'); ({ a: 10 }).should.have.any.of.properties(['a', 'b']); err(function() { ({ a: 10 }).should.not.have.any.of.properties(['a', 'b']); }, "expected Object { a: 10 } not to have property a (false negative fail)"); err(function() { ({ a: 10, b: 10 }).should.not.have.any.of.properties(['a', 'b']); }, "expected Object { a: 10, b: 10 } not to have any of properties a, b (false negative fail)"); err(function() { ({ a: 10, b: 10 }).should.not.have.any.of.properties({ a: 10, b: 12 }); }, "expected Object { a: 10, b: 10 } not to have property a of 10 (false negative fail)"); err(function() { ({ a: 10, b: 10 }).should.not.have.any.of.properties({ a: 10, b: 10 }); }, "expected Object { a: 10, b: 10 } not to have any of properties a of 10, b of 10 (false negative fail)"); err(function() { ({ a: 11, b: 11 }).should.have.any.of.properties({ a: 10, b: 10 }); }, "expected Object { a: 11, b: 11 } to have any of properties a of 10 (got 11), b of 10 (got 11)"); }); it('test keys(array)', function() { ({ foo: 1 }).should.have.keys(['foo']); ({ foo: 1, bar: 2 }).should.have.keys(['foo', 'bar']); ({ foo: 1, bar: 2 }).should.have.keys('foo', 'bar'); ({}).should.have.keys(); ({}).should.have.keys([]); ({ '1': 'cancelled', '3': 'deleted' }).should.have.keys(1, 3); err(function() { ({ foo: 1 }).should.have.keys(['bar']); }, "expected Object { foo: 1 } to have key bar\n\tmissing keys: bar\n\textra keys: foo"); err(function() { ({ foo: 1 }).should.have.keys(['bar', 'baz']); }, "expected Object { foo: 1 } to have keys bar, baz\n\tmissing keys: bar, baz\n\textra keys: foo"); err(function() { ({ foo: 1 }).should.not.have.keys('foo'); }, "expected Object { foo: 1 } not to have key foo (false negative fail)"); err(function() { ({ foo: 1 }).should.not.have.keys(['foo']); }, "expected Object { foo: 1 } not to have key foo (false negative fail)"); err(function() { ({ foo: 1, bar: 2 }).should.not.have.keys(['foo', 'bar']); }, "expected Object { bar: 2, foo: 1 } not to have keys foo, bar (false negative fail)"); }); it('test empty', function() { ''.should.be.empty(); [].should.be.empty(); ({}).should.be.empty(); ({ length: 10 }).should.not.be.empty(); (function() { arguments.should.be.empty(); })(); err(function() { ({}).should.not.be.empty(); }, 'expected Object {} not to be empty (false negative fail)'); err(function() { ({ length: 10 }).should.be.empty(); }, 'expected Object { length: 10 } to be empty\n expected Object { length: 10 } not to have own property length (false negative fail)'); err(function() { 'asd'.should.be.empty(); }, "expected 'asd' to be empty\n expected 'asd' to have property length of 0 (got 3)"); err(function() { ''.should.not.be.empty(); }, "expected '' not to be empty (false negative fail)"); }); it('should .propertyByPath lookup properties by name path', function() { ({ a: { b: 10}}).should.have.propertyByPath('a', 'b'); ({ '0': { '0': 10}}).should.not.have.propertyByPath(0, 0, 1); ({ a: { b: 10}}).should.have.propertyByPath('a'); ({ a: { b: 10}}).should.not.have.propertyByPath('z'); // true fail err(function() { ({ a: { b: 10}}).should.have.propertyByPath('a', 'b', 'c'); }, "expected Object { a: Object { b: 10 } } to have property by path a, b, c - failed on c\n expected 10 to have property c"); // true fail err(function() { ({ a: { b: 10}}).should.have.propertyByPath('z'); }, "expected Object { a: Object { b: 10 } } to have property by path z - failed on z\n expected Object { a: Object { b: 10 } } to have property z"); // false positive err(function() { ({ a: { b: 10}}).should.not.have.propertyByPath('a', 'b'); }, "expected Object { a: Object { b: 10 } } not to have property by path a, b (false negative fail)"); // false positive err(function() { ({ a: { b: 10}}).should.not.have.propertyByPath('a'); }, "expected Object { a: Object { b: 10 } } not to have property by path a (false negative fail)"); }); }); should.js-8.4.0~dfsg/test/ext/string.test.js000066400000000000000000000022221301217646700211040ustar00rootroot00000000000000var err = require('../util').err; require('../../'); describe('string', function() { it('test startWith()', function() { 'foobar'.should.startWith('foo'); 'foobar'.should.not.startWith('bar'); err(function() { 'foobar'.should.startWith('bar'); }, "expected 'foobar' to start with 'bar'"); err(function() { 'foobar'.should.not.startWith('foo'); }, "expected 'foobar' not to start with 'foo' (false negative fail)"); err(function() { 'foobar'.should.startWith('bar', 'baz'); }, "baz"); err(function() { 'foobar'.should.not.startWith('foo', 'baz'); }, "baz"); }); it('test endWith()', function() { 'foobar'.should.endWith('bar'); 'foobar'.should.not.endWith('foo'); err(function() { 'foobar'.should.endWith('foo'); }, "expected 'foobar' to end with 'foo'"); err(function() { 'foobar'.should.not.endWith('bar'); }, "expected 'foobar' not to end with 'bar' (false negative fail)"); err(function() { 'foobar'.should.endWith('foo', 'baz'); }, "baz"); err(function() { 'foobar'.should.not.endWith('bar', 'baz'); }, "baz"); }); }); should.js-8.4.0~dfsg/test/ext/type.test.js000066400000000000000000000151461301217646700205700ustar00rootroot00000000000000var err = require('../util').err, should = require('../../'); var AssertionError = require('assert').AssertionError; var util = require('util'); describe('type', function() { it('test arguments', function() { var args = (function() { return arguments; })(1,2,3); args.should.be.arguments(); [].should.not.be.arguments(); err(function() { ((function() { return arguments; })(1,2,3)).should.not.be.arguments(); }, "expected Arguments [ 1, 2, 3 ] not to be arguments (false negative fail)"); err(function() { ({}).should.be.arguments(); }, 'expected Object {} to be arguments', ' expected Object {} to have [[Class]] Arguments'); }); it('test typeof', function() { 'test'.should.have.type('string'); err(function() { 'test'.should.not.have.type('string'); }, "expected 'test' not to have type string (false negative fail)"); err(function() { 'test'.should.not.have.type('string', 'foo'); }, "foo"); err(function() { (10).should.have.type('string'); }, "expected 10 to have type string\n expected 'number' to be 'string'"); (5).should.have.type('number'); err(function() { (5).should.not.have.type('number'); }, "expected 5 not to have type number (false negative fail)"); err(function() { (5).should.not.have.type('number', 'foo'); }, "foo"); }); it('test instanceof', function() { function Foo() {} new Foo().should.be.an.instanceof(Foo); new Date().should.be.an.instanceof(Date); var tobi = { name: 'Tobi', age: 2 }; tobi.should.be.an.instanceof(Object); var getSomething = function() {return "something";}; getSomething.should.be.an.instanceof(Function); var number = Object(5); (number instanceof Number).should.be.true(); number.should.be.an.instanceof(Number); var boolean = Object(true); (boolean instanceof Boolean).should.be.true(); boolean.should.be.an.instanceof(Boolean); var string = Object('string'); (string instanceof String).should.be.true(); string.should.be.an.instanceof(String); err(function() { (3).should.an.instanceof(Foo); }, "expected 3 to be an instance of Foo"); err(function() { (3).should.an.instanceof(Foo, 'foo'); }, "foo"); err(function() { ({}).should.not.be.an.instanceof(Object); }, "expected Object {} not to be an instance of Object (false negative fail)"); }); it('test instanceOf (non-reserved)', function() { function Foo() {} new Foo().should.be.an.instanceOf(Foo); new Date().should.be.an.instanceOf(Date); var tobi = { name: 'Tobi', age: 2 }; tobi.should.be.an.instanceOf(Object); var getSomething = function() {return "something";}; getSomething.should.be.an.instanceOf(Function); err(function() { (9).should.an.instanceOf(Foo); }, "expected 9 to be an instance of Foo"); err(function() { (9).should.an.instanceOf(Foo, 'foo'); }, "foo"); function Foo2() {} Foo2.prototype.valueOf = function() { return 'foo'; }; new Foo2().should.be.an.instanceOf(Foo2); }); it('test Function', function() { var f = function() {}; f.should.be.a.Function(); Object.should.be.a.Function(); Function.should.be.a.Function(); (new Function("1 * 1")).should.be.a.Function(); err(function() { (1).should.be.a.Function(); }, "expected 1 to be a function", " expected 1 to have type function", " expected 'number' to be 'function'"); }); it('test Object', function() { ({}).should.be.an.Object(); Function.should.not.be.an.Object(); (new Object()).should.be.an.Object(); (new Date()).should.be.an.Object(); err(function() { (1).should.be.an.Object(); }, 'expected 1 to be an object', ' expected 1 to have type object', ' expected \'number\' to be \'object\''); }); it('test String', function() { ''.should.be.a.String; ({}).should.not.be.a.String; (0).should.not.be.a.String; (new String("")).should.be.a.String; //but should(new String("")).not.be.a.String; err(function() { (1).should.be.a.String(); }, 'expected 1 to be a string', ' expected 1 to have type string', ' expected \'number\' to be \'string\''); }); it('test Array', function() { [].should.be.an.Array(); (new Array(10)).should.be.an.Array(); ''.should.not.be.Array(); (1).should.not.be.Array(); err(function() { [].should.not.be.Array(); }, 'expected Array [] not to be an array (false negative fail)'); }); it('test Number', function() { (1).should.be.a.Number(); (new Number(10)).should.be.a.Number(); //but should(new Number(10)).should.not.be.a.Number(); NaN.should.be.a.Number(); Infinity.should.be.a.Number(); ({}).should.not.be.a.Number(); err(function() { ([]).should.be.a.Number(); }, 'expected Array [] to be a number', ' expected Array [] to have type number', ' expected \'object\' to be \'number\''); }); it('test Boolean', function() { (true).should.be.a.Boolean(); (false).should.be.a.Boolean(); (new Boolean(false)).should.be.a.Boolean(); //but should(new Boolean(false)).should.not.be.a.Boolean(); ({}).should.not.be.a.Boolean(); err(function() { [].should.be.a.Boolean(); }, "expected Array [] to be a boolean", " expected Array [] to have type boolean", " expected 'object' to be 'boolean'"); }); it('test Error', function() { (new Error()).should.be.an.Error(); ({}).should.not.be.Error(); var ae = new AssertionError({ actual: 10, operator: 'to fail' }); ae.should.be.an.Error(); var AsyncTimeoutError = function AsyncTimeoutError(msg) { msg && (this.message = msg); Error.apply(this, arguments); Error.captureStackTrace && Error.captureStackTrace(this, AsyncTimeoutError); }; util.inherits(AsyncTimeoutError, Error); AsyncTimeoutError.prototype.name = AsyncTimeoutError.name; var e = new AsyncTimeoutError('foo'); e.should.be.an.Error(); err(function() { ([]).should.be.an.Error(); }, 'expected Array [] to be an error', ' expected Array [] to be an instance of Error'); }); it('test Date', function() { (new Date()).should.be.a.Date(); (new Date(Date.now())).should.be.a.Date(); (new Date('foo')).should.be.a.Date(); ('foo').should.not.be.a.Date(); err(function() { ([]).should.be.a.Date(); }, 'expected Array [] to be a date', ' expected Array [] to be an instance of Date'); }); }); should.js-8.4.0~dfsg/test/nested.test.js000066400000000000000000000013631301217646700202650ustar00rootroot00000000000000var should = require('../'); var util = require('./util'); should.Assertion.add('_10', function() { this.params = {operator: 'to be a number 10'}; this.is.Number().and.equal(10); }, true); it('should throw when used last managed context', function() { util.err(function() { (11).should.be._10(); }, 'expected 11 to be a number 10\n expected 11 to be 10'); util.err(function() { ({}).should.be._10(); }, 'expected Object {} to be a number 10', ' expected Object {} to be a number', ' expected Object {} to have type number', ' expected \'object\' to be \'number\''); util.err(function() { (10).should.not.be._10(); }, 'expected 10 not to be a number 10 (false negative fail)'); }); should.js-8.4.0~dfsg/test/perf.test.js000066400000000000000000000007241301217646700177370ustar00rootroot00000000000000require('../'); function mockComplexObject(prefix, depth, width) { if (depth <= 0) { return 'value-' + prefix; } var obj = {}; for (var i = 0; i < width; i++) { obj[prefix + depth + '_' + i] = mockComplexObject(prefix, depth-1, width); } return obj; } var a = mockComplexObject('a', 8, 4); var b = mockComplexObject('b', 8, 4); it('should optimize not.equal for complex objects', function() { a.should.be.not.equal(b); // It takes a while }); should.js-8.4.0~dfsg/test/should.test.js000066400000000000000000000013651301217646700203030ustar00rootroot00000000000000 /** * Module dependencies. */ var should = require('../'); var assert = require('assert'); describe('should', function() { it('test assertion', function() { 'test'.should.be.a.String; should.equal('foo', 'foo'); }); it('test .expected and .actual', function() { try { 'foo'.should.equal('bar'); } catch (err) { assert('foo' == err.actual, 'err.actual'); assert('bar' == err.expected, 'err.expected'); } }); it('test chaining', function() { var user = { name: 'tj', pets: ['tobi', 'loki', 'jane', 'bandit'] }; user.should.be.an.instanceOf(Object).and.have.property('name', 'tj'); user.should.have.ownProperty('name') .which.not.have.length(3) .and.be.equal('tj'); }); }); should.js-8.4.0~dfsg/test/util.js000066400000000000000000000013321301217646700167760ustar00rootroot00000000000000var should = require('../'); function err(fn, msg) { if (arguments.length > 2) { msg = Array.prototype.slice.call(arguments, 1).join('\n'); } var ok = true; try { fn(); ok = false; } catch (err) { if ((typeof msg == 'string' && err.message !== msg) || (msg instanceof RegExp && !msg.test(err.message))) { throw new should.AssertionError({ message: [ 'Expected message does not match', 'expected: ' + should.format(msg), ' actual: ' + should.format(err.message) ].join('\n'), expected: msg, actual: err.message, stackStartFunction: err }); } } if (!ok) throw new Error('expected an error'); } exports.err = err;