test-defaults.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /* global describe,it */
  2. var getSlug = require('../lib/speakingurl');
  3. describe('getSlug defaults', function () {
  4. 'use strict';
  5. it('should replace whitespaces with separator', function (done) {
  6. getSlug('foo bar baz')
  7. .should.eql('foo-bar-baz');
  8. done();
  9. });
  10. it('should remove trailing space if any', function (done) {
  11. getSlug(' foo bar baz ')
  12. .should.eql('foo-bar-baz');
  13. done();
  14. });
  15. it('should remove multiple whitespaces', function (done) {
  16. getSlug(' foo bar baz FOO BAR BAZ ')
  17. .should.eql('foo-bar-baz-foo-bar-baz');
  18. done();
  19. });
  20. it('should remove multiple separators at start and end', function (done) {
  21. getSlug('-foo- bar -baz-')
  22. .should.eql('foo-bar-baz');
  23. getSlug('--foo- bar -baz---')
  24. .should.eql('foo-bar-baz');
  25. getSlug('---foo- bar -baz---')
  26. .should.eql('foo-bar-baz');
  27. done();
  28. });
  29. it('should remove multple separators', function (done) {
  30. getSlug('foo- bar -baz')
  31. .should.eql('foo-bar-baz');
  32. done();
  33. });
  34. it('should remove non-base64 characters', function (done) {
  35. var nonBase64 = ['[', ']', ',', '*', '+', '~', '.', '(', ')', '\'', '"', '!', ':', '@'];
  36. for (var i = 0; i < nonBase64.length; i++) {
  37. getSlug("foo " + nonBase64[i] + " bar baz")
  38. .should.eql("foo-bar-baz");
  39. }
  40. done();
  41. });
  42. it('should remove trailing separator', function (done) {
  43. getSlug('C\'est un beau titre qui ne laisse rien à désirer ! ')
  44. .should.eql(
  45. 'c-est-un-beau-titre-qui-ne-laisse-rien-a-desirer');
  46. done();
  47. });
  48. it('should handle whitespace after symbol', function (done) {
  49. getSlug('∆299')
  50. .should.eql('delta-299');
  51. getSlug('∆world')
  52. .should.eql('delta-world');
  53. getSlug('∆-299')
  54. .should.eql('delta-299');
  55. getSlug('∆-world')
  56. .should.eql('delta-world');
  57. getSlug('(∆)299')
  58. .should.eql('delta-299');
  59. getSlug('(∆)299', {
  60. mark: true
  61. })
  62. .should.eql('(delta)299');
  63. getSlug('∆299')
  64. .should.eql('delta-299');
  65. getSlug('∆world')
  66. .should.eql('delta-world');
  67. getSlug('Hello∆299')
  68. .should.eql('hello-delta-299');
  69. getSlug('299∆Hello')
  70. .should.eql('299-delta-hello');
  71. done();
  72. });
  73. it('should not fail if symbol at the end', function (done) {
  74. getSlug('test &')
  75. .should.eql('test-and');
  76. getSlug('test & ')
  77. .should.eql('test-and');
  78. getSlug('test &', '_')
  79. .should.eql('test_and');
  80. getSlug('test ♥')
  81. .should.eql('test-love');
  82. getSlug('test ♥ ')
  83. .should.eql('test-love');
  84. getSlug('test ♥ ')
  85. .should.eql('test-love');
  86. done();
  87. });
  88. });