Skip to content

Commit

Permalink
Organize for travis
Browse files Browse the repository at this point in the history
  • Loading branch information
Christopher Sidell committed Jul 6, 2017
1 parent 4b15b58 commit e01819a
Show file tree
Hide file tree
Showing 4 changed files with 185 additions and 159 deletions.
3 changes: 3 additions & 0 deletions README.md
@@ -1,5 +1,8 @@
# bLodash

[![Build Status](https://travis-ci.org/Sieabah/blodash.svg?branch=master)](https://travis-ci.org/Sieabah/blodash)
[![We don't lie about our coverage](https://coveralls.io/repos/github/Sieabah/blodash/badge.svg?branch=master)](https://coveralls.io/github/Sieabah/blodash?branch=master)

Why does this library exist? It's *the* satirical edition of the absolutely legendary
library that is _[lodash](https://github.com/lodash/lodash)_.

Expand Down
11 changes: 9 additions & 2 deletions package.json
Expand Up @@ -4,7 +4,9 @@
"description": "Lodash didn't blow hard enough",
"main": "index.js",
"scripts": {
"test": "mocha test.js"
"build": "istanbul cover ./node_modules/mocha/bin/_mocha ./tests/*.test.js --report lcovonly -- -R spec",
"test": "npm run build",
"posttest": "cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js; rm -rf ./coverage"
},
"repository": {
"type": "git",
Expand All @@ -23,7 +25,12 @@
"lodash": "^4.17.4"
},
"devDependencies": {
"glob": "^7.1.2",
"mocha": "^3.3.0",
"should": "^11.2.1"
"should": "^11.2.1",
"coveralls": "^2.11.15",
"istanbul": "^0.4.5",
"mocha": "^3.2.0",
"mocha-lcov-reporter": "^1.2.0"
}
}
165 changes: 8 additions & 157 deletions test.js
@@ -1,162 +1,13 @@
var b_ = require('./index.js'),
should = require('should');
'use strict';

function noop(){}
const Mocha = require('mocha'),
glob = require('glob');

describe('Tests', function(){
let mocha = new Mocha({

it('Should Do If', function(done){
b_.if(b_.true, function(){
done();
});
});
});

it('Should be completely asynchronous', function(done){
var sync = b_.false;
for(let file of glob.sync('tests/*.test.js'))
mocha.addFile(file);

b_.if(b_.true, function(){
sync = b_.true;
});

if(sync)
done();
else
done(new Error('Asynchronous'));
});

it('If Should not explode if Falsey value if given', function(){
b_.if(b_.false, b_.false);
b_.if(b_.false, b_.true);
});

it('If Should explode if Falsey value if given and silent is false', function(){
should.throws(function(){b_.if(b_.false)});
});

it('Should catch if silently', function(done){
b_.if(function(){
return b_.else(function(){
b_.if(b_.false, function(){
done(new Error("This shouldn't be called"));
})
}) === b_.undefined;
}, function(){ done(); });
});

it('Should return value', function(){
var value = b_.if(b_.true, function(){
return 'value';
});

should(value).equal('value');
});

it('Should get correctly', function(){
should(b_.get({one: 1}, 'one')).be.equal(1);
});

it('Should not allow deep gets', function(){
should.throws(function(){
b_.get({one: { two: 2 }}, 'one.two')
});
});

function safeif(value, cb){
b_.else(function() {
b_.if(function() {
return b_.else(function() {
b_.if(value, function() {
cb(b_.null);
});
}) === undefined;
});

cb(b_.true);
});
}

it('Positive if should return null', function(done){
safeif(true, function(value){
return value === b_.null ? done() : done(new Error('Positive i value: '+value))
});
});

it('Negative if should return true', function(done){
safeif(false, function(value){
return value === b_.true ? done() : done(new Error('Incorrect value: '+value))
});
});

it('Should switch normally', function(done){
b_.switch('test', done)
.eval('test');
});

it('Should switch normally with inverse', function(done){
b_.switch('test')
.case('test', done)
.eval();
});

it('Should catch any errors in switch', function(){
b_.switch('test')
.case('test', function(){
throw new Error('I fucked up');
})
.eval();
});

it('Should throw exception if default case', function(){
should.throws(function(){
b_.switch('default')
.case('test', function(){})
.eval();
});
});

it('Should fallthrough cases', function(done){
b_.switch('test')
.case('test', noop)
.case('fall', done)
.eval();
});

it('Should call each case that matches', function(){
var count = 0;
b_.switch('test')
.case('test', function(){
++count;
return null;
})
.case('test', function(){
++count;
return null;
})
.eval();

should(count).equal(2);
});

it('Should handle default case', function(done){
b_.switch('test')
.eval(undefined, done);
});

it('Should handle falling through and hitting all cases', function(){
var count = 0;
b_.switch(0)
.case(0, function(){++count;})
.case(1, function(){++count; return null})
.case(0, function(){++count;})
.eval();

should(count).equal(3);
});

it('Should handle function fallthroughs', function(done){
b_.switch(0)
.case(0, noop)
.case(done)
.eval();
});
});
mocha.run();
165 changes: 165 additions & 0 deletions tests/core.test.js
@@ -0,0 +1,165 @@
var b_ = require('../index.js'),
should = require('should');

function noop(){}

describe('Tests', function(){

it('Should Do If', function(done){
b_.if(b_.true, function(){
done();
});
});

it('Should be completely asynchronous', function(done){
var sync = b_.false;

b_.if(b_.true, function(){
sync = b_.true;
});

if(sync)
done();
else
done(new Error('Asynchronous'));
});

it('If Should not explode if Falsey value if given', function(){
b_.if(b_.false, b_.false);
b_.if(b_.false, b_.true);
});

it('If Should explode if Falsey value if given and silent is false', function(){
should.throws(function(){b_.if(b_.false)});
});

it('Should catch if silently', function(done){
b_.if(function(){
return b_.else(function(){
b_.if(b_.false, function(){
done(new Error("This shouldn't be called"));
})
}) === b_.undefined;
}, function(){ done(); });
});

it('Should return value', function(){
var value = b_.if(b_.true, function(){
return 'value';
});

should(value).equal('value');
});

it('Should get correctly', function(){
should(b_.get({one: 1}, 'one')).be.equal(1);
});

it('Should not allow deep gets', function(){
should.throws(function(){
b_.get({one: { two: 2 }}, 'one.two')
});
});

function safeif(value, cb){
b_.else(function() {
b_.if(function() {
return b_.else(function() {
b_.if(value, function() {
cb(b_.null);
});
}) === undefined;
});

cb(b_.true);
});
}

it('Positive if should return null', function(done){
safeif(true, function(value){
return value === b_.null ? done() : done(new Error('Positive i value: '+value))
});
});

it('Negative if should return true', function(done){
safeif(false, function(value){
return value === b_.true ? done() : done(new Error('Incorrect value: '+value))
});
});

it('Should switch normally', function(done){
b_.switch('test', done)
.eval('test');
});

it('Should switch normally with inverse', function(done){
b_.switch('test')
.case('test', done)
.eval();
});

it('Should catch any errors in switch', function(){
b_.switch('test')
.case('test', function(){
throw new Error('I fucked up');
})
.eval();
});

it('Should throw exception if default case', function(){
should.throws(function(){
b_.switch('default')
.case('test', function(){})
.eval();
});
});

it('Should fallthrough cases', function(done){
b_.switch('test')
.case('test', noop)
.case('fall', done)
.eval();
});

it('Should call each case that matches', function(){
var count = 0;
b_.switch('test')
.case('test', function(){
++count;
return null;
})
.case('test', function(){
++count;
return null;
})
.eval();

should(count).equal(2);
});

it('Should handle default case', function(done){
b_.switch('test')
.eval(undefined, done);
});

it('Should handle falling through and hitting all cases', function(){
var count = 0;
b_.switch(0)
.case(0, function(){++count;})
.case(1, function(){++count; return null})
.case(0, function(){++count;})
.eval();

should(count).equal(3);
});

it('Should handle function fallthroughs', function(done){
b_.switch(0)
.case(0, noop)
.case(done)
.eval();
});

b_.switch(0)
.case
});

0 comments on commit e01819a

Please sign in to comment.