get-pattern-from-exemplar.test.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. var assert = require('assert');
  2. var rttc = require('../');
  3. describe('.getPatternFromExemplar()', function() {
  4. it('should return the pattern from single-item array exemplars', function() {
  5. assert.strictEqual(rttc.getPatternFromExemplar(['foo']), 'foo');
  6. assert.strictEqual(rttc.getPatternFromExemplar(['']), '');
  7. assert.strictEqual(rttc.getPatternFromExemplar([2323]), 2323);
  8. assert.strictEqual(rttc.getPatternFromExemplar([0]), 0);
  9. assert.strictEqual(rttc.getPatternFromExemplar([true]), true);
  10. assert.strictEqual(rttc.getPatternFromExemplar([false]), false);
  11. assert.deepEqual(rttc.getPatternFromExemplar([[]]), []);
  12. assert.deepEqual(rttc.getPatternFromExemplar([{}]), {});
  13. assert.deepEqual(rttc.getPatternFromExemplar([{x:30,y:40}]), {x:30,y:40});
  14. assert.deepEqual(rttc.getPatternFromExemplar(['*']), '*');
  15. assert.deepEqual(rttc.getPatternFromExemplar(['->']), '->');
  16. assert.deepEqual(rttc.getPatternFromExemplar(['===']), '===');
  17. // A few deep test cases just to mix things up.
  18. assert.deepEqual(rttc.getPatternFromExemplar([[{x:30,y:40}]]), [{x:30,y:40}]);
  19. assert.deepEqual(rttc.getPatternFromExemplar([['===']]), ['===']);
  20. assert.deepEqual(rttc.getPatternFromExemplar([[[false]]]), [[false]]);
  21. assert.deepEqual(rttc.getPatternFromExemplar([[[{x:30, y:40, otherCoordinates: [{x:100,y:200,z:-300.5}]}]]]), [[{x:30, y:40, otherCoordinates: [{x:100,y:200,z:-300.5}]}]]);
  22. });
  23. it('should return "*" given [] (because [] is really just the same thing as ["*"])', function() {
  24. assert.strictEqual(rttc.getPatternFromExemplar([]), '*');
  25. });
  26. it('should throw if given a multi-item array', function() {
  27. assert.throws(function (){
  28. rttc.getPatternFromExemplar(['a','b','c']);
  29. });
  30. });
  31. it('should throw if given a non-array', function() {
  32. assert.throws(function (){
  33. rttc.getPatternFromExemplar({x:292, y:-49});
  34. });
  35. });
  36. });