UNPKG

reign

Version:

A persistent, typed-objects implementation.

181 lines (142 loc) 5.03 kB
'use strict'; var _ = require('./'); describe('TypeClass', function () { var TypeClass = void 0; before(function () { TypeClass = (0, _.make)({}); }); describe('PrimitiveType', function () { var PrimitiveType = void 0; var Double = void 0; var instance = void 0; before(function () { var prot = { baz: function baz() { return 'qux'; } }; Object.setPrototypeOf(prot, _.TypedObject.prototype); PrimitiveType = new TypeClass('PrimitiveType', function (config) { return { name: config.name, constructor: function constructor() {}, prototype: Object.create(prot, { foo: { value: function value() { return 'bar'; } } }), byteAlignment: config.byteAlignment, byteLength: config.byteLength }; }); }); it('should create a new TypeClass instance', function () { PrimitiveType.should.be.an.instanceOf(TypeClass); }); it('PrimitiveType should be an instance of Function', function () { PrimitiveType.should.be.an.instanceOf(Function); }); it('should create a new primitive type', function () { Double = new PrimitiveType({ name: 'Double', byteAlignment: 8, byteLength: 8 }); }); it('Double should be an instance of PrimitiveType', function () { Double.should.be.an.instanceOf(PrimitiveType); }); it('Double should be an instance of Function', function () { Double.should.be.an.instanceOf(Function); }); it('Double should not be an instance of TypeClass', function () { Double.should.not.be.an.instanceOf(TypeClass); }); it('Double should not be an instance of TypedObject', function () { Double.should.not.be.an.instanceOf(_.TypedObject); }); it('should create an instance of Double', function () { instance = new Double(); instance.should.be.an.instanceOf(Double); }); it('instance should be an instance of TypedObject', function () { instance.should.be.an.instanceOf(_.TypedObject); }); it('should inherit prototype methods', function () { instance.foo().should.equal('bar'); }); it('should inherit deeper prototype methods', function () { instance.baz().should.equal('qux'); }); }); describe('ArrayType', function () { var ArrayType = void 0; var User = void 0; var UserArrayType = void 0; var UserArray = void 0; var instance = void 0; before(function () { User = { name: 'User' }; ArrayType = new TypeClass('ArrayType', function (ElementType) { var TypedArray$prototype = {}; Object.setPrototypeOf(TypedArray$prototype, _.TypedObject.prototype); return new TypeClass('Array<' + ElementType.name + '>', function (length) { var FixedLengthArray$prototype = Object.create(TypedArray$prototype, { length: { enumerable: true, value: length } }); return { name: 'Array<' + ElementType.name + '>(' + length + ')', constructor: function constructor() {}, prototype: FixedLengthArray$prototype }; }); }); }); it('ArrayType should be an instance of TypeClass', function () { ArrayType.should.be.an.instanceOf(TypeClass); }); it('ArrayType should be an instance of Function', function () { ArrayType.should.be.an.instanceOf(Function); }); it('should define a UserArrayType', function () { UserArrayType = new ArrayType(User); }); it('UserArrayType should be an instance of ArrayType', function () { UserArrayType.should.be.an.instanceOf(ArrayType); }); it('UserArrayType should be an instance of Function', function () { UserArrayType.should.be.an.instanceOf(Function); }); it('should define a UserArray', function () { UserArray = new UserArrayType(123); }); it('UserArray should be an instance of UserArrayType', function () { UserArray.should.be.an.instanceOf(UserArrayType); }); it('UserArray should be an instance of Function', function () { UserArray.should.be.an.instanceOf(Function); }); it('should instantiate a UserArray', function () { instance = new UserArray(); }); it('instance should be an instance of UserArray', function () { instance.should.be.an.instanceOf(UserArray); }); it('instance should be an instance of TypedObject', function () { instance.should.be.an.instanceOf(_.TypedObject); }); it('UserArrayType should still be an instance of ArrayType', function () { UserArrayType.should.be.an.instanceOf(ArrayType); }); it('UserArray should still be an instance of UserArrayType', function () { UserArray.should.be.an.instanceOf(UserArrayType); }); }); });