diff --git a/.gitignore b/.gitignore index 8ccfe3e..db29198 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,8 @@ /node_modules # Tooling stuff -npm-debug.log -.eslintcache +/npm-debug.log +/.eslintcache + +# Generated stuff +/assert.d.ts diff --git a/.npmignore b/.npmignore index 030f9c8..0fef952 100644 --- a/.npmignore +++ b/.npmignore @@ -1,6 +1,5 @@ # General dev crap /appveyor.yml -/bench /coffeelint.json /fixtures /karma.conf.js @@ -16,3 +15,6 @@ # Any incomplete, in-progress feature goes here. /r/dom.js /r/dom.d.ts + +# Specific exclusion because it's used for post-install. +!/scripts/update-clean-assert.js diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 215ba96..a89295f 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -83,8 +83,6 @@ Note that I don't actually test the documentation's code, but please ensure it o - `lib` - The core of this project. Many public API modules are just thin wrappers for something in here, including the main export. -- `lib/assert` - The built-in assertions. Most of these are re-exported under the same name. - - `lib/api` - The core API. Both the primary `t` and `reflect` APIs are defined here. - `lib/core` - The core test state and execution logic. Handle with care, since it's probably the most heavily used. Bugs in this can and often will affect seemingly unrelated tests. Also, the report types are defined here. diff --git a/README.md b/README.md index 048ef65..c0a6cfb 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ tl Couple specific notes: -1. I plan to make this a very batteries-included framework. It includes several useful utilities like an assertion library far more helpful than Node's `assert` (you can define your own ad-hoc assertions, even - I do it in the tests themselves). +1. I plan to make this a very batteries-included framework. It includes several useful utilities like an assertion library far more helpful than Node's `assert` (you can easily define your own ad-hoc assertions, even - I do it in the tests themselves). 2. Not much configuration is required to get started. I aim for ease of use and convention over configuration, but I also try to enable as much flexibility as you need. Your config file can even return a promise, if that's what you need. diff --git a/assert.d.ts b/assert.d.ts deleted file mode 100644 index 3a54643..0000000 --- a/assert.d.ts +++ /dev/null @@ -1,163 +0,0 @@ -/* tslint:disable */ - -export type Key = string | number | symbol; -export type ObjectMap = {[key: string]: T} | {[key: number]: T}; -export function assert(condition: any, message?: string): void; - -export class AssertionError extends Error { - name: "AssertionError"; - message: string; - expected: any; - actual: any; - constructor(message?: string, expected?: any, actual?: any); -} - -export function format(message: string, args: ObjectMap, prettify?: (value: any) => string): string; -export function escape(message: string): string; -export function fail(message: string): void; -export function fail(message: string, args: ObjectMap, prettify?: (value: any) => string): void; - -export function ok(value: any): void; -export function notOk(value: any): void; - -export function isBoolean(object: any): void; -export function notBoolean(object: any): void; - -export function isFunction(object: any): void; -export function notFunction(object: any): void; - -export function isNumber(object: any): void; -export function notNumber(object: any): void; - -export function isObject(object: any): void; -export function notObject(object: any): void; - -export function isString(object: any): void; -export function notString(object: any): void; - -export function isSymbol(object: any): void; -export function notSymbol(object: any): void; - -export function exists(object: any): void; -export function notExists(object: any): void; - -export function isArray(object: any): void; -export function notArray(object: any): void; - -export function is(Type: new (...args: any[]) => any, object: any): void; -export function not(Type: new (...args: any[]) => any, object: any): void; - -export function equal(a: T, b: T): void; -export function notEqual(a: T, b: T): void; - -export function atLeast(n: number, limit: number): void; -export function atMost(n: number, limit: number): void; -export function above(n: number, limit: number): void; -export function below(n: number, limit: number): void; -export function between(n: number, lower: number, upper: number): void; - -export function equalLoose(a: any, b: any): void; -export function notEqualLoose(a: any, b: any): void; - -// Strict deep equality, checking prototypes as well -export function deepEqual(a: T, b: T): void; -export function notDeepEqual(a: T, b: T): void; - -// Purely structural deep equality -export function match(a: T, b: T): void; -export function notMatch(a: T, b: T): void; - -// has own property, possibly equal to a value -export function hasOwn(object: Object, key: Key): void; -export function notHasOwn(object: Object, key: Key): void; - -export function hasOwn(object: Object, key: Key, value: any): void; -export function notHasOwn(object: Object, key: Key, value: any): void; -export function hasOwnLoose(object: Object, key: Key, value: any): void; -export function notHasOwnLoose(object: Object, key: Key, value: any): void; - -// has own or inherited property, possibly equal to a value -export function hasKey(object: Object, key: Key): void; -export function notHasKey(object: Object, key: Key): void; - -export function hasKey(object: Object, key: Key, value: any): void; -export function notHasKey(object: Object, key: Key, value: any): void; -export function hasKeyLoose(object: Object, key: Key, value: any): void; -export function notHasKeyLoose(object: Object, key: Key, value: any): void; - -// has in collection (e.g. Map) -export interface MapLike { - has(value: T): boolean; - get(value: T): U; -} - -export function has(object: MapLike, key: T): void; -export function notHas(object: MapLike, key: T): void; - -export function has(object: MapLike, key: T, value: U): void; -export function notHas(object: MapLike, key: T, value: U): void; -export function hasLoose(object: MapLike, key: T, value: U): void; -export function notHasLoose(object: MapLike, key: T, value: U): void; - -// throws, possibly of a specified type -export function throws(func: () => any): void; -export function throws(Type: new (...args: any[]) => any, func: () => any): void; - -// throws, possibly satisfying a predicate function, having message -// equal to a particular string, or having message that matches a -// regular expression -export type Matcher = ((error: Error) => any) | string | RegExp | {[key: string]: any}; - -export function throwsMatch(matcher: Matcher, func: () => any): void; - -// Note: these two always fail with NaNs, and the delta ignores sign. -export function closeTo(actual: number, expected: number, epsilon?: number): void; -export function notCloseTo(actual: number, expected: number, epsilon?: number): void; - -// includes list of values -// includes all -export function includes(array: T[], values: T | T[]): void; -export function includesDeep(array: T[], values: T | T[]): void; -export function includesMatch(array: T[], values: T | T[]): void; - -// includes some -export function includesAny(array: T[], values: T[]): void; -export function includesDeepAny(array: T[], values: T[]): void; -export function includesMatchAny(array: T[], values: T[]): void; - -// missing some -export function notIncludesAll(array: T[], values: T[]): void; -export function notIncludesDeepAll(array: T[], values: T[]): void; -export function notIncludesMatchAll(array: T[], values: T[]): void; - -// missing all -export function notIncludes(array: T[], values: T[]): void; -export function notIncludesDeep(array: T[], values: T[]): void; -export function notIncludesMatch(array: T[], values: T[]): void; - -// match Object.keys(object) with list of keys -export function hasKeys(object: Object, keys: Key[]): void; -export function notHasKeysAll(object: Object, keys: Key[]): void; -export function hasKeysAny(object: Object, keys: Key[]): void; -export function notHasKeys(object: Object, keys: Key[]): void; - -// match Object.keys(object) with keys -// includes all -export function hasKeys(object: Object, keys: ObjectMap): void; -export function hasKeysMatch(object: Object, keys: ObjectMap): void; -export function hasKeysDeep(object: Object, keys: ObjectMap): void; - -// includes some -export function hasKeysAny(object: Object, keys: ObjectMap): void; -export function hasKeysAnyDeep(object: Object, keys: ObjectMap): void; -export function hasKeysAnyMatch(object: Object, keys: ObjectMap): void; - -// missing some -export function notHasKeysAll(object: Object, keys: ObjectMap): void; -export function notHasKeysAllDeep(object: Object, keys: ObjectMap): void; -export function notHasKeysAllMatch(object: Object, keys: ObjectMap): void; - -// missing all -export function notHasKeys(object: Object, keys: ObjectMap): void; -export function notHasKeysMatch(object: Object, keys: ObjectMap): void; -export function notHasKeysDeep(object: Object, keys: ObjectMap): void; diff --git a/assert.js b/assert.js index 06628b0..2e315fe 100644 --- a/assert.js +++ b/assert.js @@ -1,132 +1,3 @@ "use strict" -/** - * Core TDD-style assertions. These are done by a composition of DSLs, since - * there is *so* much repetition. Also, this is split into several namespaces to - * keep the file size manageable. - */ - -var Util = require("./lib/assert/util") -var Type = require("./lib/assert/type") -var Equal = require("./lib/assert/equal") -var Throws = require("./lib/assert/throws") -var Has = require("./lib/assert/has") -var Includes = require("./lib/assert/includes") -var HasKeys = require("./lib/assert/has-keys") - -exports.AssertionError = Util.AssertionError -exports.assert = Util.assert -exports.fail = Util.fail -exports.format = Util.format -exports.escape = Util.escape - -exports.ok = Type.ok -exports.notOk = Type.notOk -exports.isBoolean = Type.isBoolean -exports.notBoolean = Type.notBoolean -exports.isFunction = Type.isFunction -exports.notFunction = Type.notFunction -exports.isNumber = Type.isNumber -exports.notNumber = Type.notNumber -exports.isObject = Type.isObject -exports.notObject = Type.notObject -exports.isString = Type.isString -exports.notString = Type.notString -exports.isSymbol = Type.isSymbol -exports.notSymbol = Type.notSymbol -exports.exists = Type.exists -exports.notExists = Type.notExists -exports.isArray = Type.isArray -exports.notArray = Type.notArray -exports.is = Type.is -exports.not = Type.not - -exports.equal = Equal.equal -exports.notEqual = Equal.notEqual -exports.equalLoose = Equal.equalLoose -exports.notEqualLoose = Equal.notEqualLoose -exports.deepEqual = Equal.deepEqual -exports.notDeepEqual = Equal.notDeepEqual -exports.match = Equal.match -exports.notMatch = Equal.notMatch -exports.atLeast = Equal.atLeast -exports.atMost = Equal.atMost -exports.above = Equal.above -exports.below = Equal.below -exports.between = Equal.between -exports.closeTo = Equal.closeTo -exports.notCloseTo = Equal.notCloseTo - -exports.throws = Throws.throws -exports.throwsMatch = Throws.throwsMatch - -exports.hasOwn = Has.hasOwn -exports.notHasOwn = Has.notHasOwn -exports.hasOwnLoose = Has.hasOwnLoose -exports.notHasOwnLoose = Has.notHasOwnLoose -exports.hasKey = Has.hasKey -exports.notHasKey = Has.notHasKey -exports.hasKeyLoose = Has.hasKeyLoose -exports.notHasKeyLoose = Has.notHasKeyLoose -exports.has = Has.has -exports.notHas = Has.notHas -exports.hasLoose = Has.hasLoose -exports.notHasLoose = Has.notHasLoose - -/** - * There's 2 sets of 12 permutations here for `includes` and `hasKeys`, instead - * of N sets of 2 (which would fit the `foo`/`notFoo` idiom better), so it's - * easier to just make a couple separate DSLs and use that to define everything. - * - * Here's the top level: - * - * - shallow - * - strict deep - * - structural deep - * - * And the second level: - * - * - includes all/not missing some - * - includes some/not missing all - * - not including all/missing some - * - not including some/missing all - * - * Here's an example using the naming scheme for `hasKeys*` - * - * | shallow | strict deep | structural deep - * --------------|-----------------|---------------------|---------------------- - * includes all | `hasKeys` | `hasKeysDeep` | `hasKeysMatch` - * includes some | `hasKeysAny` | `hasKeysAnyDeep` | `hasKeysAnyMatch` - * missing some | `notHasKeysAll` | `notHasKeysAllDeep` | `notHasKeysAllMatch` - * missing all | `notHasKeys` | `notHasKeysDeep` | `notHasKeysMatch` - * - * Note that the `hasKeys` shallow comparison variants are also overloaded to - * consume either an array (in which it simply checks against a list of keys) or - * an object (where it does a full deep comparison). - */ - -exports.includes = Includes.includes -exports.includesDeep = Includes.includesDeep -exports.includesMatch = Includes.includesMatch -exports.includesAny = Includes.includesAny -exports.includesAnyDeep = Includes.includesAnyDeep -exports.includesAnyMatch = Includes.includesAnyMatch -exports.notIncludesAll = Includes.notIncludesAll -exports.notIncludesAllDeep = Includes.notIncludesAllDeep -exports.notIncludesAllMatch = Includes.notIncludesAllMatch -exports.notIncludes = Includes.notIncludes -exports.notIncludesDeep = Includes.notIncludesDeep -exports.notIncludesMatch = Includes.notIncludesMatch - -exports.hasKeys = HasKeys.hasKeys -exports.hasKeysDeep = HasKeys.hasKeysDeep -exports.hasKeysMatch = HasKeys.hasKeysMatch -exports.hasKeysAny = HasKeys.hasKeysAny -exports.hasKeysAnyDeep = HasKeys.hasKeysAnyDeep -exports.hasKeysAnyMatch = HasKeys.hasKeysAnyMatch -exports.notHasKeysAll = HasKeys.notHasKeysAll -exports.notHasKeysAllDeep = HasKeys.notHasKeysAllDeep -exports.notHasKeysAllMatch = HasKeys.notHasKeysAllMatch -exports.notHasKeys = HasKeys.notHasKeys -exports.notHasKeysDeep = HasKeys.notHasKeysDeep -exports.notHasKeysMatch = HasKeys.notHasKeysMatch +module.exports = require("clean-assert") diff --git a/docs/README.md b/docs/README.md index e65e23b..99d448a 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,12 +1,10 @@ # Documentation -This is the Thallium documentation. It's still a work in progress, as there's a -lot left to do in this framework. +This is the Thallium documentation. It's still a work in progress, as there's a lot left to do in this framework. -- [Getting Started](http://github.com/isiahmeadows/thallium/blob/master/docs/getting-started.md) -- [API](http://github.com/isiahmeadows/thallium/blob/master/docs/api.md) -- [Reporters](http://github.com/isiahmeadows/thallium/blob/master/docs/reporters.md) -- [Core assertions](http://github.com/isiahmeadows/thallium/blob/master/docs/assertions.md) -- [Command Line Runner](http://github.com/isiahmeadows/thallium/blob/master/docs/cli.md) -- [Plugins](http://github.com/isiahmeadows/thallium/blob/master/docs/plugins.md) -- [Examples](http://github.com/isiahmeadows/thallium/tree/master/docs/examples) +- [Getting Started](./getting-started.md) +- [API](./api.md) +- [Reporters](./reporters.md) +- [Command Line Runner](./cli.md) +- [Plugins](./plugins.md) +- [Examples](./examples) diff --git a/docs/api.md b/docs/api.md index 7bda20d..475a04d 100644 --- a/docs/api.md +++ b/docs/api.md @@ -4,8 +4,8 @@ This has a very straightforward, intuitive core API. If you're new to this, you - [Primary API](./api/thallium.md) - [Reflect API](./api/reflect.md) -- [Assertion API](./api/assert.md) +- [Assertion API using `clean-assert`](https://github.com/isiahmeadows/clean-assert/blob/master/api.md), aliased as `thallium/assert` - [Bundle API](./api/bundle.md) - [Other APIs](./api/other.md) -I would also like to note that if you're importing this using ES6 module syntax (like with Babel or TypeScript), import this as a single default export. +I would also like to note that if you're importing this using ES6 module syntax (like with Babel or TypeScript), import `thallium` as a single default export. diff --git a/docs/api/assert.md b/docs/api/assert.md deleted file mode 100644 index a62d201..0000000 --- a/docs/api/assert.md +++ /dev/null @@ -1,413 +0,0 @@ -# Assertions - -Within `thallium/assert`, the built-in assertion library, there are literally 100 different assertions, as well as a few utility methods. I've separated them all into several groups, so it's a bit easier to parse and look through. - -Do note that you don't have to use these, and matter of fact, any assertion library works with this. You could even use Chai if you wanted to. Consider this a useful built-in assertion library in case you prefer batteries included. - -- [Basic methods/properties](#sec-basic) -- [Utility methods](#sec-utility) -- [Type checking](#sec-type) -- [Equality](#sec-equality) -- [Range checking](#sec-range) -- [Exception checking](#sec-exception) -- [Key checking](#sec-key) -- [Includes in array](#sec-includes) -- [Has key-value pairs in object](#sec-has) - - -## Basic methods/properties - -Just like any assertion library, this has the obligatory basics. - -### assert.assert(condition, message?) - -```js -assert.assert(condition, message="") -``` - -The basic assert method. Most assertion libraries have some variant of this: test a `condition`, and if it's falsy, throw an assertion error with a `message`. - -### assert.fail(message?) - -```js -assert.fail(message="") -``` - -The basic automatic failure method. Most assertion libraries have some variant of this: throw an assertion error with a `message`. - -### class assert.AssertionError - -```js -new assert.AssertionError(message="", expected=undefined, actual=undefined) -``` - -The assertion error constructor used in this assertion library. Don't worry, it's only used here, and the rest of Thallium really doesn't care what assertion library you use, if any. It simply checks for the error's `name` to be `"AssertionError"`, nothing else. - - -## Utility methods - -This also has several utility methods, so you can create your own assertions and still make them just as clean, neat, and native-looking as the built-in ones. No more of this: - -```js -assert(something.isntRight(), "Something isn't right") -// AssertionError: Something isn't right -``` - -Instead, this could look like this, with beautiful error messages to match: - -```js -if (something.isntRight()) { - assert.fail("Something isn't right: expected {expected}, found {actual}", { - expected: good, - actual: bad, - }) -} -// AssertionError: Something isn't right: expected 1, found 2 -``` - -### assert.format(message, args, formatter?) - -```js -assert.format(message, args, prettify=util.inspect) -``` - -Create a formatted message from the template `message`, using `args` to fill it in and `prettify` to pretty-print it to a string. - -### assert.fail(message, args, formatter?) - -```js -assert.fail(message, args, prettify=util.inspect) -``` - -Throw a formatted assertion error, formatted with `assert.format`, and with `args.expected` and `args.actual` being passed directly to the `assert.AssertionError` constructor. - -### assert.escape(string) - -```js -assert.escape(string) -``` - -Escape a string so that `assert.format` returns the raw string instead of "pretty-printing" it (e.g. for function names injected into templates). - - -## Type checking - -There are several type checking-related assertions, engineered for clarity and conciseness. - -### Truthy/falsy with assert.ok and assert.notOk - -```js -assert.ok(value) -assert.notOk(value) -``` - -Assert whether a value is truthy or falsy. - -### Primitive types - -```js -assert.isBoolean(value) -assert.isFunction(value) -assert.isNumber(value) -assert.isObject(value) -assert.isString(value) -assert.isSymbol(value) -assert.notBoolean(value) -assert.notFunction(value) -assert.notNumber(value) -assert.notObject(value) -assert.notString(value) -assert.notSymbol(value) -``` - -Assert with `typeof` whether a value is of a certain primitive type. - -Notes: - -- If you want to test `typeof value === "undefined"`, use `assert.equal(value, null)` instead - having an extra method for just a single primitive value would be redundant. -- `assert.isObject(null)` will fail, even though `typeof null === "object"`. It's working around [one of the language's warts](http://www.2ality.com/2013/10/typeof-null.html) that sadly can't be fixed because [it breaks too many things](http://wiki.ecmascript.org/doku.php?id=harmony:typeof_null). - -### Existence - -```js -assert.exists(value) -assert.notExists(value) -``` - -Assert whether a value exists (i.e. either `null` or `undefined`) - -### Arrays - -```js -assert.isArray(value) -assert.notArray(value) -``` - -Assert whether a value is an array. - -### Instance type - -```js -assert.is(Type, value) -assert.not(Type, value) -``` - -Assert whether a value is `instanceof` an object type. - - -## Equality - -There are also, of course, several equality methods. - -### Primitive equality - -```js -assert.equal(expected, actual) // strict, expected === actual -assert.equalLoose(expected, actual) // loose, expected == actual -assert.notEqual(expected, actual) // strict, expected !== actual -assert.notEqualLoose(expected, actual) // loose, expected != actual -``` - -Assert whether a value equals another value, with strict or loose equality. - -Note: if you're checking floats/decimals for equality, don't use this method, because it will frequently get things wrong. Use `assert.closeTo()` or `assert.notCloseTo()` (below) instead - -### Floating point equality - -```js -assert.closeTo(expected, actual, tolerance=1e-10) -assert.notCloseTo(expected, actual, tolerance=1e-10) -``` - -Assert whether a float/decimal is equal to a certain value, given an optional tolerance (since floats [have a habit](https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html) of [being imprecise](http://softwareengineering.stackexchange.com/a/101170)). This is the preferred way to compare two floats for equality. - -The default tolerance is for convenience - you shouldn't need to specify how precise each time you compare two floats. Also, in case you're wondering, here's how it's checked (stops after the first step that works): - -- If any number is `NaN`, it's not considered close. -- If the tolerance is infinite, it's considered close. -- If they're identical (with `===`), then it's considered close. -- If the tolerance is zero, then it's not considered close. -- If either float is zero, then the other is compared to the tolerance via `|value| < tolerance` -- Otherwise, it's compared to the tolerance via `|expected/actual - 1| < tolerance` - -### Deep equality - -```js -assert.deepEqual(expected, actual) -assert.match(expected, actual) -assert.notDeepEqual(expected, actual) -assert.notMatch(expected, actual) -``` - -Assert whether a value deeply equals another value. `deepEqual` and `notDeepEqual` check the prototypes as well, and use the [`match.strict`](./other.md#match-strict) method internally, but `match` and `notMatch` only check the properties (with a few caveats), and use the [`match.match`](./other.md#match-match) method internally. See the documentation for those two methods if you want more info. - - -## Range checking - -There are several methods to deal with ranges and inequalities. - -```js -assert.atLeast(number, limit) // number >= limit -assert.atMost(number, limit) // number <= limit -assert.above(number, limit) // number > limit -assert.below(number, limit) // number < limit -assert.between(number, lower, upper) // lower <= number <= upper -``` - -Assert that a number is within some set of bounds. The comments detail what comparison is checked. Note that `between` is inclusive on both ends, and could be considered shorthand for the following: - -```js -assert.between(number, lower, upper) // lower <= number <= upper -assert.atLeast(number, lower) // number >= limit -assert.atMost(number, upper) // number <= limit -``` - - -## Exception checking - -There are a few methods to deal with exceptions. - -```js -assert.throws(callback) -assert.throws(Type, callback) -assert.throwsMatch(matcher, callback) -``` - -Assert that a callback throws, optionally either `instanceof Type` (for the first form) or matching a `matcher` (for the second form). In the case of the second, the `matcher` can be any of these: - -- A string, which the error's message is checked to equal -- A regular expression, which the error's message is checked to match -- A function, which receives the error and has its result checked to be truthy -- An object literal, which those properties (not necessarily own) of the error are checked to be equal - - -## Key checking - -There are several key checking methods, for own object keys, inherited object keys, and map keys. - -### Own keys - -```js -assert.hasOwn(object, key) -assert.notHasOwn(object, key) -``` - -Assert whether an object has an own key. - -```js -assert.hasOwn(object, key, value) -assert.hasOwnLoose(object, key, value) -assert.notHasOwn(object, key, value) -assert.notHasOwnLoose(object, key, value) -``` - -Assert whether an object has an own key either strictly (`===`/`!==`) or loosely (`==`/`!=`) equal to a value. - -### Own or inherited keys - -```js -assert.hasKey(object, key) -assert.notHasKey(object, key) -``` - -Assert whether an object has an own or inherited key. This even includes `Object.prototype` methods like `toString` for most objects. - -```js -assert.hasKey(object, key, value) -assert.hasKeyLoose(object, key, value) -assert.notHasKey(object, key, value) -assert.notHasKeyLoose(object, key, value) -``` - -Assert whether an object has an own or inherited key either strictly (`===`/`!==`) or loosely (`==`/`!=`) equal to a value. - -### Map keys - -```js -assert.has(object, key) -assert.notHas(object, key) -``` - -Assert whether a [map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) has a key. - -```js -assert.has(object, key, value) -assert.hasLoose(object, key, value) -assert.notHas(object, key, value) -assert.notHasLoose(object, key, value) -``` - -Assert whether a [map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) has a key either strictly (`===`/`!==`) or loosely (`==`/`!=`) equal to a value. - - -## Includes in array - -There's also some larger methods to test many possibilities at once. - -### Includes all values - -```js -// Single -assert.includes(array, value) -assert.includesDeep(array, value) -assert.includesMatch(array, value) - -// Multiple -assert.includes(array, [...values]) -assert.includesDeep(array, [...values]) -assert.includesMatch(array, [...values]) -``` - -Assert an array includes one or more values. - -### Includes some values - -```js -assert.includesAny(array, [...values]) -assert.includesAnyDeep(array, [...values]) -assert.includesAnyMatch(array, [...values]) -``` - -Assert an array includes at least one of a list of values - -### Missing some values - -```js -assert.notIncludesAll(array, [...values]) -assert.notIncludesAllDeep(array, [...values]) -assert.notIncludesAllMatch(array, [...values]) -``` - -Assert an array is missing at least one of a list of values - -### Missing all values - -```js -// Single -assert.notIncludes(array, value) -assert.notIncludesDeep(array, value) -assert.notIncludesMatch(array, value) - -// Multiple -assert.notIncludes(array, [...values]) -assert.notIncludesDeep(array, [...values]) -assert.notIncludesMatch(array, [...values]) -``` - -Assert an array does not include one or more values. - - -## Has key-value pairs in object - -Just like testing for multiple values in arrays, you can also test for multiple key-value pairs in objects. These are checked to be own properties, not inherited, and it can be considered a more flexible shorthand for multiple `assert.hasOwn` calls. - -### Has keys - -```js -assert.hasKeys(object, [...keys]) // includes all -assert.hasKeysAny(object, [...keys]) // includes some -assert.notHasKeysAll(object, [...keys]) // missing some -assert.notHasKeys(object, [...keys]) // missing all -``` - -Assert whether an array has one or more keys. The comments detail how they're checked. - -### Has all key-value pairs - -```js -assert.hasKeys(object, {key: value, ...}) -assert.hasKeysDeep(object, {key: value, ...}) -assert.hasKeysMatch(object, {key: value, ...}) -``` - -Assert an array includes one or more values. - -### Has some key-value pairs - -```js -assert.hasKeysAny(object, {key: value, ...}) -assert.hasKeysAnyDeep(object, {key: value, ...}) -assert.hasKeysAnyMatch(object, {key: value, ...}) -``` - -Assert an array includes at least one of a list of values - -### Missing some key-value pairs - -```js -assert.notHasKeysAll(object, {key: value, ...}) -assert.notHasKeysAllDeep(object, {key: value, ...}) -assert.notHasKeysAllMatch(object, {key: value, ...}) -``` - -Assert an array is missing at least one of a list of values - -### Missing all key-value pairs - -```js -assert.notHasKeys(object, {key: value, ...}) -assert.notHasKeysDeep(object, {key: value, ...}) -assert.notHasKeysMatch(object, {key: value, ...}) -``` - -Assert an array does not include one or more values. diff --git a/docs/api/bundle.md b/docs/api/bundle.md index 71c55b1..f602157 100644 --- a/docs/api/bundle.md +++ b/docs/api/bundle.md @@ -61,7 +61,7 @@ t.use(function (t) { ## API Details - `tl.t` - The primary API, from `require("thallium")`. -- `tl.assert` - The assertions namespace, from `require("thallium/assert")`. +- `tl.assert` - The assertions namespace, from `require("clean-assert")`. - `tl.r` - Each of the reporters live here. You can find more details on these [here](../reporters.md). - `tl.r.dot` - The dot reporter, same as `require("thallium/r/dot")`. - `tl.r.spec` - The spec reporter, same as `require("thallium/r/spec")`. diff --git a/docs/api/thallium.md b/docs/api/thallium.md index 6d47c00..65dd734 100644 --- a/docs/api/thallium.md +++ b/docs/api/thallium.md @@ -26,7 +26,7 @@ The basic test definition method, used for defining block tests. Should be famil ```js // JavaScript t.test("1 should equal 1", () => { - assert..equal(1, 1) + assert.equal(1, 1) }) ``` diff --git a/lib/assert/equal.js b/lib/assert/equal.js deleted file mode 100644 index fdbc801..0000000 --- a/lib/assert/equal.js +++ /dev/null @@ -1,156 +0,0 @@ -"use strict" - -var match = require("clean-match") -var Util = require("./util") - -function binary(numeric, comparator, message) { - return function (actual, expected) { - if (numeric) { - if (typeof actual !== "number") { - throw new TypeError("`actual` must be a number") - } - - if (typeof expected !== "number") { - throw new TypeError("`expected` must be a number") - } - } - - if (!comparator(actual, expected)) { - Util.fail(message, {actual: actual, expected: expected}) - } - } -} - -exports.equal = binary(false, - function (a, b) { return Util.strictIs(a, b) }, - "Expected {actual} to equal {expected}") - -exports.notEqual = binary(false, - function (a, b) { return !Util.strictIs(a, b) }, - "Expected {actual} to not equal {expected}") - -exports.equalLoose = binary(false, - function (a, b) { return Util.looseIs(a, b) }, - "Expected {actual} to loosely equal {expected}") - -exports.notEqualLoose = binary(false, - function (a, b) { return !Util.looseIs(a, b) }, - "Expected {actual} to not loosely equal {expected}") - -exports.atLeast = binary(true, - function (a, b) { return a >= b }, - "Expected {actual} to be at least {expected}") - -exports.atMost = binary(true, - function (a, b) { return a <= b }, - "Expected {actual} to be at most {expected}") - -exports.above = binary(true, - function (a, b) { return a > b }, - "Expected {actual} to be above {expected}") - -exports.below = binary(true, - function (a, b) { return a < b }, - "Expected {actual} to be below {expected}") - -exports.between = function (actual, lower, upper) { - if (typeof actual !== "number") { - throw new TypeError("`actual` must be a number") - } - - if (typeof lower !== "number") { - throw new TypeError("`lower` must be a number") - } - - if (typeof upper !== "number") { - throw new TypeError("`upper` must be a number") - } - - // The negation is to address NaNs as well, without writing a ton of special - // case boilerplate - if (!(actual >= lower && actual <= upper)) { - Util.fail("Expected {actual} to be between {lower} and {upper}", { - actual: actual, - lower: lower, - upper: upper, - }) - } -} - -exports.deepEqual = binary(false, - function (a, b) { return match.strict(a, b) }, - "Expected {actual} to deeply equal {expected}") - -exports.notDeepEqual = binary(false, - function (a, b) { return !match.strict(a, b) }, - "Expected {actual} to not deeply equal {expected}") - -exports.match = binary(false, - function (a, b) { return match.loose(a, b) }, - "Expected {actual} to match {expected}") - -exports.notMatch = binary(false, - function (a, b) { return !match.loose(a, b) }, - "Expected {actual} to not match {expected}") - -// Uses division to allow for a more robust comparison of floats. Also, this -// handles near-zero comparisons correctly, as well as a zero tolerance (i.e. -// exact comparison). -function closeTo(expected, actual, tolerance) { - if (tolerance === Infinity || actual === expected) return true - if (tolerance === 0) return false - if (actual === 0) return Math.abs(expected) < tolerance - if (expected === 0) return Math.abs(actual) < tolerance - return Math.abs(expected / actual - 1) < tolerance -} - -// Note: these two always fail when dealing with NaNs. -exports.closeTo = function (expected, actual, tolerance) { - if (typeof actual !== "number") { - throw new TypeError("`actual` must be a number") - } - - if (typeof expected !== "number") { - throw new TypeError("`expected` must be a number") - } - - if (tolerance == null) tolerance = 1e-10 - - if (typeof tolerance !== "number" || tolerance < 0) { - throw new TypeError( - "`tolerance` must be a non-negative number if given") - } - - if (actual !== actual || expected !== expected || // eslint-disable-line no-self-compare, max-len - !closeTo(expected, actual, tolerance)) { - Util.fail("Expected {actual} to be close to {expected}", { - actual: actual, - expected: expected, - }) - } -} - -exports.notCloseTo = function (expected, actual, tolerance) { - if (typeof actual !== "number") { - throw new TypeError("`actual` must be a number") - } - - if (typeof expected !== "number") { - throw new TypeError("`expected` must be a number") - } - - if (tolerance == null) tolerance = 1e-10 - - if (typeof tolerance !== "number" || tolerance < 0) { - throw new TypeError( - "`tolerance` must be a non-negative number if given") - } - - if (expected !== expected || actual !== actual || // eslint-disable-line no-self-compare, max-len - closeTo(expected, actual, tolerance)) { - Util.fail("Expected {actual} to not be close to {expected}", { - actual: actual, - expected: expected, - }) - } -} diff --git a/lib/assert/has-keys.js b/lib/assert/has-keys.js deleted file mode 100644 index 60a971a..0000000 --- a/lib/assert/has-keys.js +++ /dev/null @@ -1,85 +0,0 @@ -"use strict" - -var match = require("clean-match") -var Util = require("./util") -var hasOwn = Object.prototype.hasOwnProperty - -function hasKeys(all, object, keys) { - for (var i = 0; i < keys.length; i++) { - var test = hasOwn.call(object, keys[i]) - - if (test !== all) return !all - } - - return all -} - -function hasValues(func, all, object, keys) { - if (object === keys) return true - var list = Object.keys(keys) - - for (var i = 0; i < list.length; i++) { - var key = list[i] - var test = hasOwn.call(object, key) && func(keys[key], object[key]) - - if (test !== all) return test - } - - return all -} - -function makeHasOverload(all, invert, message) { - return function (object, keys) { - if (typeof object !== "object" || object == null) { - throw new TypeError("`object` must be an object") - } - - if (typeof keys !== "object" || keys == null) { - throw new TypeError("`keys` must be an object or array") - } - - if (Array.isArray(keys)) { - if (keys.length && hasKeys(all, object, keys) === invert) { - Util.fail(message, {actual: object, keys: keys}) - } - } else if (Object.keys(keys).length) { - if (hasValues(Util.strictIs, all, object, keys) === invert) { - Util.fail(message, {actual: object, keys: keys}) - } - } - } -} - -function makeHasKeys(func, all, invert, message) { - return function (object, keys) { - if (typeof object !== "object" || object == null) { - throw new TypeError("`object` must be an object") - } - - if (typeof keys !== "object" || keys == null) { - throw new TypeError("`keys` must be an object") - } - - // exclusive or to invert the result if `invert` is true - if (Object.keys(keys).length) { - if (hasValues(func, all, object, keys) === invert) { - Util.fail(message, {actual: object, keys: keys}) - } - } - } -} - -/* eslint-disable max-len */ - -exports.hasKeys = makeHasOverload(true, false, "Expected {actual} to have all keys in {keys}") -exports.hasKeysDeep = makeHasKeys(match.strict, true, false, "Expected {actual} to have all keys in {keys}") -exports.hasKeysMatch = makeHasKeys(match.loose, true, false, "Expected {actual} to match all keys in {keys}") -exports.hasKeysAny = makeHasOverload(false, false, "Expected {actual} to have any key in {keys}") -exports.hasKeysAnyDeep = makeHasKeys(match.strict, false, false, "Expected {actual} to have any key in {keys}") -exports.hasKeysAnyMatch = makeHasKeys(match.loose, false, false, "Expected {actual} to match any key in {keys}") -exports.notHasKeysAll = makeHasOverload(true, true, "Expected {actual} to not have all keys in {keys}") -exports.notHasKeysAllDeep = makeHasKeys(match.strict, true, true, "Expected {actual} to not have all keys in {keys}") -exports.notHasKeysAllMatch = makeHasKeys(match.loose, true, true, "Expected {actual} to not match all keys in {keys}") -exports.notHasKeys = makeHasOverload(false, true, "Expected {actual} to not have any key in {keys}") -exports.notHasKeysDeep = makeHasKeys(match.strict, false, true, "Expected {actual} to not have any key in {keys}") -exports.notHasKeysMatch = makeHasKeys(match.loose, false, true, "Expected {actual} to not match any key in {keys}") diff --git a/lib/assert/has.js b/lib/assert/has.js deleted file mode 100644 index 36b3725..0000000 --- a/lib/assert/has.js +++ /dev/null @@ -1,122 +0,0 @@ -"use strict" - -var Util = require("./util") -var hasOwn = Object.prototype.hasOwnProperty - -function has(_) { // eslint-disable-line max-len, max-params - return function (object, key, value) { - if (arguments.length >= 3) { - if (!_.has(object, key) || - !Util.strictIs(_.get(object, key), value)) { - Util.fail(_.messages[0], { - expected: value, - actual: object[key], - key: key, - object: object, - }) - } - } else if (!_.has(object, key)) { - Util.fail(_.messages[1], { - expected: value, - actual: object[key], - key: key, - object: object, - }) - } - } -} - -function hasLoose(_) { - return function (object, key, value) { - if (!_.has(object, key) || !Util.looseIs(_.get(object, key), value)) { - Util.fail(_.messages[0], { - expected: value, - actual: object[key], - key: key, - object: object, - }) - } - } -} - -function notHas(_) { // eslint-disable-line max-len, max-params - return function (object, key, value) { - if (arguments.length >= 3) { - if (_.has(object, key) && - Util.strictIs(_.get(object, key), value)) { - Util.fail(_.messages[2], { - expected: value, - actual: object[key], - key: key, - object: object, - }) - } - } else if (_.has(object, key)) { - Util.fail(_.messages[3], { - expected: value, - actual: object[key], - key: key, - object: object, - }) - } - } -} - -function notHasLoose(_) { // eslint-disable-line max-len, max-params - return function (object, key, value) { - if (_.has(object, key) && Util.looseIs(_.get(object, key), value)) { - Util.fail(_.messages[2], { - expected: value, - actual: object[key], - key: key, - object: object, - }) - } - } -} - -function hasOwnKey(object, key) { return hasOwn.call(object, key) } -function hasInKey(object, key) { return key in object } -function hasInColl(object, key) { return object.has(key) } -function hasObjectGet(object, key) { return object[key] } -function hasCollGet(object, key) { return object.get(key) } - -function createHas(has, get, messages) { - return {has: has, get: get, messages: messages} -} - -var hasOwnMethods = createHas(hasOwnKey, hasObjectGet, [ - "Expected {object} to have own key {key} equal to {expected}, but found {actual}", // eslint-disable-line max-len - "Expected {actual} to have own key {expected}", - "Expected {object} to not have own key {key} equal to {actual}", - "Expected {actual} to not have own key {expected}", -]) - -var hasKeyMethods = createHas(hasInKey, hasObjectGet, [ - "Expected {object} to have key {key} equal to {expected}, but found {actual}", // eslint-disable-line max-len - "Expected {actual} to have key {expected}", - "Expected {object} to not have key {key} equal to {actual}", - "Expected {actual} to not have key {expected}", -]) - -var hasMethods = createHas(hasInColl, hasCollGet, [ - "Expected {object} to have key {key} equal to {expected}, but found {actual}", // eslint-disable-line max-len - "Expected {actual} to have key {expected}", - "Expected {object} to not have key {key} equal to {actual}", - "Expected {actual} to not have key {expected}", -]) - -exports.hasOwn = has(hasOwnMethods) -exports.notHasOwn = notHas(hasOwnMethods) -exports.hasOwnLoose = hasLoose(hasOwnMethods) -exports.notHasOwnLoose = notHasLoose(hasOwnMethods) - -exports.hasKey = has(hasKeyMethods) -exports.notHasKey = notHas(hasKeyMethods) -exports.hasKeyLoose = hasLoose(hasKeyMethods) -exports.notHasKeyLoose = notHasLoose(hasKeyMethods) - -exports.has = has(hasMethods) -exports.notHas = notHas(hasMethods) -exports.hasLoose = hasLoose(hasMethods) -exports.notHasLoose = notHasLoose(hasMethods) diff --git a/lib/assert/includes.js b/lib/assert/includes.js deleted file mode 100644 index bd0f33f..0000000 --- a/lib/assert/includes.js +++ /dev/null @@ -1,56 +0,0 @@ -"use strict" - -var match = require("clean-match") -var Util = require("./util") - -function includes(func, all, array, values) { - // Cheap cases first - if (!Array.isArray(array)) return false - if (array === values) return true - if (all && array.length < values.length) return false - - for (var i = 0; i < values.length; i++) { - var value = values[i] - var test = false - - for (var j = 0; j < array.length; j++) { - if (func(value, array[j])) { - test = true - break - } - } - - if (test !== all) return test - } - - return all -} - -function defineIncludes(func, all, invert, message) { - return function (array, values) { - if (!Array.isArray(array)) { - throw new TypeError("`array` must be an array") - } - - if (!Array.isArray(values)) values = [values] - - if (values.length && includes(func, all, array, values) === invert) { - Util.fail(message, {actual: array, values: values}) - } - } -} - -/* eslint-disable max-len */ - -exports.includes = defineIncludes(Util.strictIs, true, false, "Expected {actual} to have all values in {values}") -exports.includesDeep = defineIncludes(match.strict, true, false, "Expected {actual} to match all values in {values}") -exports.includesMatch = defineIncludes(match.loose, true, false, "Expected {actual} to match all values in {values}") -exports.includesAny = defineIncludes(Util.strictIs, false, false, "Expected {actual} to have any value in {values}") -exports.includesAnyDeep = defineIncludes(match.strict, false, false, "Expected {actual} to match any value in {values}") -exports.includesAnyMatch = defineIncludes(match.loose, false, false, "Expected {actual} to match any value in {values}") -exports.notIncludesAll = defineIncludes(Util.strictIs, true, true, "Expected {actual} to not have all values in {values}") -exports.notIncludesAllDeep = defineIncludes(match.strict, true, true, "Expected {actual} to not match all values in {values}") -exports.notIncludesAllMatch = defineIncludes(match.loose, true, true, "Expected {actual} to not match all values in {values}") -exports.notIncludes = defineIncludes(Util.strictIs, false, true, "Expected {actual} to not have any value in {values}") -exports.notIncludesDeep = defineIncludes(match.strict, false, true, "Expected {actual} to not match any value in {values}") -exports.notIncludesMatch = defineIncludes(match.loose, false, true, "Expected {actual} to not match any value in {values}") diff --git a/lib/assert/throws.js b/lib/assert/throws.js deleted file mode 100644 index 7ebeeba..0000000 --- a/lib/assert/throws.js +++ /dev/null @@ -1,88 +0,0 @@ -"use strict" - -var Util = require("./util") - -function getName(func) { - var name = func.name - - if (name == null) name = func.displayName - if (name) return Util.escape(name) - return "" -} - -exports.throws = function (Type, callback) { - if (callback == null) { - callback = Type - Type = null - } - - if (Type != null && typeof Type !== "function") { - throw new TypeError("`Type` must be a function if passed") - } - - if (typeof callback !== "function") { - throw new TypeError("`callback` must be a function") - } - - try { - callback() // eslint-disable-line callback-return - } catch (e) { - if (Type != null && !(e instanceof Type)) { - Util.fail( - "Expected callback to throw an instance of " + getName(Type) + - ", but found {actual}", - {actual: e}) - } - return - } - - throw new Util.AssertionError("Expected callback to throw") -} - -function throwsMatchTest(matcher, e) { - if (typeof matcher === "string") return e.message === matcher - if (typeof matcher === "function") return !!matcher(e) - if (matcher instanceof RegExp) return !!matcher.test(e.message) - - var keys = Object.keys(matcher) - - for (var i = 0; i < keys.length; i++) { - var key = keys[i] - - if (!(key in e) || !Util.strictIs(matcher[key], e[key])) return false - } - - return true -} - -function isPlainObject(object) { - return object == null || Object.getPrototypeOf(object) === Object.prototype -} - -exports.throwsMatch = function (matcher, callback) { - if (typeof matcher !== "string" && - typeof matcher !== "function" && - !(matcher instanceof RegExp) && - !isPlainObject(matcher)) { - throw new TypeError( - "`matcher` must be a string, function, RegExp, or object") - } - - if (typeof callback !== "function") { - throw new TypeError("`callback` must be a function") - } - - try { - callback() // eslint-disable-line callback-return - } catch (e) { - if (!throwsMatchTest(matcher, e)) { - Util.fail( - "Expected callback to throw an error that matches " + - "{expected}, but found {actual}", - {expected: matcher, actual: e}) - } - return - } - - throw new Util.AssertionError("Expected callback to throw.") -} diff --git a/lib/assert/type.js b/lib/assert/type.js deleted file mode 100644 index 5a205b6..0000000 --- a/lib/assert/type.js +++ /dev/null @@ -1,134 +0,0 @@ -"use strict" - -var fail = require("./util").fail - -exports.ok = function (x) { - if (!x) fail("Expected {actual} to be truthy", {actual: x}) -} - -exports.notOk = function (x) { - if (x) fail("Expected {actual} to be falsy", {actual: x}) -} - -exports.isBoolean = function (x) { - if (typeof x !== "boolean") { - fail("Expected {actual} to be a boolean", {actual: x}) - } -} - -exports.notBoolean = function (x) { - if (typeof x === "boolean") { - fail("Expected {actual} to not be a boolean", {actual: x}) - } -} - -exports.isFunction = function (x) { - if (typeof x !== "function") { - fail("Expected {actual} to be a function", {actual: x}) - } -} - -exports.notFunction = function (x) { - if (typeof x === "function") { - fail("Expected {actual} to not be a function", {actual: x}) - } -} - -exports.isNumber = function (x) { - if (typeof x !== "number") { - fail("Expected {actual} to be a number", {actual: x}) - } -} - -exports.notNumber = function (x) { - if (typeof x === "number") { - fail("Expected {actual} to not be a number", {actual: x}) - } -} - -exports.isObject = function (x) { - if (typeof x !== "object" || x == null) { - fail("Expected {actual} to be an object", {actual: x}) - } -} - -exports.notObject = function (x) { - if (typeof x === "object" && x != null) { - fail("Expected {actual} to not be an object", {actual: x}) - } -} - -exports.isString = function (x) { - if (typeof x !== "string") { - fail("Expected {actual} to be a string", {actual: x}) - } -} - -exports.notString = function (x) { - if (typeof x === "string") { - fail("Expected {actual} to not be a string", {actual: x}) - } -} - -exports.isSymbol = function (x) { - if (typeof x !== "symbol") { - fail("Expected {actual} to be a symbol", {actual: x}) - } -} - -exports.notSymbol = function (x) { - if (typeof x === "symbol") { - fail("Expected {actual} to not be a symbol", {actual: x}) - } -} - -exports.exists = function (x) { - if (x == null) { - fail("Expected {actual} to exist", {actual: x}) - } -} - -exports.notExists = function (x) { - if (x != null) { - fail("Expected {actual} to not exist", {actual: x}) - } -} - -exports.isArray = function (x) { - if (!Array.isArray(x)) { - fail("Expected {actual} to be an array", {actual: x}) - } -} - -exports.notArray = function (x) { - if (Array.isArray(x)) { - fail("Expected {actual} to not be an array", {actual: x}) - } -} - -exports.is = function (Type, object) { - if (typeof Type !== "function") { - throw new TypeError("`Type` must be a function") - } - - if (!(object instanceof Type)) { - fail("Expected {object} to be an instance of {expected}", { - expected: Type, - actual: object.constructor, - object: object, - }) - } -} - -exports.not = function (Type, object) { - if (typeof Type !== "function") { - throw new TypeError("`Type` must be a function") - } - - if (object instanceof Type) { - fail("Expected {object} to not be an instance of {expected}", { - expected: Type, - object: object, - }) - } -} diff --git a/lib/assert/util.js b/lib/assert/util.js deleted file mode 100644 index 9c2f5a7..0000000 --- a/lib/assert/util.js +++ /dev/null @@ -1,125 +0,0 @@ -"use strict" - -var inspect = require("../replaced/inspect") -var getStack = require("../util").getStack -var hasOwn = Object.prototype.hasOwnProperty -var AssertionError - -try { - AssertionError = new Function([ // eslint-disable-line no-new-func - "'use strict';", - "class AssertionError extends Error {", - " constructor(message, expected, actual) {", - " super(message)", - " this.expected = expected", - " this.actual = actual", - " }", - "", - " get name() {", - " return 'AssertionError'", - " }", - "}", - // check native subclassing support - "new AssertionError('message', 1, 2)", - "return AssertionError", - ].join("\n"))() -} catch (e) { - AssertionError = typeof Error.captureStackTrace === "function" - ? function AssertionError(message, expected, actual) { - this.message = message || "" - this.expected = expected - this.actual = actual - Error.captureStackTrace(this, this.constructor) - } - : function AssertionError(message, expected, actual) { - this.message = message || "" - this.expected = expected - this.actual = actual - var e = new Error(message) - - e.name = "AssertionError" - this.stack = getStack(e) - } - - AssertionError.prototype = Object.create(Error.prototype) - - Object.defineProperty(AssertionError.prototype, "constructor", { - configurable: true, - writable: true, - enumerable: false, - value: AssertionError, - }) - - Object.defineProperty(AssertionError.prototype, "name", { - configurable: true, - writable: true, - enumerable: false, - value: "AssertionError", - }) -} - -exports.AssertionError = AssertionError - -/* eslint-disable no-self-compare */ -// For better NaN handling -exports.strictIs = function (a, b) { - return a === b || a !== a && b !== b -} - -exports.looseIs = function (a, b) { - return a == b || a !== a && b !== b // eslint-disable-line eqeqeq -} - -/* eslint-enable no-self-compare */ - -var templateRegexp = /(.?)\{(.+?)\}/g - -exports.escape = function (string) { - if (typeof string !== "string") { - throw new TypeError("`string` must be a string") - } - - return string.replace(templateRegexp, function (m, pre) { - return pre + "\\" + m.slice(1) - }) -} - -// This formats the assertion error messages. -exports.format = function (message, args, prettify) { - if (prettify == null) prettify = inspect - - if (typeof message !== "string") { - throw new TypeError("`message` must be a string") - } - - if (typeof args !== "object" || args === null) { - throw new TypeError("`args` must be an object") - } - - if (typeof prettify !== "function") { - throw new TypeError("`prettify` must be a function if passed") - } - - return message.replace(templateRegexp, function (m, pre, prop) { - if (pre === "\\") { - return m.slice(1) - } else if (hasOwn.call(args, prop)) { - return pre + prettify(args[prop], {depth: 5}) - } else { - return pre + m - } - }) -} - -exports.fail = function (message, args, prettify) { - if (args == null) throw new AssertionError(message) - throw new AssertionError( - exports.format(message, args, prettify), - args.expected, - args.actual) -} - -// The basic assert, like `assert.ok`, but gives you an optional message. -exports.assert = function (test, message) { - if (!test) throw new AssertionError(message) -} diff --git a/lib/replaced/inspect.js b/lib/replaced/inspect.js deleted file mode 100644 index ebc0231..0000000 --- a/lib/replaced/inspect.js +++ /dev/null @@ -1,8 +0,0 @@ -"use strict" - -/** - * This merely exists so that Browserify can replace this method with the right - * module (util-inspect). - */ - -module.exports = require("util").inspect diff --git a/lib/reporter/console-reporter.js b/lib/reporter/console-reporter.js index 0832795..738da39 100644 --- a/lib/reporter/console-reporter.js +++ b/lib/reporter/console-reporter.js @@ -1,7 +1,7 @@ "use strict" var methods = require("../methods") -var inspect = require("../replaced/inspect") +var inspect = require("clean-assert-util").inspect var peach = require("../util").peach var Reporter = require("./reporter") var Util = require("./util") diff --git a/make.js b/make.js index 290ba08..8c4cd53 100644 --- a/make.js +++ b/make.js @@ -131,6 +131,27 @@ task("bundle", function () { ]) }) +task("update", function (args) { + var pkgs = args.filter(function (arg) { return arg[0] !== "-" }) + var saveFlag = "--save-dev" + + args + .filter(function (arg) { return arg[0] === "-" }) + .forEach(function (arg) { + switch (arg) { + case "--release": saveFlag = "--save"; break + case "--raw": saveFlag = ""; break + default: // ignore + } + }) + + exec("npm install " + pkgs.join(" ") + saveFlag) + + if (pkgs.indexOf("clean-assert") >= 0) { + exec("node ./scripts/update-clean-assert.js") + } +}) + task("release", function (args) { var force = false var increment diff --git a/migrate/index.js b/migrate/index.js index 3e2579b..65aed72 100644 --- a/migrate/index.js +++ b/migrate/index.js @@ -16,9 +16,7 @@ var Report = require("../lib/core/reports").Report var Reflect = require("../lib/api/reflect") var Thallium = require("../lib/api/thallium") -var assert = require("../assert") -var AssertionError = assert.AssertionError -var format = assert.format +var assert = require("clean-assert") /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * - `reflect.checkInit()` is deprecated in favor of `reflect.locked` and * @@ -215,9 +213,7 @@ function defineAssertion(test, name, func) { } if (!res.test) { - throw new AssertionError( - format(res.message, res), - res.expected, res.actual) + assert.fail(res.message, res) } } @@ -369,7 +365,7 @@ Object.defineProperty(Reflect.prototype, "AssertionError", { enumerable: false, get: Common.deprecate( "`reflect.AssertionError` is deprecated. Use `assert.AssertionError` from `thallium/assert` instead.", // eslint-disable-line max-len - function () { return lockError(AssertionError) }), + function () { return lockError(assert.AssertionError) }), set: Common.deprecate( "`reflect.AssertionError` is deprecated. Use `assert.AssertionError` from `thallium/assert` instead.", // eslint-disable-line max-len lockError), @@ -386,7 +382,7 @@ methods(Thallium, { /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * - assertions defined on main export * * - `t.*` assertions -> `assert.*` (some renamed) from `thallium/assert` * - * - `t.true`/etc. are gone (except `t.undefined` -> `assert.undefined`) * + * - `t.true`/etc. are gone (except `t.undefined` -> `assert.isUndefined`) * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ Common.hideDeprecation() require("../assertions")(require("../index")) diff --git a/package.json b/package.json index 8f4dbe7..a69d849 100644 --- a/package.json +++ b/package.json @@ -4,12 +4,12 @@ "description": "A simple, unopinionated, modular test framework", "main": "index.js", "scripts": { + "postinstall": "node scripts/update-clean-assert.js || echo Warning: thallium/assert.d.ts is not set up! >&2", "test": "node make" }, "browser": { - "./lib/replaced/inspect.js": "./node_modules/util-inspect/index.js", "./lib/replaced/console.js": "./lib/replaced/console-browser.js", - "jsdom": "./node_modules/empty/object.js" + "jsdom": false }, "bin": { "tl": "bin/tl.js" @@ -23,12 +23,10 @@ "author": "Isiah Meadows ", "license": "ISC", "devDependencies": { - "benchmark": "^2.1.1", "browserify": "^13.0.1", "chokidar": "^1.6.0", "coffee-script": "^1.10.0", "coffeelint": "^1.15.7", - "empty": "^0.10.1", "es6-promise": "^4.0.5", "eslint": "^3.4.0", "eslint-config-isiahmeadows": "^0.1.6", @@ -45,6 +43,8 @@ "watchify": "^3.7.0" }, "dependencies": { + "clean-assert": "^1.0.0", + "clean-assert-util": "^1.0.1", "clean-match": "^1.0.2", "glob": "^7.0.5", "interpret": "1", diff --git a/r/tap.js b/r/tap.js index 7dad7f8..4abc810 100644 --- a/r/tap.js +++ b/r/tap.js @@ -4,7 +4,7 @@ var peach = require("../lib/util").peach var R = require("../lib/reporter") -var inspect = require("../lib/replaced/inspect") +var inspect = require("clean-assert-util").inspect function shouldBreak(minLength, str) { return str.length > R.windowWidth() - minLength || /\r?\n|[:?-]/.test(str) diff --git a/roadmap.md b/roadmap.md index a47c994..351db54 100644 --- a/roadmap.md +++ b/roadmap.md @@ -17,10 +17,10 @@ See the [changelog](https://github.com/isiahmeadows/thallium/blob/master/CHANGEL 3. Create/finish DOM reporter 4. Support flaky tests via first-class retries - This is a requirement to self-host the runner -5. Move ~~`thallium/match`~~ and `thallium/assert` implementations out of core +5. ~~Move `thallium/match` and `thallium/assert` implementations out of core~~ - ~~`thallium/match` is useful on its own~~ - - Third-party assertions should be able to build off the same basic assertion primitives without depending on `thallium` - - The assertions' core primitives are already fairly stable + - ~~Third-party assertions should be able to build off the same basic assertion primitives without depending on `thallium`~~ + - ~~The assertions' core primitives are already fairly stable~~ 6. Add `t.hasReporter()` so the CLI can detect no reporter set and add the appropriate default. ## 0.4.0 diff --git a/scripts/update-clean-assert.js b/scripts/update-clean-assert.js new file mode 100644 index 0000000..63c59aa --- /dev/null +++ b/scripts/update-clean-assert.js @@ -0,0 +1,11 @@ +"use strict" + +// A simple script to set up the `thallium/assert` definition, run on both +// postinstall and `clean-assert` update. + +var fs = require("fs") +var path = require("path") +var file = require.resolve("clean-assert/index.d.ts") +var dest = path.resolve(__dirname, "../assert.d.ts") + +fs.createReadStream(file).pipe(fs.createWriteStream(dest)) diff --git a/test-util/globals.js b/test-util/globals.js index d1ca967..2e5b8a2 100644 --- a/test-util/globals.js +++ b/test-util/globals.js @@ -50,7 +50,6 @@ var Util = global.Util = { methods: require("../lib/methods.js"), R: require("../lib/reporter/index.js"), - inspect: require("../lib/replaced/inspect.js"), /* eslint-enable global-require */ diff --git a/test/assert/assertion-error.js b/test/assert/assertion-error.js deleted file mode 100644 index fd158b8..0000000 --- a/test/assert/assertion-error.js +++ /dev/null @@ -1,41 +0,0 @@ -"use strict" - -describe("core (assertion error)", function () { - var AssertionError = assert.AssertionError - var hasOwn = Object.prototype.hasOwnProperty - - it("is an error", function () { - if (!(new AssertionError() instanceof Error)) { - throw new Error("Expected AssertionError to subclass Error") - } - }) - - function checkValue(e, prop, expected, own) { - if (own && !hasOwn.call(e, prop)) { - throw new Error("Expected error to have own `" + prop + - "` property") - } - - if (e[prop] !== expected) { - throw new Error("Expected e." + prop + " to equal " + - Util.inspect(expected) + ", but found " + - Util.inspect(e[prop])) - } - } - - // Otherwise, this won't work on native subclasses. - function check(name, message, expected, actual) { - it(name, function () { - var e = new AssertionError(message, expected, actual) - - checkValue(e, "message", message) - checkValue(e, "expected", expected, true) - checkValue(e, "actual", actual, true) - }) - } - - check("correctly sets existing properties", "message", 1, 2) - check("correctly sets missing `actual`", "message", 1, undefined) - check("correctly sets missing `expected`", "message", undefined, 2) - check("correctly sets missing `message`", "", 1, 2) -}) diff --git a/test/assert/base.js b/test/assert/base.js deleted file mode 100644 index 9f3f76a..0000000 --- a/test/assert/base.js +++ /dev/null @@ -1,344 +0,0 @@ -"use strict" - -/* global Map, Symbol */ - -describe("assert (base)", function () { - describe("assert()", function () { - it("works", function () { - function fail(arg, message) { - try { - assert.assert(arg, message) - throw new Error("Expected assertion to throw") - } catch (e) { - assert.equal(e.message, message) - } - } - - assert.assert(true) - assert.assert(1) - assert.assert(Infinity) - assert.assert("foo") - assert.assert({}) - assert.assert([]) - assert.assert(new Date()) - if (typeof Symbol === "function") assert.assert(Symbol()) - - fail(undefined, "message") - fail(null, "message") - fail(false, "message") - fail(0, "message") - fail("", "message") - fail(NaN, "message") - }) - - it("escapes the message", function () { - Util.fail("assert", undefined, "{test}") - Util.fail("assert", null, "{test}") - Util.fail("assert", false, "{test}") - Util.fail("assert", 0, "{test}") - Util.fail("assert", "", "{test}") - Util.fail("assert", NaN, "{test}") - }) - }) - - Util.basic("ok()", function () { - assert.ok(true) - assert.ok(1) - assert.ok(Infinity) - assert.ok("foo") - assert.ok({}) - assert.ok([]) - assert.ok(new Date()) - if (typeof Symbol === "function") assert.ok(Symbol()) - - Util.fail("ok") - Util.fail("ok", undefined) - Util.fail("ok", null) - Util.fail("ok", false) - Util.fail("ok", 0) - Util.fail("ok", "") - Util.fail("ok", NaN) - }) - - Util.basic("notOk()", function () { - Util.fail("notOk", true) - Util.fail("notOk", 1) - Util.fail("notOk", Infinity) - Util.fail("notOk", "foo") - Util.fail("notOk", {}) - Util.fail("notOk", []) - Util.fail("notOk", new Date()) - if (typeof Symbol === "function") Util.fail("notOk", Symbol()) - - assert.notOk() - assert.notOk(undefined) - assert.notOk(null) - assert.notOk(false) - assert.notOk(0) - assert.notOk("") - assert.notOk(NaN) - }) - - Util.basic("equal()", function () { - assert.equal(0, 0) - assert.equal(1, 1) - assert.equal(null, null) - assert.equal(undefined, undefined) - assert.equal(Infinity, Infinity) - assert.equal(NaN, NaN) - assert.equal("", "") - assert.equal("foo", "foo") - - var obj = {} - - assert.equal(obj, obj) - - Util.fail("equal", {}, {}) - Util.fail("equal", null, undefined) - Util.fail("equal", 0, 1) - Util.fail("equal", 1, "1") - }) - - Util.basic("notEqual()", function () { - Util.fail("notEqual", 0, 0) - Util.fail("notEqual", 1, 1) - Util.fail("notEqual", null, null) - Util.fail("notEqual", undefined, undefined) - Util.fail("notEqual", Infinity, Infinity) - Util.fail("notEqual", NaN, NaN) - Util.fail("notEqual", "", "") - Util.fail("notEqual", "foo", "foo") - - var obj = {} - - Util.fail("notEqual", obj, obj) - - assert.notEqual({}, {}) - assert.notEqual(null, undefined) - assert.notEqual(0, 1) - assert.notEqual(1, "1") - }) - - Util.basic("equalLoose()", function () { - assert.equalLoose(0, 0) - assert.equalLoose(1, 1) - assert.equalLoose(null, null) - assert.equalLoose(undefined, undefined) - assert.equalLoose(Infinity, Infinity) - assert.equalLoose(NaN, NaN) - assert.equalLoose("", "") - assert.equalLoose("foo", "foo") - assert.equalLoose(null, undefined) - assert.equalLoose(1, "1") - - var obj = {} - - assert.equalLoose(obj, obj) - - Util.fail("equalLoose", {}, {}) - Util.fail("equalLoose", 0, 1) - }) - - Util.basic("notEqualLoose()", function () { - Util.fail("notEqualLoose", 0, 0) - Util.fail("notEqualLoose", 1, 1) - Util.fail("notEqualLoose", null, null) - Util.fail("notEqualLoose", undefined, undefined) - Util.fail("notEqualLoose", Infinity, Infinity) - Util.fail("notEqualLoose", NaN, NaN) - Util.fail("notEqualLoose", "", "") - Util.fail("notEqualLoose", "foo", "foo") - Util.fail("notEqualLoose", null, undefined) - Util.fail("notEqualLoose", 1, "1") - - var obj = {} - - Util.fail("notEqualLoose", obj, obj) - - assert.notEqualLoose({}, {}) - assert.notEqualLoose(0, 1) - }) - - Util.basic("deepEqual()", function () { - assert.deepEqual(0, 0) - assert.deepEqual(1, 1) - assert.deepEqual(null, null) - assert.deepEqual(undefined, undefined) - assert.deepEqual(Infinity, Infinity) - assert.deepEqual(NaN, NaN) - assert.deepEqual("", "") - assert.deepEqual("foo", "foo") - - var obj = {} - - assert.deepEqual(obj, obj) - - assert.deepEqual({}, {}) - Util.fail("deepEqual", null, undefined) - Util.fail("deepEqual", 0, 1) - Util.fail("deepEqual", 1, "1") - - assert.deepEqual( - {a: [2, 3], b: [4]}, - {a: [2, 3], b: [4]}) - }) - - Util.basic("notDeepEqual()", function () { - Util.fail("notDeepEqual", 0, 0) - Util.fail("notDeepEqual", 1, 1) - Util.fail("notDeepEqual", null, null) - Util.fail("notDeepEqual", undefined, undefined) - Util.fail("notDeepEqual", Infinity, Infinity) - Util.fail("notDeepEqual", NaN, NaN) - Util.fail("notDeepEqual", "", "") - Util.fail("notDeepEqual", "foo", "foo") - - var obj = {} - - Util.fail("notDeepEqual", obj, obj) - - Util.fail("notDeepEqual", {}, {}) - assert.notDeepEqual(null, undefined) - assert.notDeepEqual(0, 1) - assert.notDeepEqual(1, "1") - - Util.fail("notDeepEqual", - {a: [2, 3], b: [4]}, - {a: [2, 3], b: [4]}) - }) - - function F() { this.value = 1 } - Util.methods(F, { - get prop() { return 1 }, - }) - - Util.basic("hasOwn()", function () { - assert.hasOwn({prop: 1}, "prop") - assert.hasOwn({prop: 1}, "prop", 1) - assert.hasOwn(new F(), "value", 1) - - Util.fail("hasOwn", {prop: 1}, "toString") - Util.fail("hasOwn", {prop: 1}, "value") - Util.fail("hasOwn", {prop: 1}, "prop", 2) - Util.fail("hasOwn", {prop: 1}, "prop", "1") - Util.fail("hasOwn", new F(), "prop") - Util.fail("hasOwn", new F(), "prop", 1) - Util.fail("hasOwn", new F(), "value", 2) - }) - - Util.basic("notHasOwn()", function () { - Util.fail("notHasOwn", {prop: 1}, "prop") - Util.fail("notHasOwn", {prop: 1}, "prop", 1) - Util.fail("notHasOwn", new F(), "value", 1) - - assert.notHasOwn({prop: 1}, "toString") - assert.notHasOwn({prop: 1}, "value") - assert.notHasOwn({prop: 1}, "prop", 2) - assert.notHasOwn({prop: 1}, "prop", "1") - assert.notHasOwn(new F(), "prop") - assert.notHasOwn(new F(), "prop", 1) - assert.notHasOwn(new F(), "value", 2) - }) - - Util.basic("hasOwnLoose()", function () { - assert.hasOwnLoose({prop: 1}, "prop", 1) - assert.hasOwnLoose(new F(), "value", 1) - assert.hasOwnLoose({prop: 1}, "prop", "1") - - Util.fail("hasOwnLoose", {prop: 1}, "prop", 2) - Util.fail("hasOwnLoose", new F(), "prop", 1) - Util.fail("hasOwnLoose", new F(), "value", 2) - }) - - Util.basic("notHasOwnLoose()", function () { - Util.fail("notHasOwnLoose", {prop: 1}, "prop", 1) - Util.fail("notHasOwnLoose", new F(), "value", 1) - Util.fail("notHasOwnLoose", {prop: 1}, "prop", "1") - - assert.notHasOwnLoose({prop: 1}, "prop", 2) - assert.notHasOwnLoose(new F(), "prop", 1) - assert.notHasOwnLoose(new F(), "value", 2) - }) - - Util.basic("hasKey()", function () { - assert.hasKey({prop: 1}, "prop") - assert.hasKey({prop: 1}, "prop", 1) - assert.hasKey(new F(), "value", 1) - assert.hasKey({prop: 1}, "toString") - assert.hasKey(new F(), "prop") - assert.hasKey(new F(), "prop", 1) - - Util.fail("hasKey", {prop: 1}, "value") - Util.fail("hasKey", {prop: 1}, "prop", 2) - Util.fail("hasKey", {prop: 1}, "prop", "1") - Util.fail("hasKey", new F(), "value", 2) - }) - - Util.basic("notHasKey()", function () { - Util.fail("notHasKey", {prop: 1}, "prop") - Util.fail("notHasKey", {prop: 1}, "prop", 1) - Util.fail("notHasKey", new F(), "value", 1) - Util.fail("notHasKey", {prop: 1}, "toString") - Util.fail("notHasKey", new F(), "prop") - Util.fail("notHasKey", new F(), "prop", 1) - - assert.notHasKey({prop: 1}, "value") - assert.notHasKey({prop: 1}, "prop", 2) - assert.notHasKey({prop: 1}, "prop", "1") - assert.notHasKey(new F(), "value", 2) - }) - - Util.basic("hasKeyLoose()", function () { - assert.hasKeyLoose({prop: 1}, "prop", 1) - assert.hasKeyLoose(new F(), "value", 1) - assert.hasKeyLoose(new F(), "prop", 1) - assert.hasKeyLoose({prop: 1}, "prop", "1") - - Util.fail("hasKeyLoose", {prop: 1}, "prop", 2) - Util.fail("hasKeyLoose", new F(), "value", 2) - }) - - Util.basic("notHasKeyLoose()", function () { - Util.fail("notHasKeyLoose", {prop: 1}, "prop", 1) - Util.fail("notHasKeyLoose", new F(), "value", 1) - Util.fail("notHasKeyLoose", new F(), "prop", 1) - Util.fail("notHasKeyLoose", {prop: 1}, "prop", "1") - - assert.notHasKeyLoose({prop: 1}, "prop", 2) - assert.notHasKeyLoose(new F(), "value", 2) - }) - - if (typeof Map !== "undefined") { - Util.basic("has()", function () { - assert.has(new Map([["prop", 1]]), "prop") - assert.has(new Map([["prop", 1]]), "prop", 1) - - Util.fail("has", new Map([["prop", 1]]), "value") - Util.fail("has", new Map([["prop", 1]]), "prop", 2) - Util.fail("has", new Map([["prop", 1]]), "prop", "1") - }) - - Util.basic("notHas()", function () { - Util.fail("notHas", new Map([["prop", 1]]), "prop") - Util.fail("notHas", new Map([["prop", 1]]), "prop", 1) - - assert.notHas(new Map([["prop", 1]]), "value") - assert.notHas(new Map([["prop", 1]]), "prop", 2) - assert.notHas(new Map([["prop", 1]]), "prop", "1") - }) - - Util.basic("hasLoose()", function () { - assert.hasLoose(new Map([["prop", 1]]), "prop", 1) - assert.hasLoose(new Map([["prop", 1]]), "prop", "1") - - Util.fail("hasLoose", new Map([["prop", 1]]), "prop", 2) - }) - - Util.basic("notHasLoose()", function () { - Util.fail("notHasLoose", new Map([["prop", 1]]), "prop", 1) - Util.fail("notHasLoose", new Map([["prop", 1]]), "prop", "1") - - assert.notHasLoose(new Map([["prop", 1]]), "prop", 2) - }) - } -}) diff --git a/test/assert/computation.js b/test/assert/computation.js deleted file mode 100644 index 8cf50de..0000000 --- a/test/assert/computation.js +++ /dev/null @@ -1,298 +0,0 @@ -"use strict" - -describe("assert (computation)", function () { - var fail = Util.fail - var basic = Util.basic - - describe("throws()", function () { - it("works", function () { - assert.throws(function () { throw new Error("fail") }) - assert.throws(TypeError, function () { throw new TypeError("fail") }) // eslint-disable-line max-len - assert.throws(Error, function () { throw new TypeError("fail") }) - fail("throws", Error, function () {}) - fail("throws", function () {}) - }) - - it("doesn't rethrow non-matching errors", function () { - fail("throws", TypeError, function () { throw new Error("fail") }) - }) - - it("doesn't rethrow non-errors", function () { - /* eslint-disable no-throw-literal */ - - assert.throws(function () { throw undefined }) - assert.throws(function () { throw null }) - assert.throws(function () { throw 1 }) - assert.throws(function () { throw "why" }) - assert.throws(function () { throw true }) - assert.throws(function () { throw [] }) - assert.throws(function () { throw {} }) - - fail("throws", Error, function () { throw undefined }) - fail("throws", Error, function () { throw null }) - fail("throws", Error, function () { throw 1 }) - fail("throws", Error, function () { throw "why" }) - fail("throws", Error, function () { throw true }) - fail("throws", Error, function () { throw [] }) - fail("throws", Error, function () { throw {} }) - - /* eslint-disable no-undef */ - - if (typeof Symbol === "function") { - assert.throws(function () { throw Symbol() }) - fail("throws", Error, function () { throw Symbol() }) - } - - /* eslint-enable no-undef, no-throw-literal */ - }) - }) - - basic("throwsMatch()", function () { - var sentinel = new Error("sentinel") - - function test() { throw sentinel } - function is(e) { return e === sentinel } - function not(e) { return e !== sentinel } - - assert.throwsMatch(is, test) - assert.throwsMatch("sentinel", test) - assert.throwsMatch(/sent/, test) - assert.throwsMatch({message: "sentinel"}, test) - - fail("throwsMatch", not, test) - fail("throwsMatch", not, function () {}) - fail("throwsMatch", "nope", test) - fail("throwsMatch", /hi/, test) - fail("throwsMatch", {message: "nope"}, test) - }) - - describe("atLeast()", function () { - it("works", function () { - assert.atLeast(0, 0) - assert.atLeast(1, 1) - assert.atLeast(1, -1) - assert.atLeast(12398.4639, 1245.472398) - - fail("atLeast", 0, 1000) - fail("atLeast", -1, 1) - fail("atLeast", -1, 0) - }) - - it("works with Infinities", function () { - assert.atLeast(0, -Infinity) - assert.atLeast(-Infinity, -Infinity) - assert.atLeast(Infinity, -Infinity) - assert.atLeast(Infinity, 0) - assert.atLeast(Infinity, Infinity) - - fail("atLeast", -Infinity, Infinity) - fail("atLeast", -Infinity, 0) - }) - - it("fails with NaNs", function () { - fail("atLeast", NaN, 0) - fail("atLeast", 0, NaN) - fail("atLeast", NaN, NaN) - fail("atLeast", NaN, Infinity) - fail("atLeast", Infinity, NaN) - fail("atLeast", NaN, -Infinity) - fail("atLeast", -Infinity, NaN) - }) - }) - - describe("atMost()", function () { - it("works", function () { - assert.atMost(0, 0) - assert.atMost(1, 1) - fail("atMost", 1, -1) - fail("atMost", 12398.4639, 1245.472398) - - assert.atMost(0, 1000) - assert.atMost(-1, 1) - assert.atMost(-1, 0) - }) - - it("works with Infinities", function () { - fail("atMost", 0, -Infinity) - assert.atMost(-Infinity, -Infinity) - fail("atMost", Infinity, -Infinity) - fail("atMost", Infinity, 0) - assert.atMost(Infinity, Infinity) - - assert.atMost(-Infinity, Infinity) - assert.atMost(-Infinity, 0) - }) - - it("fails with NaNs", function () { - fail("atMost", NaN, 0) - fail("atMost", 0, NaN) - fail("atMost", NaN, NaN) - fail("atMost", NaN, Infinity) - fail("atMost", Infinity, NaN) - fail("atMost", NaN, -Infinity) - fail("atMost", -Infinity, NaN) - }) - }) - - describe("below()", function () { - it("works", function () { - fail("below", 0, 0) - fail("below", 1, 1) - fail("below", 1, -1) - fail("below", 12398.4639, 1245.472398) - - assert.below(0, 1000) - assert.below(-1, 1) - assert.below(-1, 0) - }) - - it("works with Infinities", function () { - fail("below", 0, -Infinity) - fail("below", -Infinity, -Infinity) - fail("below", Infinity, -Infinity) - fail("below", Infinity, 0) - fail("below", Infinity, Infinity) - - assert.below(-Infinity, Infinity) - assert.below(-Infinity, 0) - }) - - it("fails with NaNs", function () { - fail("below", NaN, 0) - fail("below", 0, NaN) - fail("below", NaN, NaN) - fail("below", NaN, Infinity) - fail("below", Infinity, NaN) - fail("below", NaN, -Infinity) - fail("below", -Infinity, NaN) - }) - }) - - describe("between()", function () { - it("works", function () { - assert.between(0, 0, 1) - assert.between(1, 0, 1) - assert.between(1, 1, 1) - assert.between(0, -1, 1) - fail("between", 1, -1, 0) - assert.between(1, -1, 1) - fail("between", 12398.4639, 1245.472398, 12345.12345) - }) - - it("works with Infinities", function () { - fail("between", 0, -Infinity, -1) - assert.between(0, -Infinity, 0) - assert.between(-Infinity, -Infinity, -Infinity) - assert.between(-Infinity, -Infinity, 0) - fail("between", Infinity, -Infinity, 0) - fail("between", Infinity, 0, 0) - assert.between(Infinity, 0, Infinity) - assert.between(-Infinity, -Infinity, Infinity) - }) - - it("fails with NaNs", function () { - fail("between", NaN, 0, NaN) - fail("between", NaN, NaN, 0) - fail("between", 0, NaN, 0) - fail("between", 0, 0, NaN) - fail("between", NaN, NaN, NaN) - fail("between", NaN, 0, Infinity) - fail("between", NaN, -Infinity, 0) - fail("between", NaN, -Infinity, Infinity) - fail("between", Infinity, NaN, 0) - fail("between", Infinity, 0, NaN) - fail("between", Infinity, NaN, NaN) - fail("between", -Infinity, NaN, 0) - fail("between", -Infinity, 0, NaN) - fail("between", -Infinity, NaN, NaN) - }) - }) - - describe("closeTo()", function () { - it("works", function () { - assert.closeTo(0, 0, 0) - assert.closeTo(-0, 0, 0) - assert.closeTo(0.1, 0, 0.2) - assert.closeTo(-0.1, 0, 0.2) - assert.closeTo(0.5, 1, 1) - assert.closeTo(-0.5, -1, 1) - assert.closeTo(-0.5, 0, 1) - assert.closeTo(0.5, 0, 1) - fail("closeTo", 0.2, 0, 0.1) - fail("closeTo", -0.2, 0, 0.1) - fail("closeTo", 1, 0, 0.2) - fail("closeTo", 1, -1, 0.2) - fail("closeTo", 1, 0, 0.2) - }) - - it("works with Infinities", function () { - assert.closeTo(0, 0, Infinity) - assert.closeTo(100, 0, Infinity) - assert.closeTo(Infinity, 0, Infinity) - assert.closeTo(Infinity, -Infinity, Infinity) - assert.closeTo(0, 0, Infinity) - assert.closeTo(0, 100, Infinity) - assert.closeTo(0, Infinity, Infinity) - assert.closeTo(-Infinity, Infinity, Infinity) - }) - - it("fails with NaNs", function () { - fail("closeTo", NaN, 0, 0) - fail("closeTo", NaN, 0, Infinity) - fail("closeTo", NaN, Infinity, 0) - fail("closeTo", NaN, Infinity, Infinity) - fail("closeTo", NaN, -Infinity, 0) - fail("closeTo", NaN, -Infinity, Infinity) - fail("closeTo", 0, NaN, 0) - fail("closeTo", 0, NaN, Infinity) - fail("closeTo", Infinity, NaN, 0) - fail("closeTo", Infinity, NaN, Infinity) - fail("closeTo", -Infinity, NaN, 0) - fail("closeTo", -Infinity, NaN, Infinity) - }) - }) - - describe("notCloseTo()", function () { - it("works", function () { - fail("notCloseTo", 0, 0, 0) - fail("notCloseTo", 0, 0, 0) - fail("notCloseTo", 0.1, 0, 0.2) - fail("notCloseTo", -0.1, 0, 0.2) - fail("notCloseTo", 0.5, 1, 1) - fail("notCloseTo", -0.5, -1, 1) - fail("notCloseTo", -0.5, 0, 1) - fail("notCloseTo", 0.5, 0, 1) - assert.notCloseTo(0.2, 0, 0.1) - assert.notCloseTo(-0.2, 0, 0.1) - assert.notCloseTo(1, 0, 0.2) - assert.notCloseTo(1, -1, 0.2) - assert.notCloseTo(1, 0, 0.2) - }) - - it("works with Infinities", function () { - fail("notCloseTo", 0, 0, Infinity) - fail("notCloseTo", 100, 0, Infinity) - fail("notCloseTo", Infinity, 0, Infinity) - fail("notCloseTo", Infinity, -Infinity, Infinity) - fail("notCloseTo", 0, 0, Infinity) - fail("notCloseTo", 0, 100, Infinity) - fail("notCloseTo", 0, Infinity, Infinity) - fail("notCloseTo", -Infinity, Infinity, Infinity) - }) - - it("fails with NaNs", function () { - fail("notCloseTo", NaN, 0, 0) - fail("notCloseTo", NaN, 0, Infinity) - fail("notCloseTo", NaN, Infinity, 0) - fail("notCloseTo", NaN, Infinity, Infinity) - fail("notCloseTo", NaN, -Infinity, 0) - fail("notCloseTo", NaN, -Infinity, Infinity) - fail("notCloseTo", 0, NaN, 0) - fail("notCloseTo", 0, NaN, Infinity) - fail("notCloseTo", Infinity, NaN, 0) - fail("notCloseTo", Infinity, NaN, Infinity) - fail("notCloseTo", -Infinity, NaN, 0) - fail("notCloseTo", -Infinity, NaN, Infinity) - }) - }) -}) diff --git a/test/assert/has-keys.js b/test/assert/has-keys.js deleted file mode 100644 index aac66b5..0000000 --- a/test/assert/has-keys.js +++ /dev/null @@ -1,225 +0,0 @@ -"use strict" - -describe("assert (has keys)", function () { - // It"s much easier to find problems when the tests are generated. - function shallow(name, opts) { - function run(succeed) { - var args = [] - - for (var i = 1; i < arguments.length; i++) { - args.push(arguments[i]) - } - - if (succeed) { - return assert[name].apply(undefined, args) - } else { - return Util.fail.apply(undefined, [name].concat(args)) - } - } - - describe(name + "()", function () { - it("exists", function () { - assert.isFunction(assert[name]) - }) - - if (opts.keys) { - it("checks number keys", function () { - run(!opts.invert, - {1: true, 2: true, 3: false}, - [1]) - }) - - it("checks string keys", function () { - run(!opts.invert, - {foo: true, bar: false, baz: 1}, - ["foo"]) - }) - } - - it("checks numbers", function () { - run(!opts.invert, - {1: true, 2: true, 3: false}, - {1: true}) - }) - - it("checks strings", function () { - run(!opts.invert, {foo: true, bar: false, baz: 1}, {foo: true}) - }) - - it("is strict", function () { - run(opts.invert, - {foo: "1", bar: 2, baz: 3}, - {foo: 1}) - }) - - it("checks objects", function () { - var obj1 = {} - var obj2 = {} - var obj3 = {} - - run(!opts.invert, - {obj1: obj1, obj3: obj3, prop: 3, foo: "foo"}, - {obj1: obj1, obj3: obj3}) - - run(!opts.invert, - {obj1: obj1, obj2: obj2, obj3: obj3}, - {obj1: obj1, obj2: obj2, obj3: obj3}) - - run(!opts.invert, - {obj1: obj1, obj2: obj2, obj3: obj3}, - {obj1: obj1, obj3: obj3}) - - run(!(opts.invert ^ opts.all), - {obj1: obj1, obj3: obj3}, - {obj1: obj1, obj2: obj2, obj3: obj3}) - - run(!(opts.invert ^ opts.all), - {obj1: obj1, obj3: obj3, prop: 3, foo: "foo"}, - {obj1: obj1, obj2: obj2, obj3: obj3}) - }) - - it("checks nothing", function () { - run(true, {foo: {}, bar: {}}, {}) - }) - - it("checks missing keys", function () { - if (opts.keys) run(opts.invert, {foo: 1, bar: 2, baz: 3}, [10]) - run(opts.invert, {foo: 1, bar: 2, baz: 3}, {a: 10}) - run(opts.invert, {foo: 1, bar: 2, baz: 3}, {foo: 10}) - }) - - it("checks missing objects", function () { - var obj1 = {} - var obj2 = {} - var obj3 = {} - - run(opts.invert, - {obj1: obj1, obj2: obj2, a: 3, b: "foo", c: {}}, - {c: {}}) - - run(opts.invert, {obj1: obj1, obj2: obj2, obj3: obj3}, {a: {}}) - - run(opts.invert, {obj1: obj1, obj2: obj2, obj3: obj3}, {a: []}) - - run(opts.invert ^ !opts.all, - {obj1: obj1, obj2: obj2, obj3: obj3}, - {a: [], obj1: obj1}) - }) - }) - } - - shallow("hasKeys", {keys: true, all: true}) - shallow("notHasKeysAll", {keys: true, all: true, invert: true}) - shallow("hasKeysAny", {keys: true}) - shallow("notHasKeys", {keys: true, invert: true}) - - /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ - - function deep(name, opts) { - function run(succeed) { - var args = [] - - for (var i = 1; i < arguments.length; i++) { - args.push(arguments[i]) - } - - if (succeed) { - return assert[name].apply(undefined, args) - } else { - return Util.fail.apply(undefined, [name].concat(args)) - } - } - - describe(name + "()", function () { - it("exists", function () { - assert.isFunction(assert[name]) - }) - - it("checks numbers", function () { - run(!opts.invert, {1: true, 2: false, 3: 0}, {1: true}) - }) - - it("checks strings", function () { - run(!opts.invert, {foo: 1, bar: 2, baz: 3}, {foo: 1}) - }) - - it("is strict", function () { - run(opts.invert, - {foo: "1", bar: 2, baz: 3}, - {foo: 1}) - }) - - it("checks objects", function () { - var obj1 = {} - var obj2 = {} - var obj3 = {} - - run(!opts.invert, - {obj1: obj1, obj3: obj3, prop: 3, foo: "foo"}, - {obj1: obj1, obj3: obj3}) - - run(!opts.invert, - {obj1: obj1, obj2: obj2, obj3: obj3}, - {obj1: obj1, obj2: obj2, obj3: obj3}) - - run(!opts.invert, - {obj1: obj1, obj2: obj2, obj3: obj3}, - {obj1: obj1, obj3: obj3}) - - run(!(opts.invert ^ opts.all), - {obj1: obj1, obj3: obj3}, - {obj1: obj1, obj2: obj2, obj3: obj3}) - - run(!(opts.invert ^ opts.all), - {obj1: obj1, obj3: obj3, foo: 3, bar: "foo"}, - {obj1: obj1, obj2: obj2, obj3: obj3}) - - run(!opts.invert, - {foo: {foo: 1}, bar: {foo: 2}, baz: 3, quux: {}}, - {foo: {foo: 1}}) - - run(!opts.invert, - {foo: {foo: 1}, bar: {bar: 2}, baz: {}}, - {bar: {bar: 2}, baz: {}}) - - run(opts.invert, - {foo: {foo: 1}, bar: {bar: 2}, baz: []}, - {bar: []}) - }) - - it("checks nothing", function () { - run(true, [{}, {}], []) - }) - - it("checks missing numbers", function () { - run(opts.invert, {foo: 1, bar: 2, baz: 3}, {foo: 10}) - }) - - it("checks missing objects", function () { - run(opts.invert, - {foo: {foo: 1}, bar: {bar: 2}, baz: {}}, - {quux: []}) - - run(opts.invert ^ !opts.all, - {foo: {foo: 1}, bar: {bar: 2}, baz: {}}, - {quux: [], foo: {foo: 1}}) - }) - - it("checks structurally", function () { - function A() { this.foo = 1 } - function B() { this.foo = 1 } - - run(opts.invert ^ opts.match, [new A()], [new B()]) - }) - }) - } - - deep("hasKeysDeep", {all: true}) - deep("notHasKeysAllDeep", {invert: true, all: true}) - deep("hasKeysAnyDeep", {}) - deep("notHasKeysDeep", {invert: true}) - deep("hasKeysMatch", {match: true, all: true}) - deep("notHasKeysAllMatch", {match: true, invert: true, all: true}) - deep("hasKeysAnyMatch", {match: true}) - deep("notHasKeysMatch", {match: true, invert: true}) -}) diff --git a/test/assert/includes.js b/test/assert/includes.js deleted file mode 100644 index 47d4b3d..0000000 --- a/test/assert/includes.js +++ /dev/null @@ -1,473 +0,0 @@ -"use strict" - -describe("assert (includes)", function () { - describe("includes()", function () { - it("checks numbers", function () { - assert.includes([1, 2, 3, 4, 5], 1) - assert.includes([1, 2, 3, 4, 5], [1]) - }) - - it("is strict", function () { - Util.fail("includes", ["1", 2, 3, 4, 5], 1) - Util.fail("includes", ["1", 2, 3, 4, 5], [1]) - }) - - it("checks objects", function () { - var obj1 = {} - var obj2 = {} - var obj3 = {} - - assert.includes([obj1, 3, obj3, "foo"], [obj1, obj3]) - assert.includes([obj1, obj2, obj3], [obj1, obj2, obj3]) - Util.fail("includes", [obj1, 3, obj3, "foo"], [obj1, obj2, obj3]) - }) - - it("checks nothing", function () { - assert.includes([{}, {}], []) - }) - - it("checks missing numbers", function () { - Util.fail("includes", [1, 2, 3, 4, 5], 10) - Util.fail("includes", [1, 2, 3, 4, 5], [10]) - }) - - it("checks missing objects", function () { - var obj1 = {} - var obj2 = {} - var obj3 = {} - - Util.fail("includes", [obj1, obj2, 3, "foo", {}], [{}]) - Util.fail("includes", [obj1, obj2, obj3], [{}]) - Util.fail("includes", [obj1, obj2, obj3], [[]]) - }) - }) - - describe("notIncludesAll()", function () { - it("checks numbers", function () { - Util.fail("notIncludesAll", [1, 2, 3, 4, 5], 1) - Util.fail("notIncludesAll", [1, 2, 3, 4, 5], [1]) - }) - - it("is strict", function () { - assert.notIncludesAll(["1", 2, 3, 4, 5], 1) - assert.notIncludesAll(["1", 2, 3, 4, 5], [1]) - }) - - it("checks objects", function () { - var obj1 = {} - var obj2 = {} - var obj3 = {} - - Util.fail("notIncludesAll", [obj1, 3, obj3, "foo"], [obj1, obj3]) - Util.fail("notIncludesAll", [obj1, obj2, obj3], [obj1, obj2, obj3]) - assert.notIncludesAll([obj1, 3, obj3, "foo"], [obj1, obj2, obj3]) - }) - - it("checks nothing", function () { - assert.notIncludesAll([{}, {}], []) - }) - - it("checks missing numbers", function () { - assert.notIncludesAll([1, 2, 3, 4, 5], 10) - assert.notIncludesAll([1, 2, 3, 4, 5], [10]) - }) - - it("checks missing objects", function () { - var obj1 = {} - var obj2 = {} - var obj3 = {} - - assert.notIncludesAll([obj1, obj2, 3, "foo", {}], [{}]) - assert.notIncludesAll([obj1, obj2, obj3], [{}]) - assert.notIncludesAll([obj1, obj2, obj3], [[]]) - }) - }) - - describe("includesAny()", function () { - it("checks numbers", function () { - assert.includesAny([1, 2, 3, 4, 5], 1) - assert.includesAny([1, 2, 3, 4, 5], [1]) - }) - - it("is strict", function () { - Util.fail("includesAny", ["1", 2, 3, 4, 5], 1) - Util.fail("includesAny", ["1", 2, 3, 4, 5], [1]) - }) - - it("checks objects", function () { - var obj1 = {} - var obj2 = {} - var obj3 = {} - - assert.includesAny([obj1, 3, obj3, "foo"], [obj1, obj3]) - assert.includesAny([obj1, obj2, obj3], [obj1, obj2, obj3]) - assert.includesAny([obj1, 3, obj3, "foo"], [obj1, obj2, obj3]) - }) - - it("checks nothing", function () { - assert.includesAny([{}, {}], []) - }) - - it("checks missing numbers", function () { - Util.fail("includesAny", [1, 2, 3, 4, 5], 10) - Util.fail("includesAny", [1, 2, 3, 4, 5], [10]) - }) - - it("checks missing objects", function () { - var obj1 = {} - var obj2 = {} - var obj3 = {} - - Util.fail("includesAny", [obj1, obj2, 3, "foo", {}], [{}]) - Util.fail("includesAny", [obj1, obj2, obj3], [{}]) - Util.fail("includesAny", [obj1, obj2, obj3], [[]]) - }) - }) - - describe("notIncludes()", function () { - it("checks numbers", function () { - Util.fail("notIncludes", [1, 2, 3, 4, 5], 1) - Util.fail("notIncludes", [1, 2, 3, 4, 5], [1]) - }) - - it("is strict", function () { - assert.notIncludes(["1", 2, 3, 4, 5], 1) - assert.notIncludes(["1", 2, 3, 4, 5], [1]) - }) - - it("checks objects", function () { - var obj1 = {} - var obj2 = {} - var obj3 = {} - - Util.fail("notIncludes", [obj1, 3, obj3, "foo"], [obj1, obj3]) - Util.fail("notIncludes", [obj1, obj2, obj3], [obj1, obj2, obj3]) - Util.fail("notIncludes", [obj1, 3, obj3, "foo"], [obj1, obj2, obj3]) - }) - - it("checks nothing", function () { - assert.notIncludes([{}, {}], []) - }) - - it("checks missing numbers", function () { - assert.notIncludes([1, 2, 3, 4, 5], 10) - assert.notIncludes([1, 2, 3, 4, 5], [10]) - }) - - it("checks missing objects", function () { - var obj1 = {} - var obj2 = {} - var obj3 = {} - - assert.notIncludes([obj1, obj2, 3, "foo", {}], [{}]) - assert.notIncludes([obj1, obj2, obj3], [{}]) - assert.notIncludes([obj1, obj2, obj3], [[]]) - }) - }) - - /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ - - describe("includesDeep()", function () { - it("checks numbers", function () { - assert.includesDeep([1, 2, 3, 4, 5], 1) - assert.includesDeep([1, 2, 3, 4, 5], [1]) - }) - - it("is strict", function () { - Util.fail("includesDeep", ["1", 2, 3, 4, 5], 1) - Util.fail("includesDeep", ["1", 2, 3, 4, 5], [1]) - }) - - it("checks objects", function () { - var obj1 = {} - var obj2 = {} - var obj3 = {} - - assert.includesDeep([obj1, 3, obj3, "foo"], [obj1, obj3]) - assert.includesDeep([obj1, obj2, obj3], [obj1, obj2, obj3]) - assert.includesDeep([obj1, 3, obj3, "foo"], [obj1, obj2, obj3]) - - assert.includesDeep([{foo: 1}, {bar: 2}, 3, "foo", {}], [{foo: 1}]) - assert.includesDeep([{foo: 1}, {bar: 2}, {}], [{bar: 2}, {}]) - assert.includesDeep([{foo: 1}, {bar: 2}, []], [[]]) - }) - - it("checks nothing", function () { - assert.includesDeep([{}, {}], []) - }) - - it("checks missing numbers", function () { - Util.fail("includesDeep", [1, 2, 3, 4, 5], 10) - Util.fail("includesDeep", [1, 2, 3, 4, 5], [10]) - }) - - it("checks missing objects", function () { - Util.fail("includesDeep", [{foo: 1}, {bar: 2}, {}], [[]]) - Util.fail("includesDeep", [{foo: 1}, {bar: 2}, {}], [[], {foo: 1}]) - }) - }) - - describe("notIncludesAllDeep()", function () { - it("checks numbers", function () { - Util.fail("notIncludesAllDeep", [1, 2, 3, 4, 5], 1) - Util.fail("notIncludesAllDeep", [1, 2, 3, 4, 5], [1]) - }) - - it("is strict", function () { - assert.notIncludesAllDeep(["1", 2, 3, 4, 5], 1) - assert.notIncludesAllDeep(["1", 2, 3, 4, 5], [1]) - }) - - it("checks objects", function () { - assert.notIncludesAllDeep([{foo: 1}, 3, "foo"], ["foo", 1]) - - assert.notIncludesAllDeep( - [{foo: 1}, {bar: 2}], - [{foo: 1}, {bar: 1}]) - - Util.fail("notIncludesAllDeep", - [{foo: 1}, {bar: 2}], - [{foo: 1}, {bar: 2}]) - }) - - it("checks nothing", function () { - assert.notIncludesAllDeep([{}, {}], []) - }) - - it("checks missing numbers", function () { - assert.notIncludesAllDeep([1, 2, 3, 4, 5], 10) - assert.notIncludesAllDeep([1, 2, 3, 4, 5], [10]) - }) - - it("checks missing objects", function () { - assert.notIncludesAllDeep([{foo: 1}, {bar: 2}, {}], [[]]) - assert.notIncludesAllDeep([{foo: 1}, {bar: 2}, {}], [[], {foo: 1}]) - }) - }) - - describe("includesAnyDeep()", function () { - it("checks numbers", function () { - assert.includesAnyDeep([1, 2, 3, 4, 5], 1) - assert.includesAnyDeep([1, 2, 3, 4, 5], [1]) - }) - - it("is strict", function () { - Util.fail("includesAnyDeep", ["1", 2, 3, 4, 5], 1) - Util.fail("includesAnyDeep", ["1", 2, 3, 4, 5], [1]) - }) - - it("checks objects", function () { - assert.includesAnyDeep([{foo: 1}, 3, "foo"], ["foo", 1]) - assert.includesAnyDeep([{foo: 1}, {bar: 2}], [{foo: 1}, {bar: 1}]) - assert.includesAnyDeep([{foo: 1}, {bar: 2}], [{foo: 1}, {bar: 2}]) - }) - - it("checks nothing", function () { - assert.includesAnyDeep([{}, {}], []) - }) - - it("checks missing numbers", function () { - Util.fail("includesAnyDeep", [1, 2, 3, 4, 5], 10) - Util.fail("includesAnyDeep", [1, 2, 3, 4, 5], [10]) - }) - - it("checks missing objects", function () { - Util.fail("includesAnyDeep", [{foo: 1}, {bar: 2}, {}], [[]]) - assert.includesAnyDeep([{foo: 1}, {bar: 2}, {}], [[], {foo: 1}]) - }) - }) - - describe("notIncludesDeep()", function () { - it("checks numbers", function () { - Util.fail("notIncludesDeep", [1, 2, 3, 4, 5], 1) - Util.fail("notIncludesDeep", [1, 2, 3, 4, 5], [1]) - }) - - it("is strict", function () { - assert.notIncludesDeep(["1", 2, 3, 4, 5], 1) - assert.notIncludesDeep(["1", 2, 3, 4, 5], [1]) - }) - - it("checks objects", function () { - Util.fail("notIncludesDeep", [{foo: 1}, 3, "foo"], ["foo", 1]) - - Util.fail("notIncludesDeep", - [{foo: 1}, {bar: 2}], - [{foo: 1}, {bar: 1}]) - - Util.fail("notIncludesDeep", - [{foo: 1}, {bar: 2}], - [{foo: 1}, {bar: 2}]) - }) - - it("checks nothing", function () { - assert.notIncludesDeep([{}, {}], []) - }) - - it("checks missing numbers", function () { - assert.notIncludesDeep([1, 2, 3, 4, 5], 10) - assert.notIncludesDeep([1, 2, 3, 4, 5], [10]) - }) - - it("checks missing objects", function () { - assert.notIncludesDeep([{foo: 1}, {bar: 2}, {}], [[]]) - - Util.fail("notIncludesDeep", - [{foo: 1}, {bar: 2}, {}], - [[], {foo: 1}]) - }) - }) - - /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ - - describe("includesMatch()", function () { - it("checks numbers", function () { - assert.includesMatch([1, 2, 3, 4, 5], 1) - assert.includesMatch([1, 2, 3, 4, 5], [1]) - }) - - it("is strict", function () { - Util.fail("includesMatch", ["1", 2, 3, 4, 5], 1) - Util.fail("includesMatch", ["1", 2, 3, 4, 5], [1]) - }) - - it("checks objects", function () { - var obj1 = {} - var obj2 = {} - var obj3 = {} - - assert.includesMatch([obj1, 3, obj3, "foo"], [obj1, obj3]) - assert.includesMatch([obj1, obj2, obj3], [obj1, obj2, obj3]) - assert.includesMatch([obj1, 3, obj3, "foo"], [obj1, obj2, obj3]) - - assert.includesMatch([{foo: 1}, {bar: 2}, 3, "foo", {}], [{foo: 1}]) - assert.includesMatch([{foo: 1}, {bar: 2}, {}], [{bar: 2}, {}]) - assert.includesMatch([{foo: 1}, {bar: 2}, []], [[]]) - }) - - it("checks nothing", function () { - assert.includesMatch([{}, {}], []) - }) - - it("checks missing numbers", function () { - Util.fail("includesMatch", [1, 2, 3, 4, 5], 10) - Util.fail("includesMatch", [1, 2, 3, 4, 5], [10]) - }) - - it("checks missing objects", function () { - Util.fail("includesMatch", [{foo: 1}, {bar: 2}, {}], [[]]) - Util.fail("includesMatch", [{foo: 1}, {bar: 2}, {}], [[], {foo: 1}]) - }) - }) - - describe("notIncludesAllMatch()", function () { - it("checks numbers", function () { - Util.fail("notIncludesAllMatch", [1, 2, 3, 4, 5], 1) - Util.fail("notIncludesAllMatch", [1, 2, 3, 4, 5], [1]) - }) - - it("is strict", function () { - assert.notIncludesAllMatch(["1", 2, 3, 4, 5], 1) - assert.notIncludesAllMatch(["1", 2, 3, 4, 5], [1]) - }) - - it("checks objects", function () { - assert.notIncludesAllMatch([{foo: 1}, 3, "foo"], ["foo", 1]) - - assert.notIncludesAllMatch( - [{foo: 1}, {bar: 2}], - [{foo: 1}, {bar: 1}]) - - Util.fail("notIncludesAllMatch", - [{foo: 1}, {bar: 2}], - [{foo: 1}, {bar: 2}]) - }) - - it("checks nothing", function () { - assert.notIncludesAllMatch([{}, {}], []) - }) - - it("checks missing numbers", function () { - assert.notIncludesAllMatch([1, 2, 3, 4, 5], 10) - assert.notIncludesAllMatch([1, 2, 3, 4, 5], [10]) - }) - - it("checks missing objects", function () { - assert.notIncludesAllMatch([{foo: 1}, {bar: 2}, {}], [[]]) - assert.notIncludesAllMatch([{foo: 1}, {bar: 2}, {}], [[], {foo: 1}]) - }) - }) - - describe("includesAnyMatch()", function () { - it("checks numbers", function () { - assert.includesAnyMatch([1, 2, 3, 4, 5], 1) - assert.includesAnyMatch([1, 2, 3, 4, 5], [1]) - }) - - it("is strict", function () { - Util.fail("includesAnyMatch", ["1", 2, 3, 4, 5], 1) - Util.fail("includesAnyMatch", ["1", 2, 3, 4, 5], [1]) - }) - - it("checks objects", function () { - assert.includesAnyMatch([{foo: 1}, 3, "foo"], ["foo", 1]) - assert.includesAnyMatch([{foo: 1}, {bar: 2}], [{foo: 1}, {bar: 1}]) - assert.includesAnyMatch([{foo: 1}, {bar: 2}], [{foo: 1}, {bar: 2}]) - }) - - it("checks nothing", function () { - assert.includesAnyMatch([{}, {}], []) - }) - - it("checks missing numbers", function () { - Util.fail("includesAnyMatch", [1, 2, 3, 4, 5], 10) - Util.fail("includesAnyMatch", [1, 2, 3, 4, 5], [10]) - }) - - it("checks missing objects", function () { - Util.fail("includesAnyMatch", [{foo: 1}, {bar: 2}, {}], [[]]) - assert.includesAnyMatch([{foo: 1}, {bar: 2}, {}], [[], {foo: 1}]) - }) - }) - - describe("notIncludesMatch()", function () { - it("checks numbers", function () { - Util.fail("notIncludesMatch", [1, 2, 3, 4, 5], 1) - Util.fail("notIncludesMatch", [1, 2, 3, 4, 5], [1]) - }) - - it("is strict", function () { - assert.notIncludesMatch(["1", 2, 3, 4, 5], 1) - assert.notIncludesMatch(["1", 2, 3, 4, 5], [1]) - }) - - it("checks objects", function () { - Util.fail("notIncludesMatch", [{foo: 1}, 3, "foo"], ["foo", 1]) - - Util.fail("notIncludesMatch", - [{foo: 1}, {bar: 2}], - [{foo: 1}, {bar: 1}]) - - Util.fail("notIncludesMatch", - [{foo: 1}, {bar: 2}], - [{foo: 1}, {bar: 2}]) - }) - - it("checks nothing", function () { - assert.notIncludesMatch([{}, {}], []) - }) - - it("checks missing numbers", function () { - assert.notIncludesMatch([1, 2, 3, 4, 5], 10) - assert.notIncludesMatch([1, 2, 3, 4, 5], [10]) - }) - - it("checks missing objects", function () { - assert.notIncludesMatch([{foo: 1}, {bar: 2}, {}], [[]]) - - Util.fail("notIncludesMatch", - [{foo: 1}, {bar: 2}, {}], - [[], {foo: 1}]) - }) - }) -}) diff --git a/test/assert/match.js b/test/assert/match.js deleted file mode 100644 index da1574d..0000000 --- a/test/assert/match.js +++ /dev/null @@ -1,38 +0,0 @@ -"use strict" - -describe("assert (match)", function () { - it("exists", function () { - assert.isFunction(assert.match) - assert.isFunction(assert.notMatch) - assert.isFunction(assert.deepEqual) - assert.isFunction(assert.notDeepEqual) - }) - - it("checks match + same prototype", function () { - function A(id) { this.id = id } - - assert.deepEqual(new A(1), new A(1)) - assert.match(new A(1), new A(1)) - }) - - it("checks match + different prototype", function () { - function A(id) { this.id = id } - - assert.notDeepEqual(new A(1), {id: 1}) - assert.match(new A(1), {id: 1}) - }) - - it("checks no match + same prototype", function () { - function A(id) { this.id = id } - - assert.notDeepEqual(new A(1), new A(2)) - assert.notMatch(new A(1), new A(2)) - }) - - it("checks no match + different prototype", function () { - function A(id) { this.id = id } - - assert.notDeepEqual(new A(1), {id: 2}) - assert.notMatch(new A(1), {id: 2}) - }) -}) diff --git a/test/assert/type.js b/test/assert/type.js deleted file mode 100644 index f8b3d47..0000000 --- a/test/assert/type.js +++ /dev/null @@ -1,192 +0,0 @@ -"use strict" - -/* global Symbol */ - -describe("assert (type)", function () { - function testType(name, callback, raw) { - var positive = raw ? name.toLowerCase() : "is" + name - var negated = raw ? "not" + name : "not" + name - - Util.basic(positive + "()", function () { - callback(assert[positive], Util.fail.bind(undefined, positive)) - }) - - Util.basic(negated + "()", function () { - callback(Util.fail.bind(undefined, negated), assert[negated]) - }) - } - - testType("Boolean", function (is, not) { - is(true) - is(false) - not(0) - not(1) - not(NaN) - not(Infinity) - not("foo") - not("") - not(null) - not({}) - not([]) - not(function () {}) - not(undefined) - not() - if (typeof Symbol === "function") not(Symbol()) - }) - - testType("Number", function (is, not) { - not(true) - not(false) - is(0) - is(1) - is(NaN) - is(Infinity) - not("foo") - not("") - not(null) - not({}) - not([]) - not(function () {}) - not(undefined) - not() - if (typeof Symbol === "function") not(Symbol()) - }) - - testType("Function", function (is, not) { - not(true) - not(false) - not(0) - not(1) - not(NaN) - not(Infinity) - not("foo") - not("") - not(null) - not({}) - not([]) - is(function () {}) - not(undefined) - not() - if (typeof Symbol === "function") not(Symbol()) - }) - - testType("Object", function (is, not) { - not(true) - not(false) - not(0) - not(1) - not(NaN) - not(Infinity) - not("foo") - not("") - not(null) - is({}) - is([]) - not(function () {}) - not(undefined) - not() - if (typeof Symbol === "function") not(Symbol()) - }) - - testType("String", function (is, not) { - not(true) - not(false) - not(0) - not(1) - not(NaN) - not(Infinity) - is("foo") - is("") - not(null) - not({}) - not([]) - not(function () {}) - not(undefined) - not() - if (typeof Symbol === "function") not(Symbol()) - }) - - testType("Symbol", function (is, not) { - not(true) - not(false) - not(0) - not(1) - not(NaN) - not(Infinity) - not("foo") - not("") - not(null) - not({}) - not([]) - not(function () {}) - not(undefined) - not() - if (typeof Symbol === "function") is(Symbol()) - }) - - testType("Exists", function (is, not) { - is(true) - is(false) - is(0) - is(1) - is(NaN) - is(Infinity) - is("foo") - is("") - not(null) - is({}) - is([]) - is(function () {}) - not(undefined) - not() - if (typeof Symbol === "function") is(Symbol()) - }, true) - - testType("Array", function (is, not) { - not(true) - not(false) - not(0) - not(1) - not(NaN) - not(Infinity) - not("foo") - not("") - not(null) - not({}) - is([]) - not(function () {}) - not(undefined) - not() - if (typeof Symbol === "function") not(Symbol()) - }) - - Util.basic("is()", function () { - function A() {} - assert.is(A, new A()) - assert.is(Object, new A()) - - function B() {} - Util.methods(B, A) - - assert.is(B, new B()) - assert.is(A, new B()) - - Util.fail("is", B, new A()) - Util.fail("is", RegExp, []) - }) - - Util.basic("not()", function () { - function A() {} - Util.fail("not", A, new A()) - Util.fail("not", Object, new A()) - - function B() {} - Util.methods(B, A) - - Util.fail("not", B, new B()) - Util.fail("not", A, new B()) - - assert.not(B, new A()) - assert.not(RegExp, []) - }) -}) diff --git a/tsconfig.json b/tsconfig.json index bb7e970..d872dd3 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -7,10 +7,8 @@ "moduleResolution": "node" }, "files": [ - "assert.d.ts", "index.d.ts", "internal.d.ts", - "match.d.ts", "r/dot.d.ts", "r/index.d.ts", "r/spec.d.ts",