Permalink
Browse files

Merge pull request #27 from XadillaX/feature/boolean

Feature/boolean
  • Loading branch information...
XadillaX committed Nov 2, 2015
2 parents 3ae37d2 + 60a95d2 commit fca5f18744227d2d92b6d7cb0dbfad6959c6e75a
Showing with 104 additions and 219 deletions.
  1. +45 −0 lib/fieldType/boolean.js
  2. +2 −0 lib/fieldType/index.js
  3. +0 −219 npm-shrinkwrap.json
  4. +57 −0 test/field.js
@@ -0,0 +1,45 @@
/**
* XadillaX created at 2015-11-02 10:40:53 With ♥
*
* Copyright (c) 2015 Souche.com, all rights
* reserved.
*/
"use strict";

var _Boolean = {};
_Boolean.name = "_Boolean";
_Boolean.needQuotes = false;

/**
* restore
* @param {_Boolean} parsed the parsed integer
* @return {Number} the integer restored
*/
_Boolean.restore = function(parsed) {
return (parsed ^ 0) & 1;
};

/**
* parse
* @param {Number} orig the original integer
* @return {_Boolean} the boolean value
*/
_Boolean.parse = function(orig) {
return !!orig;
};

_Boolean.defaultValue = 0;

/**
* equal
* @param {Number|Boolean} a integer I
* @param {Number|Boolean} b integer II
* @return {Boolean} whether they are equal
*/
_Boolean.equal = function(a, b) {
a = !!a;
b = !!b;
return a === b;
};

module.exports = _Boolean;
@@ -7,13 +7,15 @@
"use strict";

var _String = require("./string");
var _Boolean = require("./boolean");
var Integer = require("./integer");
var Float = require("./float");
var Json = require("./json");
var Datetime = require("./datetime");

module.exports = {
String : _String,
Boolean : _Boolean,
Integer : Integer,
Float : Float,
Json : Json,

This file was deleted.

Oops, something went wrong.
@@ -48,6 +48,63 @@ describe("Field",function () {
});
});
});

describe("Boolean type", function () {
var _Boolean = field.Boolean;
describe("#restore", function () {
it("arg Integer", function () {
(_Boolean.restore(1)).should.equal(1);
(_Boolean.restore(-1)).should.equal(1);
});
it("arg Float", function () {
(_Boolean.restore(1.1)).should.equal(1);
(_Boolean.restore(-1.1)).should.equal(1);
});
it("arg string", function () {
(_Boolean.restore("1.441")).should.equal(1);
(_Boolean.restore("-1.1")).should.equal(1);
(_Boolean.restore("-1")).should.equal(1);
(_Boolean.restore("1")).should.equal(1);
});
it("arg boolean", function() {
(_Boolean.restore(true)).should.equal(1);
(_Boolean.restore(false)).should.equal(0);
});
});
describe("#parse", function () {
it("arg Integer", function () {
(_Boolean.parse(1)).should.equal(true);
(_Boolean.parse(-1)).should.equal(true);
(_Boolean.parse(0)).should.equal(false);
});
it("arg Float", function () {
(_Boolean.parse(1.1)).should.equal(true);
(_Boolean.parse(-1.1)).should.equal(true);
});
it("arg string", function () {
(_Boolean.parse("1.441")).should.equal(true);
(_Boolean.parse("-1.1")).should.equal(true);
(_Boolean.parse("-1")).should.equal(true);
});
});
describe("#equal", function () {
it("should return true", function () {
(_Boolean.equal("123.1", 123)).should.be.true;
(_Boolean.equal(123.1, 123)).should.be.true;
(_Boolean.equal(0, 0)).should.be.true;
(_Boolean.equal("-1", -1)).should.be.true;
(_Boolean.equal(-1.1, -1)).should.be.true;
});
it("should return false", function () {
(_Boolean.equal("124.1", false)).should.not.be.true;
(_Boolean.equal(124.1, "")).should.not.be.true;
(_Boolean.equal(3, 0)).should.not.be.true;
(_Boolean.equal(true, false)).should.not.be.true;
(_Boolean.equal(true, 0)).should.not.be.true;
});
});
});

describe("Integer type", function () {
var Integer = field.Integer;
describe("#restore", function () {

0 comments on commit fca5f18

Please sign in to comment.