Skip to content

Commit

Permalink
fix interfaces issues
Browse files Browse the repository at this point in the history
  • Loading branch information
fabioricali committed Jul 7, 2017
1 parent 2f2c9aa commit 03ed6b1
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Changed
- improved `be.json`
- improved `be.buffer`
- now `be.equal` support also object and array

### Fixed
- now `be.equal` with zero negative return false
- `be.all.array` failed
- `be.any.array` failed

## [1.3.1] - 2017-07-04

Expand Down
5 changes: 4 additions & 1 deletion src/asserts/mixed.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,14 +160,17 @@ Mixed.semVer = (value) => {
* be.equal({a:1}, {a:1}) // true
*/
Mixed.equal = (value, other) => {
console.log('sss',Types.all.array(value, other));
//console.log('aaa',Types.all.object(value, other));
//console.log('bbb',Types.all.array(value, other));
console.log('ccc',Types.all.number(value, other));
if(Types.all.number(value, other))
return value === other && 1 / value === 1 / other;
else if(Types.all.string(value, other) || Types.all.regexp(value, other))
return value.toString() === other.toString();
else if(Types.all.boolean(value, other))
return value === other;
else if(Types.all.object(value, other) || Types.all.array(value, other)) {
console.log('sss',Types.all.array(value, other));
if (Object.keys(value).length !== Object.keys(other).length)
return false;
for (let prop in value) {
Expand Down
5 changes: 3 additions & 2 deletions src/interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ Interface.create = (obj) => {
if (typeof obj[i].multiple === 'undefined') {
obj.all[i] = (...params) => {
let args = params;
if (Interface._isArray(args[0]))

if (Interface._isArray(args[0]) && args.length === 1)
args = args[0];

if(!args.length) return false;
Expand All @@ -69,7 +70,7 @@ Interface.create = (obj) => {

obj.any[i] = (...params) => {
let args = params;
if (Interface._isArray(args[0]))
if (Interface._isArray(args[0]) && args.length === 1)
args = args[0];

for (let a in args) {
Expand Down
47 changes: 47 additions & 0 deletions test/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,30 @@ describe('boolean', function () {
assert.equal(result, true);
});

it('boolean interface all, should be return true', function () {
var result = be.all.boolean(true, false, true);
console.log(result);
assert.equal(result, true);
});

it('boolean interface any, should be return true', function () {
var result = be.any.boolean(1, false, 1);
console.log(result);
assert.equal(result, true);
});

it('boolean array interface any, should be return true', function () {
var result = be.any.boolean([1, false, 1]);
console.log(result);
assert.equal(result, true);
});

it('boolean array interface all, should be return true', function () {
var result = be.all.boolean([true, false, true]);
console.log(result);
assert.equal(result, true);
});

it('string value, should be return false', function () {
var result = be.boolean('true');
console.log(result);
Expand Down Expand Up @@ -636,4 +660,27 @@ describe('defined_', function () {
console.log(result);
assert.equal(result, false);
});
});

describe('array_', function () {
it('should be return true', function () {
var result = be.array([1,2,3]);
console.log(result);
assert.equal(result, true);
});
it('interface all, should be return true', function () {
var result = be.all.array([1,2,3],[2,4,5]);
console.log(result);
assert.equal(result, true);
});
it('interface any, should be return true', function () {
var result = be.any.array([1,2,3],true);
console.log(result);
assert.equal(result, true);
});
it('should be return false', function () {
var result = be.array('hello');
console.log(result);
assert.equal(result, false);
});
});

0 comments on commit 03ed6b1

Please sign in to comment.