test-speakingurl.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. /* global describe,it */
  2. var getSlug = require('../lib/speakingurl');
  3. describe('getSlug config combinations', function () {
  4. 'use strict';
  5. it('should separate with configured character, with non-Base64 separator', function (done) {
  6. getSlug('Foo, Bar Baz', {
  7. separator: '*',
  8. maintainCase: false
  9. })
  10. .should.eql('foo*bar*baz');
  11. getSlug('Foo- Bar Baz', {
  12. separator: '*',
  13. maintainCase: false
  14. })
  15. .should.eql('foo-*bar*baz');
  16. getSlug('Foo] Bar Baz', {
  17. separator: '*',
  18. maintainCase: false
  19. })
  20. .should.eql('foo*bar*baz');
  21. done();
  22. });
  23. it('should separate with configured character, with only Base64 characters allowed', function (done) {
  24. getSlug('Foo, Bar Baz', {
  25. separator: '_',
  26. onlyBase64: true
  27. })
  28. .should.eql('foo_bar_baz');
  29. getSlug('Foo- Bar Baz', {
  30. separator: '_',
  31. onlyBase64: true
  32. })
  33. .should.eql('foo-_bar_baz');
  34. getSlug('Foo] Bar Baz', {
  35. separator: '_',
  36. onlyBase64: true
  37. })
  38. .should.eql('foo_bar_baz');
  39. done();
  40. });
  41. it('should separate with configured character, with smart trim', function (done) {
  42. getSlug('Foobarbaz, Bar Baz', {
  43. separator: '_',
  44. truncate: 12
  45. })
  46. .should.eql('foobarbaz');
  47. getSlug('Foobarbaz, Bar Baz', {
  48. separator: '_',
  49. truncate: 15
  50. })
  51. .should.eql('foobarbaz_bar');
  52. getSlug(' Foobarbaz, Bar Baz', {
  53. separator: '_',
  54. truncate: 15
  55. })
  56. .should.eql('foobarbaz_bar');
  57. getSlug(' Foobarbaz, Bar Baz', {
  58. separator: '_',
  59. truncate: 15
  60. })
  61. .should.eql('foobarbaz_bar');
  62. done();
  63. });
  64. it('should maintain case characters, with non-Base64 separator', function (done) {
  65. getSlug('Foo, Bar Baz', {
  66. maintainCase: true,
  67. separator: '*'
  68. })
  69. .should.eql('Foo*Bar*Baz');
  70. getSlug('Foo- Bar Baz', {
  71. maintainCase: true,
  72. separator: '*'
  73. })
  74. .should.eql('Foo-*Bar*Baz');
  75. getSlug('Foo] Bar Baz', {
  76. maintainCase: true,
  77. separator: '*'
  78. })
  79. .should.eql('Foo*Bar*Baz');
  80. done();
  81. });
  82. it('should maintain case characters, with only Base64 characters allowed', function (done) {
  83. getSlug('Foo, Bar Baz', {
  84. maintainCase: true,
  85. uric: false,
  86. uricNoSlash: false,
  87. mark: false
  88. })
  89. .should.eql('Foo-Bar-Baz');
  90. getSlug('Foo- Bar Baz', {
  91. maintainCase: true,
  92. uric: false,
  93. uricNoSlash: false,
  94. mark: false
  95. })
  96. .should.eql('Foo-Bar-Baz');
  97. getSlug('Foo] Bar Baz', {
  98. maintainCase: true,
  99. uric: false,
  100. uricNoSlash: false,
  101. mark: false
  102. })
  103. .should.eql('Foo-Bar-Baz');
  104. done();
  105. });
  106. it('should maintain case characters, with smart trim', function (done) {
  107. getSlug('Foobarbaz, Bar Baz', {
  108. maintainCase: true,
  109. truncate: 12
  110. })
  111. .should.eql('Foobarbaz');
  112. getSlug('Foobarbaz, Bar Baz', {
  113. maintainCase: true,
  114. truncate: 15
  115. })
  116. .should.eql('Foobarbaz-Bar');
  117. getSlug(' Foobarbaz, Bar Baz', {
  118. maintainCase: true,
  119. truncate: 15
  120. })
  121. .should.eql('Foobarbaz-Bar');
  122. getSlug(' Foobarbaz, Bar Baz', {
  123. maintainCase: true,
  124. truncate: 15
  125. })
  126. .should.eql('Foobarbaz-Bar');
  127. done();
  128. });
  129. it('should prefer Base64 characters only', function (done) {
  130. getSlug('Foo, Bar Baz', {
  131. uric: false,
  132. uricNoSlash: false,
  133. mark: false
  134. })
  135. .should.eql('foo-bar-baz');
  136. getSlug('Foo- Bar Baz', {
  137. uric: false,
  138. uricNoSlash: false,
  139. mark: false
  140. })
  141. .should.eql('foo-bar-baz');
  142. getSlug('Foo] Bar Baz', {
  143. uric: false,
  144. uricNoSlash: false,
  145. mark: false
  146. })
  147. .should.eql('foo-bar-baz');
  148. getSlug('Foo* Bar Baz', {
  149. uric: false,
  150. uricNoSlash: false,
  151. mark: false
  152. })
  153. .should.eql('foo-bar-baz');
  154. done();
  155. });
  156. });