key-combo.spec.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. var assert = require('assert');
  2. var KeyCombo = require('../lib/key-combo');
  3. describe('KeyCombo', function() {
  4. describe('.parseComboStr', function() {
  5. it('can parse combo strings', function() {
  6. var comboArr = KeyCombo.parseComboStr('a + b');
  7. assert.equal(comboArr[0][0], 'a');
  8. assert.equal(comboArr[0][1], 'b');
  9. });
  10. it('can parse combo strings containing combo deliminators', function() {
  11. var comboArr = KeyCombo.parseComboStr('a + b > c + d');
  12. assert.equal(comboArr[0][0], 'a');
  13. assert.equal(comboArr[0][1], 'b');
  14. assert.equal(comboArr[1][0], 'c');
  15. assert.equal(comboArr[1][1], 'd');
  16. });
  17. it('can parse combo strings containing sequence deliminators');
  18. });
  19. describe('#check', function() {
  20. it('can check the combo against an array of key names', function() {
  21. var keyCombo1 = new KeyCombo('a + b');
  22. var keyCombo2 = new KeyCombo('a + \\+');
  23. assert.ok(keyCombo1.check(['a', 'b']));
  24. assert.ok(keyCombo1.check(['b', 'a']));
  25. assert.ok(keyCombo1.check(['a', 'b', 'c']));
  26. assert.ok(keyCombo1.check(['z', 'a', 'b']));
  27. assert.ok(keyCombo1.check(['z', 'a', 'b', 'c']));
  28. assert.ok(keyCombo2.check(['a', '+']));
  29. });
  30. it('can check the combo containing combo deliminators against an array of key names', function() {
  31. var keyCombo = new KeyCombo('a + b > c + d');
  32. assert.ok(keyCombo.check(['a', 'b', 'c', 'd']));
  33. assert.ok(keyCombo.check(['b', 'a', 'd', 'c']));
  34. assert.ok(keyCombo.check(['a', 'b', 'e', 'c', 'd', 'f']));
  35. assert.ok(keyCombo.check(['z', 'a', 'b', 'y', 'c', 'd']));
  36. assert.ok(keyCombo.check(['z', 'a', 'b', 'y', 'x', 'c', 'd', 'w']));
  37. assert.equal(keyCombo.check(['c', 'd', 'a', 'b']), false);
  38. assert.equal(keyCombo.check(['d', 'c', 'b', 'a']), false);
  39. });
  40. it('can check the combo containing sequence deliminators against an array of key names');
  41. });
  42. describe('#isEqual', function() {
  43. it('can correctly equate two the combo to a given one', function() {
  44. var keyCombo1 = new KeyCombo('a + b');
  45. var keyCombo2 = new KeyCombo('a + b');
  46. var keyCombo3 = new KeyCombo('b + a');
  47. var keyCombo4 = new KeyCombo('a + b + c');
  48. var keyCombo5 = new KeyCombo('a > b');
  49. assert.ok(keyCombo1.isEqual(keyCombo2));
  50. assert.ok(keyCombo1.isEqual(keyCombo3));
  51. assert.equal(keyCombo1.isEqual(keyCombo4), false);
  52. assert.equal(keyCombo1.isEqual(keyCombo5), false);
  53. });
  54. });
  55. });