Skip to content

Commit

Permalink
use Z.equals for equality checks
Browse files Browse the repository at this point in the history
  • Loading branch information
davidchambers committed Apr 9, 2017
1 parent 4e0c4d9 commit 06151a0
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 9 deletions.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ test/public/bundle.js: \
bower_components/jquery/dist/jquery.js \
bower_components/qunit/qunit/qunit.js \
bower_components/ramda/dist/ramda.js \
bower_components/sanctuary-type-identifiers/index.js \
bower_components/sanctuary-type-classes/index.js \
lib/doctest.js \
test/shared/results.js
mkdir -p $(@D)
Expand Down
4 changes: 3 additions & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
"dependencies": {
"coffee-script": "1.10.x",
"jquery": "2.1.x",
"ramda": "0.19.x"
"ramda": "0.19.x",
"sanctuary-type-classes": "4.0.x",
"sanctuary-type-identifiers": "1.0.x"
},
"devDependencies": {
"qunit": "1.19.x"
Expand Down
20 changes: 13 additions & 7 deletions lib/doctest.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,22 @@
}


var CoffeeScript, R, esprima;
var CoffeeScript, R, Z, esprima, type;
if (typeof window !== 'undefined') {
CoffeeScript = global.CoffeeScript;
esprima = global.esprima;
R = global.R;
Z = global.sanctuaryTypeClasses;
type = global.sanctuaryTypeIdentifiers;
global.doctest = doctest;
} else {
var fs = require('fs');
var pathlib = require('path');
CoffeeScript = require('coffee-script');
esprima = require('esprima');
R = require('ramda');
Z = require('sanctuary-type-classes');
type = require('sanctuary-type-identifiers');
module.exports = doctest;
}

Expand Down Expand Up @@ -108,7 +112,9 @@
var reduce = R.flip(R.addIndex(R.reduce));

// show :: a -> String
var show = R.toString;
function show(x) {
return type(x) === 'Error' ? String(x) : Z.toString(x);
}

// startsWith :: String -> String -> Boolean
var startsWith = R.curry(function(prefix, s) {
Expand Down Expand Up @@ -592,12 +598,12 @@

results.push([
throws === io['!'] &&
(R.is(Error, actual) ?
actual.constructor === expected.constructor &&
(throws && !expected.message ||
actual.message === expected.message) :
(throws ?
type(actual) === 'Error' &&
actual.name === expected.name &&
(expected.message === '' || actual.message === expected.message) :
// else
R.equals(actual, expected)),
Z.equals(actual, expected)),
(throws ? formatError(expected.message !== '') : show)(actual),
(io['!'] ? formatError(expected.message !== '') : show)(expected),
io[':']
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
"coffee-script": "1.10.x",
"commander": "2.8.x",
"esprima": "3.1.x",
"ramda": "0.19.x"
"ramda": "0.19.x",
"sanctuary-type-classes": "4.0.x",
"sanctuary-type-identifiers": "1.0.x"
},
"devDependencies": {
"bower": "1.5.x",
Expand Down
16 changes: 16 additions & 0 deletions test/fantasy-land/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// > Absolute(-1)
// Absolute(1)
function Absolute(n) {
if (!(this instanceof Absolute)) return new Absolute(n);
this.value = n;
}

Absolute['@@type'] = 'doctest/Absolute';

Absolute.prototype.toString = function() {
return 'Absolute(' + this.value + ')';
};

Absolute.prototype['fantasy-land/equals'] = function(other) {
return Math.abs(this.value) === Math.abs(other.value);
};
4 changes: 4 additions & 0 deletions test/fantasy-land/results.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = [[
'uses Z.equals for equality checks',
[true, 'Absolute(-1)', 'Absolute(1)', 2]
]];
1 change: 1 addition & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ testModule('test/line-endings/LF.js');
testModule('test/line-endings/LF.coffee');
testModule('test/exceptions/index.js');
testModule('test/statements/index.js');
testModule('test/fantasy-land/index.js');
testModule('test/transcribe/index.js', {prefix: '.'});
testModule('test/transcribe/index.coffee', {prefix: '.'});
testModule('test/amd/index.js', {module: 'amd'});
Expand Down

0 comments on commit 06151a0

Please sign in to comment.