test-separator.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /* global describe,it */
  2. var getSlug = require('../lib/speakingurl');
  3. describe('getSlug separator', function () {
  4. 'use strict';
  5. it('should separate with non-whitespace', function (done) {
  6. getSlug('Foo Bar Baz', {
  7. separator: '-'
  8. })
  9. .should.eql('foo-bar-baz');
  10. getSlug('Foo Bar Baz', {
  11. separator: '*'
  12. })
  13. .should.eql('foo*bar*baz');
  14. getSlug('Foo Bar Baz', {
  15. separator: '_'
  16. })
  17. .should.eql('foo_bar_baz');
  18. getSlug('Foo Bar Baz', '-')
  19. .should.eql('foo-bar-baz');
  20. getSlug('Foo Bar Baz', '*')
  21. .should.eql('foo*bar*baz');
  22. getSlug('Foo Bar Baz', '_')
  23. .should.eql('foo_bar_baz');
  24. done();
  25. });
  26. it('should separate with non-whitespace, with trailing spaces', function (done) {
  27. getSlug(' Foo Bar Baz ', {
  28. separator: '-'
  29. })
  30. .should.eql('foo-bar-baz');
  31. getSlug(' Foo Bar Baz ', {
  32. separator: '*'
  33. })
  34. .should.eql('foo*bar*baz');
  35. getSlug(' Foo Bar Baz ', {
  36. separator: '_'
  37. })
  38. .should.eql('foo_bar_baz');
  39. getSlug(' Foo Bar Baz ', '-')
  40. .should.eql('foo-bar-baz');
  41. getSlug(' Foo Bar Baz ', '*')
  42. .should.eql('foo*bar*baz');
  43. getSlug(' Foo Bar Baz ', '_')
  44. .should.eql('foo_bar_baz');
  45. done();
  46. });
  47. it('should separate with trailing separator "-"', function (done) {
  48. getSlug('-Foo Bar Baz-', {
  49. separator: '-'
  50. })
  51. .should.eql('foo-bar-baz');
  52. getSlug('--Foo Bar Baz---', {
  53. separator: '-'
  54. })
  55. .should.eql('foo-bar-baz');
  56. getSlug('---Foo Bar Baz---', {
  57. separator: '-'
  58. })
  59. .should.eql('foo-bar-baz');
  60. getSlug('-Foo Bar Baz-', '-')
  61. .should.eql('foo-bar-baz');
  62. getSlug('--Foo Bar Baz---', '-')
  63. .should.eql('foo-bar-baz');
  64. getSlug('---Foo Bar Baz---', '-')
  65. .should.eql('foo-bar-baz');
  66. done();
  67. });
  68. it('should separate with trailing separator "*"', function (done) {
  69. getSlug('*Foo Bar Baz*', {
  70. separator: '*'
  71. })
  72. .should.eql('foo*bar*baz');
  73. getSlug('**Foo Bar Baz**', {
  74. separator: '*'
  75. })
  76. .should.eql('foo*bar*baz');
  77. getSlug('***Foo Bar Baz***', {
  78. separator: '*'
  79. })
  80. .should.eql('foo*bar*baz');
  81. getSlug('*Foo Bar Baz*', '*')
  82. .should.eql('foo*bar*baz');
  83. getSlug('**Foo Bar Baz**', '*')
  84. .should.eql('foo*bar*baz');
  85. getSlug('***Foo Bar Baz***', '*')
  86. .should.eql('foo*bar*baz');
  87. done();
  88. });
  89. it('should separate with trailing separator "_"', function (done) {
  90. getSlug('_Foo Bar Baz_', {
  91. separator: '_'
  92. })
  93. .should.eql('foo_bar_baz');
  94. getSlug('__Foo Bar Baz__', {
  95. separator: '_'
  96. })
  97. .should.eql('foo_bar_baz');
  98. getSlug('___Foo Bar Baz___', {
  99. separator: '_'
  100. })
  101. .should.eql('foo_bar_baz');
  102. getSlug('_Foo Bar Baz_', '_')
  103. .should.eql('foo_bar_baz');
  104. getSlug('__Foo Bar Baz__', '_')
  105. .should.eql('foo_bar_baz');
  106. getSlug('___Foo Bar Baz___', '_')
  107. .should.eql('foo_bar_baz');
  108. done();
  109. });
  110. it('should remove trailing separator "*"', function (done) {
  111. getSlug(' C\'est un beau titre qui ne laisse rien à désirer !', {
  112. separator: '*'
  113. })
  114. .should.eql(
  115. 'c*est*un*beau*titre*qui*ne*laisse*rien*a*desirer');
  116. getSlug(' C\'est un beau titre qui ne laisse rien à désirer !',
  117. '*')
  118. .should.eql(
  119. 'c*est*un*beau*titre*qui*ne*laisse*rien*a*desirer');
  120. done();
  121. });
  122. it('should return empty string because of non string input', function (done) {
  123. getSlug(true)
  124. .should.eql('');
  125. done();
  126. });
  127. });