reign
Version:
A persistent, typed-objects implementation.
107 lines (85 loc) • 3.07 kB
JavaScript
;
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; };
describeRealm('Builtin: Boolean', function (options) {
var realm = void 0;
var backing = void 0;
var T = void 0;
var address = void 0;
before(function () {
realm = options.realm;
backing = realm.backing;
T = realm.T;
address = backing.alloc(T.Boolean.byteLength);
});
after(function () {
backing.free(address);
});
describe('Cast', function () {
it('should return an empty value for empty input', function () {
T.Boolean().should.equal(false);
});
it('should cast a number', function () {
T.Boolean(258).should.equal(true);
});
it('should cast a string', function () {
T.Boolean("123").should.equal(true);
});
it('should cast an empty string', function () {
T.Boolean("").should.equal(false);
});
});
it('should not create a new instance', function () {
(function () {
return new T.Boolean(true);
}).should.throw(TypeError);
});
describe('.emptyValue()', function () {
it('should return an empty value', function () {
T.Boolean.emptyValue().should.equal(false);
});
});
describe('.randomValue()', function () {
it('should return a random value', function () {
var value = T.Boolean.randomValue();
(typeof value === 'undefined' ? 'undefined' : _typeof(value)).should.equal('boolean');
});
it('should accept a random value', function () {
T.Boolean.accepts(T.Boolean.randomValue()).should.equal(true);
});
});
describe('.initialize(), .store(), .load() and .clear()', function () {
var input = void 0;
before(function () {
input = true;
});
it('should initialize an address', function () {
T.Boolean.initialize(backing, address);
});
it('should load an empty value from a just-initialized address', function () {
T.Boolean.load(backing, address).should.equal(false);
});
it('should store a value at an address', function () {
T.Boolean.store(backing, address, input);
});
it('should load a value from an address', function () {
T.Boolean.load(backing, address).should.equal(input);
});
it('should clear a value from an address', function () {
T.Boolean.clear(backing, address);
});
it('should load an empty value from a cleaned up address', function () {
(T.Boolean.load(backing, address) === false).should.equal(true);
});
});
describe('.hashValue()', function () {
it('should hash a value', function () {
T.Boolean.hashValue(123).should.be.above(-1);
});
it('should hash a true value', function () {
T.Boolean.hashValue(true).should.be.above(-1);
});
it('should hash an empty value', function () {
T.Boolean.hashValue(T.Boolean.emptyValue()).should.be.above(-1);
});
});
});