|
| 1 | +// Pull in the helper to make sure we're tracking coverage |
| 2 | +var helper = require('./helper'), |
| 3 | + expect = require('expect.js') |
| 4 | + |
| 5 | +var types = require('../lib/types') |
| 6 | + |
| 7 | +describe('Type-system', function () { |
| 8 | + var rootObject = new types.Object('fake') |
| 9 | + rootObject.supertype = null |
| 10 | + rootObject.isRoot = true |
| 11 | + |
| 12 | + describe('given an Object', function () { |
| 13 | + var object = null |
| 14 | + it('should be constructed correctly', function () { |
| 15 | + object = new types.Object(rootObject) |
| 16 | + expect(object.supertype).to.eql(rootObject) |
| 17 | + expect(object.properties).to.eql({}) |
| 18 | + expect(object.initializers).to.eql([]) |
| 19 | + }) |
| 20 | + it('should throw an error on missing property', function () { |
| 21 | + expect(function () { |
| 22 | + var type = object.getTypeOfProperty('missing') |
| 23 | + }).to.throwException() |
| 24 | + }) |
| 25 | + var Number = new types.Number(rootObject) |
| 26 | + it('should create a property', function () { |
| 27 | + object.setTypeOfProperty('present', Number) |
| 28 | + }) |
| 29 | + it('should get that property', function () { |
| 30 | + var type = object.getTypeOfProperty('present') |
| 31 | + expect(type).to.eql(Number) |
| 32 | + }) |
| 33 | + }) |
| 34 | + |
| 35 | + describe('given a Function', function () { |
| 36 | + var fn = null, |
| 37 | + Number = new types.Number(rootObject), |
| 38 | + String = new types.String(rootObject) |
| 39 | + it('should be constructed correctly', function () { |
| 40 | + fn = new types.Function(rootObject, [Number], String) |
| 41 | + expect(fn.args.length).to.eql(1) |
| 42 | + expect(fn.args[0]).to.eql(Number) |
| 43 | + expect(fn.ret).to.eql(String) |
| 44 | + }) |
| 45 | + it('should not equal non-Function type', function () { |
| 46 | + expect(fn.equals(Number)).to.be(false) |
| 47 | + }) |
| 48 | + it('should not equal Function with different number of arguments', function () { |
| 49 | + var otherFn = new types.Function(rootObject, [], String) |
| 50 | + expect(fn.equals(otherFn)).to.be(false) |
| 51 | + }) |
| 52 | + it('should not equal Function with different types of arguments', function () { |
| 53 | + var otherFn = new types.Function(rootObject, [String], String) |
| 54 | + expect(fn.equals(otherFn)).to.be(false) |
| 55 | + }) |
| 56 | + it('should not equal Function with different return type', function () { |
| 57 | + var otherFn = new types.Function(rootObject, [Number], Number) |
| 58 | + expect(fn.equals(otherFn)).to.be(false) |
| 59 | + }) |
| 60 | + }) |
| 61 | +}) |
| 62 | + |
0 commit comments