Skip to content

Commit

Permalink
tabs -> spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
jkroso committed Mar 2, 2014
1 parent 60868a3 commit f48aa37
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 109 deletions.
10 changes: 5 additions & 5 deletions deep.js
Expand Up @@ -6,7 +6,7 @@ var coerce = Result.coerce
var when = Result.when

module.exports = function(value){
return coerce(unbox(value))
return coerce(unbox(value))
}

/**
Expand All @@ -17,11 +17,11 @@ module.exports = function(value){
*/

function unbox(value){
if (value instanceof ResType) return when(value, unbox)
if (value && typeof value == 'object') return unboxAll(value)
return value
if (value instanceof ResType) return when(value, unbox)
if (value && typeof value == 'object') return unboxAll(value)
return value
}

function unboxAll(obj){
return map(obj, unbox)
return map(obj, unbox)
}
4 changes: 2 additions & 2 deletions index.js
Expand Up @@ -10,7 +10,7 @@ module.exports = exports = all

exports.naked =
exports.args = function(){
return all(arguments)
return all(arguments)
}

/**
Expand All @@ -21,7 +21,7 @@ exports.args = function(){
*/

function all(obj){
return map(obj, identity)
return map(obj, identity)
}

/**
Expand Down
28 changes: 14 additions & 14 deletions test/index.html
@@ -1,23 +1,23 @@
<!doctype html>
<html>
<head>
<title>when-all tests</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="../node_modules/mocha/mocha.css">
<title>when-all tests</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="../node_modules/mocha/mocha.css">
</head>
<body>
<div id="mocha"></div>
<script>
var mocha = require('mocha')
mocha.setup('bdd')
mocha.timeout(200)
<div id="mocha"></div>
<script>
var mocha = require('mocha')
mocha.setup('bdd')
mocha.timeout(200)

require('./when-all.test')
require('./when-all.test')

mocha.run(function(){
console.log('Done!')
})
</script>
mocha.run(function(){
console.log('Done!')
})
</script>
</body>
</html>
176 changes: 88 additions & 88 deletions test/when-all.test.js
Expand Up @@ -8,107 +8,107 @@ var wrap = Result.wrap

test('all()', all)
test('all.args()', function(array){
return all.args.apply(this, array)
return all.args.apply(this, array)
})

function test(what, all){
describe(what, function(){
it('should return a Result', function(){
all([]).should.be.an.instanceOf(ResultType)
})
it('should resolve instantly if the array is empty', function(done){
all([]).state.should.equal('done')
all([]).then(function(val){
val.should.deep.equal([])
}).node(done)
})
it('should resolve to the values within the original array', function(done){
all([1,2,3]).then(function(vals){
vals.should.deep.equal([1,2,3])
done()
})
})
it('should resolve any results within the array before resolving itself', function(done){
all([delay(1), delay(2), delay(3)]).then(function(vals){
vals.should.deep.equal([1,2,3])
done()
})
})
it('should error with the first failed Result', function(done){
all([delay(1), delay(2, 'error'), delay(3)]).then(null, function(val){
val.should.equal(2)
done()
})
})
})
describe(what, function(){
it('should return a Result', function(){
all([]).should.be.an.instanceOf(ResultType)
})
it('should resolve instantly if the array is empty', function(done){
all([]).state.should.equal('done')
all([]).then(function(val){
val.should.deep.equal([])
}).node(done)
})
it('should resolve to the values within the original array', function(done){
all([1,2,3]).then(function(vals){
vals.should.deep.equal([1,2,3])
done()
})
})
it('should resolve any results within the array before resolving itself', function(done){
all([delay(1), delay(2), delay(3)]).then(function(vals){
vals.should.deep.equal([1,2,3])
done()
})
})
it('should error with the first failed Result', function(done){
all([delay(1), delay(2, 'error'), delay(3)]).then(null, function(val){
val.should.equal(2)
done()
})
})
})
}

describe('object', function (){
it('resolve to a new Object', function(done){
all({
a: delay(1),
b: delay(2),
c: 3
}).then(function(obj){
obj.should.deep.equal({a:1,b:2,c:3})
}).node(done)
})
it('resolve to a new Object', function(done){
all({
a: delay(1),
b: delay(2),
c: 3
}).then(function(obj){
obj.should.deep.equal({a:1,b:2,c:3})
}).node(done)
})

it('should fail if one value fails', function(done){
all({
a: delay(new Error('fail'), 'error'),
b: delay(2),
c: 3
}).then(null, function(e){
e.message.should.equal('fail')
done()
})
})
it('should fail if one value fails', function(done){
all({
a: delay(new Error('fail'), 'error'),
b: delay(2),
c: 3
}).then(null, function(e){
e.message.should.equal('fail')
done()
})
})

it('should handle immediate resolution', function(done){
all({
a: wrap(1),
b: wrap(2),
c: wrap(3)
}).then(function(obj){
obj.should.deep.equal({a:1,b:2,c:3})
}).node(done)
})
it('should handle immediate resolution', function(done){
all({
a: wrap(1),
b: wrap(2),
c: wrap(3)
}).then(function(obj){
obj.should.deep.equal({a:1,b:2,c:3})
}).node(done)
})
})

describe('deep', function(){
it('recur down till everything is unboxed', function(done){
deep(wrap({
a: delay('a'),
b: delay([
wrap(1),
delay(2)
]),
c: 'c'
})).then(function(obj){
obj.should.eql({
a: 'a',
b: [1, 2],
c: 'c'
})
}).node(done)
})
it('recur down till everything is unboxed', function(done){
deep(wrap({
a: delay('a'),
b: delay([
wrap(1),
delay(2)
]),
c: 'c'
})).then(function(obj){
obj.should.eql({
a: 'a',
b: [1, 2],
c: 'c'
})
}).node(done)
})

it('should handle failing results', function(done){
var error = new Error(this.test.title)
deep({
a: 2,
b: delay(error, 'error')
}).then(null, function(e){
e.should.equal(error)
}).node(done)
})
it('should handle failing results', function(done){
var error = new Error(this.test.title)
deep({
a: 2,
b: delay(error, 'error')
}).then(null, function(e){
e.should.equal(error)
}).node(done)
})
})

function delay(value, method){
var result = new Result
setTimeout(function(){
result[method || 'write'](value)
}, Math.random() * 10)
return result
var result = new Result
setTimeout(function(){
result[method || 'write'](value)
}, Math.random() * 10)
return result
}

0 comments on commit f48aa37

Please sign in to comment.