Skip to content

Commit

Permalink
Updates components
Browse files Browse the repository at this point in the history
Signed-off-by: Christopher Rogers <chrissrogers@gmail.com>
  • Loading branch information
chrissrogers committed Oct 14, 2015
1 parent 163588f commit b9e0c15
Show file tree
Hide file tree
Showing 34 changed files with 6,992 additions and 3 deletions.
3 changes: 3 additions & 0 deletions components/component-assert@0.5.1/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
build
components
node_modules
42 changes: 42 additions & 0 deletions components/component-assert@0.5.1/History.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@

0.5.1 / 2015-08-19
==================

* bump yields/fmt

0.5.0 / 2014-10-07
==================

* index: Fix .throws() and .doesNotThrow()
* add mocha diff

0.4.0 / 2014-06-30
==================

* fix default assertion messages
* add testing server

0.3.1 / 2014-06-03
==================

* fix custom assertion messages being ignored

0.3.0 / 2013-12-10
==================

* add node assert methods

0.2.0 / 2013-08-15
==================

* update to work with latest component/stack.

0.1.1 / 2012-10-09
==================

* fix paren balancing with greedy capture

0.1.0 / 2012-10-09
==================

* add callsite support for auto-generated messages
20 changes: 20 additions & 0 deletions components/component-assert@0.5.1/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

build: components index.js
@component build --dev

components: component.json
@component install --dev

clean:
@rm -fr build components

node_modules: package.json
@npm install

server: node_modules build
@node test/server.js

test: build
@open http://localhost:7575

.PHONY: clean server test
25 changes: 25 additions & 0 deletions components/component-assert@0.5.1/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

# assert

C-style assertion lib.

## Example

With custom assertion message:

```js
var assert = require('assert');
assert(expr, 'oh no it broke');
```

Or auto-generated assertion message in
browsers that support `Error.captureStackTrace()`:

```js
var assert = require('assert');
assert(user.name == 'Tobi');
```

## License

MIT
18 changes: 18 additions & 0 deletions components/component-assert@0.5.1/component.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "assert",
"repo": "component/assert",
"description": "Assertion lib",
"version": "0.5.1",
"keywords": [
"assert",
"test"
],
"dependencies": {
"component/stack": "*",
"jkroso/equals": "*",
"yields/fmt": "0.1.0"
},
"scripts": [
"index.js"
]
}
6 changes: 6 additions & 0 deletions components/component-assert@0.5.1/example.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<html>
<body>
<script src="build/build.js"></script>
<script src="example.js"></script>
</body>
</html>
13 changes: 13 additions & 0 deletions components/component-assert@0.5.1/example.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

/**
* Module dependencies.
*/

var assert = require('assert');

function test() {
var user = { name: 'Tobi' };
assert(user.name == 'tobi');
}

test();
203 changes: 203 additions & 0 deletions components/component-assert@0.5.1/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@

/**
* Module dependencies.
*/

var equals = require('equals');
var fmt = require('fmt');
var stack = require('stack');

/**
* Assert `expr` with optional failure `msg`.
*
* @param {Mixed} expr
* @param {String} [msg]
* @api public
*/

module.exports = exports = function (expr, msg) {
if (expr) return;
throw error(msg || message());
};

/**
* Assert `actual` is weak equal to `expected`.
*
* @param {Mixed} actual
* @param {Mixed} expected
* @param {String} [msg]
* @api public
*/

exports.equal = function (actual, expected, msg) {
if (actual == expected) return;
throw error(msg || fmt('Expected %o to equal %o.', actual, expected), actual, expected);
};

/**
* Assert `actual` is not weak equal to `expected`.
*
* @param {Mixed} actual
* @param {Mixed} expected
* @param {String} [msg]
* @api public
*/

exports.notEqual = function (actual, expected, msg) {
if (actual != expected) return;
throw error(msg || fmt('Expected %o not to equal %o.', actual, expected));
};

/**
* Assert `actual` is deep equal to `expected`.
*
* @param {Mixed} actual
* @param {Mixed} expected
* @param {String} [msg]
* @api public
*/

exports.deepEqual = function (actual, expected, msg) {
if (equals(actual, expected)) return;
throw error(msg || fmt('Expected %o to deeply equal %o.', actual, expected), actual, expected);
};

/**
* Assert `actual` is not deep equal to `expected`.
*
* @param {Mixed} actual
* @param {Mixed} expected
* @param {String} [msg]
* @api public
*/

exports.notDeepEqual = function (actual, expected, msg) {
if (!equals(actual, expected)) return;
throw error(msg || fmt('Expected %o not to deeply equal %o.', actual, expected));
};

/**
* Assert `actual` is strict equal to `expected`.
*
* @param {Mixed} actual
* @param {Mixed} expected
* @param {String} [msg]
* @api public
*/

exports.strictEqual = function (actual, expected, msg) {
if (actual === expected) return;
throw error(msg || fmt('Expected %o to strictly equal %o.', actual, expected), actual, expected);
};

/**
* Assert `actual` is not strict equal to `expected`.
*
* @param {Mixed} actual
* @param {Mixed} expected
* @param {String} [msg]
* @api public
*/

exports.notStrictEqual = function (actual, expected, msg) {
if (actual !== expected) return;
throw error(msg || fmt('Expected %o not to strictly equal %o.', actual, expected));
};

/**
* Assert `block` throws an `error`.
*
* @param {Function} block
* @param {Function} [error]
* @param {String} [msg]
* @api public
*/

exports.throws = function (block, err, msg) {
var threw;
try {
block();
} catch (e) {
threw = e;
}

if (!threw) throw error(msg || fmt('Expected %s to throw an error.', block.toString()));
if (err && !(threw instanceof err)) {
throw error(msg || fmt('Expected %s to throw an %o.', block.toString(), err));
}
};

/**
* Assert `block` doesn't throw an `error`.
*
* @param {Function} block
* @param {Function} [error]
* @param {String} [msg]
* @api public
*/

exports.doesNotThrow = function (block, err, msg) {
var threw;
try {
block();
} catch (e) {
threw = e;
}

if (threw) throw error(msg || fmt('Expected %s not to throw an error.', block.toString()));
if (err && (threw instanceof err)) {
throw error(msg || fmt('Expected %s not to throw an %o.', block.toString(), err));
}
};

/**
* Create a message from the call stack.
*
* @return {String}
* @api private
*/

function message() {
if (!Error.captureStackTrace) return 'assertion failed';
var callsite = stack()[2];
var fn = callsite.getFunctionName();
var file = callsite.getFileName();
var line = callsite.getLineNumber() - 1;
var col = callsite.getColumnNumber() - 1;
var src = get(file);
line = src.split('\n')[line].slice(col);
var m = line.match(/assert\((.*)\)/);
return m && m[1].trim();
}

/**
* Load contents of `script`.
*
* @param {String} script
* @return {String}
* @api private
*/

function get(script) {
var xhr = new XMLHttpRequest;
xhr.open('GET', script, false);
xhr.send(null);
return xhr.responseText;
}

/**
* Error with `msg`, `actual` and `expected`.
*
* @param {String} msg
* @param {Mixed} actual
* @param {Mixed} expected
* @return {Error}
*/

function error(msg, actual, expected){
var err = new Error(msg);
err.showDiff = 3 == arguments.length;
err.actual = actual;
err.expected = expected;
return err;
}
8 changes: 8 additions & 0 deletions components/component-assert@0.5.1/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "assert",
"private": true,
"dependencies": {
"express": "^4.4.5",
"hbs": "^2.7.0"
}
}
14 changes: 14 additions & 0 deletions components/component-assert@0.5.1/test/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<html>
<head>
<title>assert tests</title>
<link rel="stylesheet" href="test/mocha.css" />
</head>
<body>
<div id="mocha"></div>
<script src="test/mocha.js"></script>
<script>mocha.setup({ui: 'bdd'})</script>
<script src="build/build.js"></script>
<script src="test/index.js"></script>
<script>mocha.run();</script>
</body>
</html>
Loading

0 comments on commit b9e0c15

Please sign in to comment.