simple-squiggle

A restricted subset of Squiggle
Log | Files | Refs | README

find.test.js (1351B)


      1 var assert = require('assert');
      2 var typed = require('../typed-function');
      3 
      4 describe('find', function () {
      5 
      6   function a () {}
      7   function b () {}
      8   function c () {}
      9   function d () {}
     10   function e () {}
     11 
     12   var fn = typed('fn', {
     13     'number': a,
     14     'string, ...number': b,
     15     'number, boolean': c,
     16     'any': d,
     17     '': e
     18   });
     19 
     20 
     21   it('should find a signature from an array with types', function() {
     22     assert.strictEqual(typed.find(fn, ['number']), a);
     23     assert.strictEqual(typed.find(fn, ['number', 'boolean']), c);
     24     assert.strictEqual(typed.find(fn, ['any']), d);
     25     assert.strictEqual(typed.find(fn, []), e);
     26 
     27   });
     28 
     29   it('should find a signature from a comma separated string with types', function() {
     30     assert.strictEqual(typed.find(fn, 'number'), a);
     31     assert.strictEqual(typed.find(fn, 'number,boolean'), c);
     32     assert.strictEqual(typed.find(fn, ' number, boolean '), c); // with spaces
     33     assert.strictEqual(typed.find(fn, 'any'), d);
     34     assert.strictEqual(typed.find(fn, ''), e);
     35   });
     36 
     37   it('should throw an error when not found', function() {
     38     assert.throws(function () {
     39       typed.find(fn, 'number, number');
     40     }, /TypeError: Signature not found \(signature: fn\(number, number\)\)/);
     41   });
     42 
     43 
     44   // TODO: implement support for matching non-exact signatures
     45   //assert.strictEqual(typed.find(fn, ['Array']), d);
     46 
     47 
     48 });