get-default-exemplar.test.js 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. var util = require('util');
  2. var assert = require('assert');
  3. var _ = require('@sailshq/lodash');
  4. var rttc = require('../');
  5. describe('.getDefaultExemplar()', function() {
  6. it('should generate correct exemplars', function() {
  7. CHECK_GENERATES_CORRECT_EXEMPLARS('getDefaultExemplar');
  8. });
  9. it('should generate correct exemplars when using `.exemplar()` alias', function() {
  10. CHECK_GENERATES_CORRECT_EXEMPLARS('exemplar');
  11. });
  12. });
  13. // Helpers:
  14. function CHECK_GENERATES_CORRECT_EXEMPLARS (methodName) {
  15. // Top-level
  16. assert.equal(rttc[methodName]('string'), 'a string');
  17. assert.equal(rttc[methodName]('number'), 123);
  18. assert.equal(rttc[methodName]('boolean'), true);
  19. assert(_.isEqual(rttc[methodName]({}), {}));
  20. assert(_.isEqual(rttc[methodName]([]), []));
  21. assert.equal(rttc[methodName]('json'), '*');
  22. assert.equal(rttc[methodName]('lamda'), '->');
  23. assert.equal(rttc[methodName]('ref'), '===');
  24. // Facted dictionary
  25. assert(_.isEqual(rttc[methodName]({x: 'string'}), {x:'a string'}));
  26. assert(_.isEqual(rttc[methodName]({x:'number'}), {x:123}));
  27. assert(_.isEqual(rttc[methodName]({x:'boolean'}), {x:true}));
  28. assert(_.isEqual(rttc[methodName]({x:{}}), {x:{}}));
  29. assert(_.isEqual(rttc[methodName]({x:[]}), {x:[]}));
  30. assert(_.isEqual(rttc[methodName]({x:'json'}), {x:'*'}));
  31. assert(_.isEqual(rttc[methodName]({x:'lamda'}), {x:'->'}));
  32. assert(_.isEqual(rttc[methodName]({x:'ref'}), {x:'==='}));
  33. // Patterned array
  34. assert(_.isEqual(rttc[methodName](['string']), ['a string']));
  35. assert(_.isEqual(rttc[methodName](['number']), [123]));
  36. assert(_.isEqual(rttc[methodName](['boolean']), [true]));
  37. assert(_.isEqual(rttc[methodName]([{}]), [{}]));
  38. assert(_.isEqual(rttc[methodName]([[]]), [[]]));
  39. assert(_.isEqual(rttc[methodName](['json']), ['*']));
  40. assert(_.isEqual(rttc[methodName](['lamda']), ['->']));
  41. assert(_.isEqual(rttc[methodName](['ref']), ['===']));
  42. // Patterned array in faceted dictionary
  43. assert(_.isEqual(rttc[methodName]({x:['string']}), {x:['a string']}));
  44. assert(_.isEqual(rttc[methodName]({x:['number']}), {x:[123]}));
  45. assert(_.isEqual(rttc[methodName]({x:['boolean']}), {x:[true]}));
  46. assert(_.isEqual(rttc[methodName]({x:[{}]}), {x:[{}]}));
  47. assert(_.isEqual(rttc[methodName]({x:[[]]}), {x:[[]]}));
  48. assert(_.isEqual(rttc[methodName]({x:['json']}), {x:['*']}));
  49. assert(_.isEqual(rttc[methodName]({x:['lamda']}), {x:['->']}));
  50. assert(_.isEqual(rttc[methodName]({x:['ref']}), {x:['===']}));
  51. // Faceted dictionary in patterned array
  52. assert(_.isEqual(rttc[methodName]([{x: 'string'}]), [{x:'a string'}]));
  53. assert(_.isEqual(rttc[methodName]([{x:'number'}]), [{x:123}]));
  54. assert(_.isEqual(rttc[methodName]([{x:'boolean'}]), [{x:true}]));
  55. assert(_.isEqual(rttc[methodName]([{x:{}}]), [{x:{}}]));
  56. assert(_.isEqual(rttc[methodName]([{x:[]}]), [{x:[]}]));
  57. assert(_.isEqual(rttc[methodName]([{x:'json'}]), [{x:'*'}]));
  58. assert(_.isEqual(rttc[methodName]([{x:'lamda'}]), [{x:'->'}]));
  59. assert(_.isEqual(rttc[methodName]([{x:'ref'}]), [{x:'==='}]));
  60. }