inflections-test.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. (function() {
  2. var assert, vows;
  3. vows = require('vows');
  4. assert = require('assert');
  5. vows.describe('Module Inflector inflections').addBatch({
  6. 'Test inflector inflections': {
  7. topic: require('../../lib/inflections'),
  8. 'clear': {
  9. 'single': function(topic) {
  10. topic.uncountables = [1, 2, 3];
  11. topic.humans = [1, 2, 3];
  12. topic.clear('uncountables');
  13. assert.isEmpty(topic.uncountables);
  14. return assert.deepEqual(topic.humans, [1, 2, 3]);
  15. },
  16. 'all': function(topic) {
  17. assert.deepEqual(topic.humans, [1, 2, 3]);
  18. topic.uncountables = [1, 2, 3];
  19. topic.clear();
  20. assert.isEmpty(topic.uncountables);
  21. return assert.isEmpty(topic.humans);
  22. }
  23. },
  24. 'uncountable': {
  25. 'one item': function(topic) {
  26. topic.clear();
  27. assert.isEmpty(topic.uncountables);
  28. topic.uncountable('money');
  29. return assert.deepEqual(topic.uncountables, ['money']);
  30. },
  31. 'many items': function(topic) {
  32. topic.clear();
  33. assert.isEmpty(topic.uncountables);
  34. topic.uncountable(['money', 'rice']);
  35. return assert.deepEqual(topic.uncountables, ['money', 'rice']);
  36. }
  37. },
  38. 'human': function(topic) {
  39. topic.clear();
  40. assert.isEmpty(topic.humans);
  41. topic.human("legacy_col_person_name", "Name");
  42. return assert.deepEqual(topic.humans, [["legacy_col_person_name", "Name"]]);
  43. },
  44. 'plural': function(topic) {
  45. topic.clear();
  46. assert.isEmpty(topic.plurals);
  47. topic.plural('ox', 'oxen');
  48. assert.deepEqual(topic.plurals, [['ox', 'oxen']]);
  49. topic.uncountable('money');
  50. assert.deepEqual(topic.uncountables, ['money']);
  51. topic.uncountable('monies');
  52. topic.plural('money', 'monies');
  53. assert.deepEqual(topic.plurals, [['money', 'monies'], ['ox', 'oxen']]);
  54. return assert.isEmpty(topic.uncountables);
  55. },
  56. 'singular': function(topic) {
  57. topic.clear();
  58. assert.isEmpty(topic.singulars);
  59. topic.singular('ox', 'oxen');
  60. assert.deepEqual(topic.singulars, [['ox', 'oxen']]);
  61. topic.uncountable('money');
  62. assert.deepEqual(topic.uncountables, ['money']);
  63. topic.uncountable('monies');
  64. topic.singular('money', 'monies');
  65. assert.deepEqual(topic.singulars, [['money', 'monies'], ['ox', 'oxen']]);
  66. return assert.isEmpty(topic.uncountables);
  67. },
  68. 'irregular': function(topic) {
  69. topic.clear();
  70. topic.uncountable(['octopi', 'octopus']);
  71. assert.deepEqual(topic.uncountables, ['octopi', 'octopus']);
  72. topic.irregular('octopus', 'octopi');
  73. assert.isEmpty(topic.uncountables);
  74. assert.equal(topic.singulars[0][0].toString(), /(o)ctopi$/i.toString());
  75. assert.equal(topic.singulars[0][1], '$1ctopus');
  76. assert.equal(topic.plurals[0][0].toString(), /(o)ctopi$/i.toString());
  77. assert.equal(topic.plurals[0][1], '$1ctopi');
  78. assert.equal(topic.plurals[1][0].toString(), /(o)ctopus$/i.toString());
  79. return assert.equal(topic.plurals[1][1].toString(), '$1ctopi');
  80. }
  81. }
  82. })["export"](module);
  83. }).call(this);