string-test.js 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. (function() {
  2. var assert, vows, util;
  3. vows = require('vows');
  4. assert = require('assert');
  5. util = require('../../lib/util');
  6. vows.describe('Module core extension String').addBatch({
  7. 'Testing value': {
  8. topic: 'bullet',
  9. 'join the keys': function(topic) {
  10. return assert.equal(util.string.value(topic), 'bullet');
  11. }
  12. },
  13. 'Testing gsub': {
  14. topic: 'bullet',
  15. 'when no args': function(topic) {
  16. return assert.equal(util.string.gsub(topic), 'bullet');
  17. },
  18. 'when only 1 arg': function(topic) {
  19. return assert.equal(util.string.gsub(topic, /./), 'bullet');
  20. },
  21. 'when given proper args': function(topic) {
  22. return assert.equal(util.string.gsub(topic, /[aeiou]/, '*'), 'b*ll*t');
  23. },
  24. 'when replacement is a function': {
  25. 'with many groups': function(topic) {
  26. var str;
  27. str = util.string.gsub(topic, /([aeiou])(.)/, function($) {
  28. return "<" + $[1] + ">" + $[2];
  29. });
  30. return assert.equal(str, 'b<u>ll<e>t');
  31. },
  32. 'with no groups': function(topic) {
  33. var str;
  34. str = util.string.gsub(topic, /[aeiou]/, function($) {
  35. return "<" + $[1] + ">";
  36. });
  37. return assert.equal(str, 'b<u>ll<e>t');
  38. }
  39. },
  40. 'when replacement is special': {
  41. 'with many groups': function(topic) {
  42. return assert.equal(util.string.gsub(topic, /([aeiou])(.)/, '<$1>$2'), 'b<u>ll<e>t');
  43. },
  44. 'with no groups': function(topic) {
  45. return assert.equal(util.string.gsub(topic, /[aeiou]/, '<$1>'), 'b<u>ll<e>t');
  46. }
  47. }
  48. },
  49. 'Testing capitalize': {
  50. topic: 'employee salary',
  51. 'normal': function(topic) {
  52. return assert.equal(util.string.capitalize(topic), 'Employee Salary');
  53. }
  54. },
  55. 'Testing upcase': {
  56. topic: 'bullet',
  57. 'only first letter should be upcase': function(topic) {
  58. return assert.equal(util.string.upcase(topic), 'Bullet');
  59. },
  60. 'letter after underscore': function(topic) {
  61. return assert.equal(util.string.upcase('bullet_record'), 'Bullet_Record');
  62. },
  63. 'letter after slash': function(topic) {
  64. return assert.equal(util.string.upcase('bullet_record/errors'), 'Bullet_Record/Errors');
  65. },
  66. 'no letter after space': function(topic) {
  67. return assert.equal(util.string.upcase('employee salary'), 'Employee salary');
  68. }
  69. },
  70. 'Testing downcase': {
  71. topic: 'BULLET',
  72. 'only first letter should be downcase': function(topic) {
  73. return assert.equal(util.string.downcase(topic), 'bULLET');
  74. },
  75. 'letter after underscore': function(topic) {
  76. return assert.equal(util.string.downcase('BULLET_RECORD'), 'bULLET_rECORD');
  77. },
  78. 'letter after slash': function(topic) {
  79. return assert.equal(util.string.downcase('BULLET_RECORD/ERRORS'), 'bULLET_rECORD/eRRORS');
  80. }
  81. }
  82. })["export"](module);
  83. }).call(this);