test-truncate.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /* global describe,it */
  2. var getSlug = require('../lib/speakingurl');
  3. describe('getSlug smart truncate', function () {
  4. 'use strict';
  5. it('should maintain case characters, with smart truncate', function (done) {
  6. getSlug('Foobarbaz, Bar Baz', {
  7. truncate: 12
  8. })
  9. .should.eql('foobarbaz');
  10. getSlug('Foobarbaz, Bar Baz', {
  11. truncate: 15
  12. })
  13. .should.eql('foobarbaz-bar');
  14. getSlug(' Foobarbaz, Bar Baz', {
  15. truncate: 15
  16. })
  17. .should.eql('foobarbaz-bar');
  18. getSlug(' Foobarbaz, Bar Baz', {
  19. truncate: 15
  20. })
  21. .should.eql('foobarbaz-bar');
  22. getSlug('Foo Foo bar Zoo Bar Baz', {
  23. truncate: 15
  24. })
  25. .should.eql('foo-foo-bar-zoo');
  26. getSlug('Foo Foo bar ZooBar Baz', {
  27. truncate: 15
  28. })
  29. .should.eql('foo-foo-bar');
  30. getSlug('Foo Foo bar ZooBar Baz', {
  31. truncate: 15
  32. })
  33. .should.eql('foo-foo-bar');
  34. getSlug('Foo Foo Bar Bar', {
  35. truncate: "foo"
  36. })
  37. .should.eql('foo-foo-bar-bar');
  38. getSlug('Foo Foo Bar Bar', {
  39. truncate: false
  40. })
  41. .should.eql('foo-foo-bar-bar');
  42. getSlug('Foo Foo Bar Bar', {
  43. truncate: true
  44. })
  45. .should.eql('foo-foo-bar-bar');
  46. getSlug('a Foo', {
  47. truncate: true
  48. })
  49. .should.eql('a-foo');
  50. done();
  51. });
  52. });