Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jonschlinkert committed Sep 26, 2015
1 parent eeebc59 commit 07a3058
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 86 deletions.
34 changes: 5 additions & 29 deletions lib/comparison.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
'use strict';

var any = require('any');
var contains = require('./utils/contains');
var isObject = require('./object').isObject;
var isString = require('./string').isString;

/**
* Expose `helpers`
Expand Down Expand Up @@ -39,7 +40,7 @@ helpers.and = function(a, b, options) {
* @api public
*/

helpers.has = function(value, pattern) {
helpers.has = function(value, pattern, options) {
if (typeof pattern === 'undefined') {
return options.inverse(this);
}
Expand All @@ -65,28 +66,6 @@ helpers.has = function(value, pattern) {
}
};

/**
* Returns `true` if a value exists in the given string, array or
* object, or if a callback is passed checks to see if a truthy
* value is returned for any element in a collection or for any
* sub-string in a string.
*
* @param {*} `val` The value to check.
* @param {*} `pattern` The pattern to check for.
* @param {Object} `options`
* @return {Boolean}
* @api public
*/

helpers.any = function(val, pattern, options) {
if (Array.isArray)
console.log(arguments)
if (any(val, pattern)) {
return options.fn(this);
}
return options.inverse(this);
};

/**
* Checks if `collection` has the given `value`, using strict
* equality (`===`) for comparisons. If `startIndex` is negative,
Expand Down Expand Up @@ -479,6 +458,8 @@ helpers.unlessLteq = function(context, options) {
* ```js
* {{ifAny this compare=that}}
* ```
* @return {String} Block, or inverse block if specified and falsey.
* @api public
*/

helpers.ifAny = function() {
Expand Down Expand Up @@ -522,8 +503,3 @@ helpers.ifEven = function(conditional, options) {
return options.inverse(this);
}
};


function isString(val) {
return val && typeof val === 'string';
}
12 changes: 12 additions & 0 deletions lib/string.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,18 @@ helpers.hyphenate = function(str) {
}
};

/**
* Return true if val is a string
*
* @param {String} `val`
* @return {Boolean}
* @api public
*/

helpers.isString = function(val) {
return val && typeof val === 'string';
};

/**
* Make all letters in the string lowercase
*
Expand Down
1 change: 0 additions & 1 deletion lib/utils/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@

'use strict';

var extend = require('extend-shallow');
var utils = require('export-files')(__dirname);

/**
Expand Down
102 changes: 46 additions & 56 deletions test/comparison.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,6 @@ helpers.comparison({handlebars: hbs});

var context = {array: ['a', 'b', 'c']};

describe('any', function() {
it('should conditionally render a block the array isn\'t empty.', function() {
var fn = hbs.compile('{{#any array "a"}}AAA{{else}}BBB{{/any}}');
fn(context).should.equal('AAA');
});

it('should render the inverse when the array is empty', function() {
var fn = hbs.compile('{{#any array "d"}}AAA{{else}}BBB{{/any}}');
fn(context).should.equal('BBB');
});
});

describe('{{compare}}', function() {
describe('{{#compare left "<=" right}}', function() {
it('should render the first block if the left value is equal or greater.', function() {
Expand All @@ -27,6 +15,7 @@ describe('{{compare}}', function() {
fn({left: 10, right: 15}).should.equal('greater than or equal to 10');
});
});

describe('{{#compare unicorns "<" ponies}}', function() {
it('should render the first block if the left value is less than the right.', function() {
var source = '{{#compare unicorns "<" ponies}}I knew it, unicorns are just low-quality ponies!{{/compare}}';
Expand All @@ -35,6 +24,7 @@ describe('{{compare}}', function() {
res.should.equal('I knew it, unicorns are just low-quality ponies!');
});
});

describe('{{#compare obj "typeof" "object"}}', function() {
it('should render the first block if the right value is an object.', function() {
var fn = hbs.compile('{{#compare obj "typeof" "object"}}an object{{else}}not an object{{/compare}}');
Expand Down Expand Up @@ -130,74 +120,74 @@ describe('{{and}}', function() {
});
});

describe('{{if_eq}}', function() {
describe('{{#if_eq number compare=8}}', function() {
describe('{{ifEq}}', function() {
describe('{{#ifEq number compare=8}}', function() {
it('should render a block if the value is equal to a given number.', function() {
var fn = hbs.compile('{{#if_eq number compare=8}}AAA{{/if_eq}}');
var fn = hbs.compile('{{#ifEq number compare=8}}AAA{{/ifEq}}');
fn({number: 8}).should.equal('AAA');
});
it('should not render a block if the value is not equal to a given number.', function() {
var fn = hbs.compile('{{#if_gt number compare=8}}AAA{{/if_gt}}');
var fn = hbs.compile('{{#ifGt number compare=8}}AAA{{/ifGt}}');
fn({number: 5}).should.equal('');
});
});
});

describe('{{if_gt}}', function() {
describe('{{#if_gt number compare=8}}', function() {
describe('{{ifGt}}', function() {
describe('{{#ifGt number compare=8}}', function() {
it('should render a block if the value is greater than a given number.', function() {
var fn = hbs.compile('{{#if_gt number compare=8}}AAA{{/if_gt}}');
var fn = hbs.compile('{{#ifGt number compare=8}}AAA{{/ifGt}}');
fn({number: 10}).should.equal('AAA');
});
it('should not render a block if the value is less than a given number.', function() {
var fn = hbs.compile('{{#if_gt number compare=8}}AAA{{/if_gt}}');
var fn = hbs.compile('{{#ifGt number compare=8}}AAA{{/ifGt}}');
fn({number: 5}).should.equal('');
});
});
});

describe('{{if_gteq}}', function() {
describe('{{#if_gteq number compare=8}}', function() {
describe('{{ifGteq}}', function() {
describe('{{#ifGteq number compare=8}}', function() {
it('should render a block if the value is greater than a given number.', function() {
var fn = hbs.compile('{{#if_gteq number compare=8}}AAA{{/if_gteq}}');
var fn = hbs.compile('{{#ifGteq number compare=8}}AAA{{/ifGteq}}');
fn({number: 12}).should.equal('AAA');
});
it('should render a block if the value is equal to a given number.', function() {
var fn = hbs.compile('{{#if_gteq number compare=8}}AAA{{/if_gteq}}');
var fn = hbs.compile('{{#ifGteq number compare=8}}AAA{{/ifGteq}}');
fn({number: 8}).should.equal('AAA');
});
it('should not render a block if the value is less than a given number.', function() {
var fn = hbs.compile('{{#if_gteq number compare=8}}AAA{{/if_gteq}}');
var fn = hbs.compile('{{#ifGteq number compare=8}}AAA{{/ifGteq}}');
fn({number: 5}).should.equal('');
});
});
});

describe('{{if_lt}}', function() {
describe('{{#if_lt number compare=8}}', function() {
describe('{{ifLt}}', function() {
describe('{{#ifLt number compare=8}}', function() {
it('should render a block if the value is less than a given number.', function() {
var fn = hbs.compile('{{#if_lt number compare=8}}AAA{{/if_lt}}');
var fn = hbs.compile('{{#ifLt number compare=8}}AAA{{/ifLt}}');
fn({number: 5}).should.equal('AAA');
});
it('should not render a block if the value is greater than a given number.', function() {
var fn = hbs.compile('{{#if_lt number compare=8}}AAA{{/if_lt}}');
var fn = hbs.compile('{{#ifLt number compare=8}}AAA{{/ifLt}}');
fn({number: 42}).should.equal('');
});
});
});

describe('{{if_lteq}}', function() {
describe('{{#if_lteq number compare=8}}', function() {
describe('{{ifLteq}}', function() {
describe('{{#ifLteq number compare=8}}', function() {
it('should render a block if the value is less than a given number.', function() {
var fn = hbs.compile('{{#if_lteq number compare=8}}AAA{{/if_lteq}}');
var fn = hbs.compile('{{#ifLteq number compare=8}}AAA{{/ifLteq}}');
fn({number: 1}).should.equal('AAA');
});
it('should render a block if the value is equal to a given number.', function() {
var fn = hbs.compile('{{#if_lteq number compare=8}}AAA{{/if_lteq}}');
var fn = hbs.compile('{{#ifLteq number compare=8}}AAA{{/ifLteq}}');
fn({number: 8}).should.equal('AAA');
});
it('should not render a block if the value is greater than a given number.', function() {
var fn = hbs.compile('{{#if_lteq number compare=8}}AAA{{/if_lteq}}');
var fn = hbs.compile('{{#ifLteq number compare=8}}AAA{{/ifLteq}}');
fn({number: 27}).should.equal('');
});
});
Expand Down Expand Up @@ -228,74 +218,74 @@ describe('{{ifNth}}', function() {
});
});

describe('{{unless_eq}}', function() {
describe('{{#unless_eq number compare=8}}', function() {
describe('{{unlessEq}}', function() {
describe('{{#unlessEq number compare=8}}', function() {
it('should render a block unless the value is equal to a given number.', function() {
var fn = hbs.compile('{{#unless_eq number compare=8}}AAA{{/unless_eq}}');
var fn = hbs.compile('{{#unlessEq number compare=8}}AAA{{/unlessEq}}');
fn({number: 10}).should.equal('AAA');
});
it('should render a block unless the value is equal to a given number.', function() {
var fn = hbs.compile('{{#unless_eq number compare=8}}AAA{{/unless_eq}}');
var fn = hbs.compile('{{#unlessEq number compare=8}}AAA{{/unlessEq}}');
fn({number: 8}).should.equal('');
});
});
});

describe('{{unless_gt}}', function() {
describe('{{#unless_gt number compare=8}}', function() {
describe('{{unlessGt}}', function() {
describe('{{#unlessGt number compare=8}}', function() {
it('should render a block unless the value is greater than a given number.', function() {
var fn = hbs.compile('{{#unless_gt number compare=8}}AAA{{/unless_gt}}');
var fn = hbs.compile('{{#unlessGt number compare=8}}AAA{{/unlessGt}}');
fn({number: 5}).should.equal('AAA');
});
it('should render a block unless the value is greater than a given number.', function() {
var fn = hbs.compile('{{#unless_gt number compare=8}}AAA{{/unless_gt}}');
var fn = hbs.compile('{{#unlessGt number compare=8}}AAA{{/unlessGt}}');
fn({number: 10}).should.equal('');
});
});
});

describe('{{unless_lt}}', function() {
describe('{{#unless_lt number compare=8}}', function() {
describe('{{unlessLt}}', function() {
describe('{{#unlessLt number compare=8}}', function() {
it('should render a block unless the value is less than a given number.', function() {
var fn = hbs.compile('{{#unless_lt number compare=8}}AAA{{/unless_lt}}');
var fn = hbs.compile('{{#unlessLt number compare=8}}AAA{{/unlessLt}}');
fn({number: 10}).should.equal('AAA');
});
it('should render a block unless the value is less than a given number.', function() {
var fn = hbs.compile('{{#unless_lt number compare=8}}AAA{{/unless_lt}}');
var fn = hbs.compile('{{#unlessLt number compare=8}}AAA{{/unlessLt}}');
fn({number: 5}).should.equal('');
});
});
});

describe('{{unless_gteq}}', function() {
describe('{{#unless_gteq number compare=8}}', function() {
describe('{{unlessGteq}}', function() {
describe('{{#unlessGteq number compare=8}}', function() {
it('should render a block unless the value is greater than or equal to a given number.', function() {
var fn = hbs.compile('{{#unless_gteq number compare=8}}AAA{{/unless_gteq}}');
var fn = hbs.compile('{{#unlessGteq number compare=8}}AAA{{/unlessGteq}}');
fn({number: 4}).should.equal('AAA');
});
it('should render a block unless the value is greater than or equal to a given number.', function() {
var fn = hbs.compile('{{#unless_gteq number compare=8}}AAA{{/unless_gteq}}');
var fn = hbs.compile('{{#unlessGteq number compare=8}}AAA{{/unlessGteq}}');
fn({number: 8}).should.equal('');
});
it('should not render a block unless the value is greater than or equal to a given number.', function() {
var fn = hbs.compile('{{#unless_gteq number compare=8}}AAA{{/unless_gteq}}');
var fn = hbs.compile('{{#unlessGteq number compare=8}}AAA{{/unlessGteq}}');
fn({number: 34}).should.equal('');
});
});
});

describe('{{unless_lteq}}', function() {
describe('{{#unless_lteq number compare=8}}', function() {
describe('{{unlessLteq}}', function() {
describe('{{#unlessLteq number compare=8}}', function() {
it('should render a block unless the value is less than or equal to a given number.', function() {
var fn = hbs.compile('{{#unless_lteq number compare=8}}AAA{{/unless_lteq}}');
var fn = hbs.compile('{{#unlessLteq number compare=8}}AAA{{/unlessLteq}}');
fn({number: 10}).should.equal('AAA');
});
it('should render a block unless the value is less than or equal to a given number.', function() {
var fn = hbs.compile('{{#unless_lteq number compare=8}}AAA{{/unless_lteq}}');
var fn = hbs.compile('{{#unlessLteq number compare=8}}AAA{{/unlessLteq}}');
fn({number: 8}).should.equal('');
});
it('should not render a block unless the value is less than or equal to a given number.', function() {
var fn = hbs.compile('{{#unless_lteq number compare=8}}AAA{{/unless_lteq}}');
var fn = hbs.compile('{{#unlessLteq number compare=8}}AAA{{/unlessLteq}}');
fn({number: 4}).should.equal('');
});
});
Expand Down

0 comments on commit 07a3058

Please sign in to comment.