Brak opisu

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /* global describe, it */
  2. var assert = require('assert');
  3. var changeCase = require('./');
  4. describe('change case', function () {
  5. it('should convert to lower case', function () {
  6. assert.equal(changeCase.lower('test'), 'test');
  7. assert.equal(changeCase.lowerCase('TEST'), 'test');
  8. });
  9. it('should convert to upper case', function () {
  10. assert.equal(changeCase.upper('TEST'), 'TEST');
  11. assert.equal(changeCase.upperCase('test'), 'TEST');
  12. });
  13. it('should upper case the first character', function () {
  14. assert.equal(changeCase.ucFirst('TEST'), 'TEST');
  15. assert.equal(changeCase.upperCaseFirst('test'), 'Test');
  16. });
  17. it('should determine whether a string is all upper case or not', function () {
  18. assert.equal(changeCase.isUpper('ALLUPPERCASE'), true);
  19. assert.equal(changeCase.isUpperCase('NotAllUpperCase'), false);
  20. assert.equal(changeCase.isUpperCase('alllowercase'), false);
  21. });
  22. it('should determine whether a string is all upper case or not', function () {
  23. assert.equal(changeCase.isLower('ALLUPPERCASE'), false);
  24. assert.equal(changeCase.isLowerCase('NotAllLowerCase'), false);
  25. assert.equal(changeCase.isLowerCase('alllowercase'), true);
  26. });
  27. it('should convert to title case', function () {
  28. assert.equal(changeCase.title('a test sentence'), 'A Test Sentence');
  29. assert.equal(changeCase.titleCase('i found a bug'), 'I Found A Bug');
  30. assert.equal(changeCase.titleCase('some things\''), 'Some Things');
  31. assert.equal(changeCase.titleCase('"quotes"'), 'Quotes');
  32. assert.equal(changeCase.titleCase('hyphen-ness'), 'Hyphen Ness');
  33. });
  34. it('should convert to sentence case', function () {
  35. assert.equal(changeCase.sentence('a-simple-test'), 'a simple test');
  36. assert.equal(changeCase.sentenceCase('this is a test'), 'this is a test');
  37. assert.equal(changeCase.sentenceCase('this_is_a_test'), 'this is a test');
  38. assert.equal(changeCase.sentenceCase('this-is-a-test'), 'this is a test');
  39. });
  40. it('should convert to camel case', function () {
  41. assert.equal(changeCase.camel('TestString'), 'testString');
  42. assert.equal(changeCase.camelCase('Test String'), 'testString');
  43. assert.equal(changeCase.camelCase('Test_String'), 'testString');
  44. assert.equal(changeCase.camelCase('Test-String'), 'testString');
  45. assert.equal(changeCase.camelCase('Facebook API'), 'facebookApi');
  46. assert.equal(changeCase.camelCase('-webkit-transform'), 'webkitTransform');
  47. assert.equal(changeCase.camelCase('fooBarBaz'), 'fooBarBaz');
  48. assert.equal(changeCase.camelCase('some (things)'), 'someThings');
  49. });
  50. it('should convert to pascal case', function () {
  51. assert.equal(changeCase.pascal('testString'), 'TestString');
  52. assert.equal(changeCase.pascalCase('Test String'), 'TestString');
  53. assert.equal(changeCase.pascalCase('Test_String'), 'TestString');
  54. assert.equal(changeCase.pascalCase('Test-String'), 'TestString');
  55. assert.equal(changeCase.pascalCase('Facebook API'), 'FacebookApi');
  56. assert.equal(changeCase.pascalCase('a-test-again'), 'ATestAgain');
  57. assert.equal(changeCase.pascalCase('a---better__test'), 'ABetterTest');
  58. });
  59. it('should convert to snake case', function () {
  60. assert.equal(changeCase.snake('testString'), 'test_string');
  61. assert.equal(changeCase.snakeCase('Test String'), 'test_string');
  62. assert.equal(changeCase.snakeCase('Test_String'), 'test_string');
  63. assert.equal(changeCase.snakeCase('Test-String'), 'test_string');
  64. assert.equal(changeCase.snakeCase('a---better__test'), 'a_better_test');
  65. });
  66. it('should convert to param case', function () {
  67. assert.equal(changeCase.param('testString'), 'test-string');
  68. assert.equal(changeCase.paramCase('Test String'), 'test-string');
  69. assert.equal(changeCase.paramCase('Test_String'), 'test-string');
  70. assert.equal(changeCase.paramCase('Test-String'), 'test-string');
  71. assert.equal(changeCase.paramCase('a---better__test'), 'a-better-test');
  72. });
  73. it('should convert to constant case', function () {
  74. assert.equal(changeCase.constant('testString'), 'TEST_STRING');
  75. assert.equal(changeCase.constantCase('Test String'), 'TEST_STRING');
  76. assert.equal(changeCase.constantCase('Test_String'), 'TEST_STRING');
  77. assert.equal(changeCase.constantCase('Test-String'), 'TEST_STRING');
  78. assert.equal(changeCase.constantCase('a---better__test'), 'A_BETTER_TEST');
  79. });
  80. it('should convert to dot case', function () {
  81. assert.equal(changeCase.dot('testString'), 'test.string');
  82. assert.equal(changeCase.dotCase('Test String'), 'test.string');
  83. assert.equal(changeCase.dotCase('Test_String'), 'test.string');
  84. assert.equal(changeCase.dotCase('Test-String'), 'test.string');
  85. assert.equal(changeCase.dotCase('a---better__test'), 'a.better.test');
  86. });
  87. it('should convert to path case', function () {
  88. assert.equal(changeCase.path('testString'), 'test/string');
  89. assert.equal(changeCase.pathCase('Test String'), 'test/string');
  90. assert.equal(changeCase.pathCase('Test_String'), 'test/string');
  91. assert.equal(changeCase.pathCase('Test-String'), 'test/string');
  92. assert.equal(changeCase.pathCase('a---better__test'), 'a/better/test');
  93. });
  94. it('should swap the cases', function () {
  95. assert.equal(changeCase.swap('RaNdOMcasE'), 'rAnDomCASe');
  96. assert.equal(changeCase.swapCase('mIX It.Down?'), 'Mix iT.dOWN?');
  97. });
  98. });