123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181 |
- /* global describe,it */
- var getSlug = require('../lib/speakingurl');
- describe('getSlug separator', function () {
- 'use strict';
- it('should separate with non-whitespace', function (done) {
- getSlug('Foo Bar Baz', {
- separator: '-'
- })
- .should.eql('foo-bar-baz');
- getSlug('Foo Bar Baz', {
- separator: '*'
- })
- .should.eql('foo*bar*baz');
- getSlug('Foo Bar Baz', {
- separator: '_'
- })
- .should.eql('foo_bar_baz');
- getSlug('Foo Bar Baz', '-')
- .should.eql('foo-bar-baz');
- getSlug('Foo Bar Baz', '*')
- .should.eql('foo*bar*baz');
- getSlug('Foo Bar Baz', '_')
- .should.eql('foo_bar_baz');
- done();
- });
- it('should separate with non-whitespace, with trailing spaces', function (done) {
- getSlug(' Foo Bar Baz ', {
- separator: '-'
- })
- .should.eql('foo-bar-baz');
- getSlug(' Foo Bar Baz ', {
- separator: '*'
- })
- .should.eql('foo*bar*baz');
- getSlug(' Foo Bar Baz ', {
- separator: '_'
- })
- .should.eql('foo_bar_baz');
- getSlug(' Foo Bar Baz ', '-')
- .should.eql('foo-bar-baz');
- getSlug(' Foo Bar Baz ', '*')
- .should.eql('foo*bar*baz');
- getSlug(' Foo Bar Baz ', '_')
- .should.eql('foo_bar_baz');
- done();
- });
- it('should separate with trailing separator "-"', function (done) {
- getSlug('-Foo Bar Baz-', {
- separator: '-'
- })
- .should.eql('foo-bar-baz');
- getSlug('--Foo Bar Baz---', {
- separator: '-'
- })
- .should.eql('foo-bar-baz');
- getSlug('---Foo Bar Baz---', {
- separator: '-'
- })
- .should.eql('foo-bar-baz');
- getSlug('-Foo Bar Baz-', '-')
- .should.eql('foo-bar-baz');
- getSlug('--Foo Bar Baz---', '-')
- .should.eql('foo-bar-baz');
- getSlug('---Foo Bar Baz---', '-')
- .should.eql('foo-bar-baz');
- done();
- });
- it('should separate with trailing separator "*"', function (done) {
- getSlug('*Foo Bar Baz*', {
- separator: '*'
- })
- .should.eql('foo*bar*baz');
- getSlug('**Foo Bar Baz**', {
- separator: '*'
- })
- .should.eql('foo*bar*baz');
- getSlug('***Foo Bar Baz***', {
- separator: '*'
- })
- .should.eql('foo*bar*baz');
- getSlug('*Foo Bar Baz*', '*')
- .should.eql('foo*bar*baz');
- getSlug('**Foo Bar Baz**', '*')
- .should.eql('foo*bar*baz');
- getSlug('***Foo Bar Baz***', '*')
- .should.eql('foo*bar*baz');
- done();
- });
- it('should separate with trailing separator "_"', function (done) {
- getSlug('_Foo Bar Baz_', {
- separator: '_'
- })
- .should.eql('foo_bar_baz');
- getSlug('__Foo Bar Baz__', {
- separator: '_'
- })
- .should.eql('foo_bar_baz');
- getSlug('___Foo Bar Baz___', {
- separator: '_'
- })
- .should.eql('foo_bar_baz');
- getSlug('_Foo Bar Baz_', '_')
- .should.eql('foo_bar_baz');
- getSlug('__Foo Bar Baz__', '_')
- .should.eql('foo_bar_baz');
- getSlug('___Foo Bar Baz___', '_')
- .should.eql('foo_bar_baz');
- done();
- });
- it('should remove trailing separator "*"', function (done) {
- getSlug(' C\'est un beau titre qui ne laisse rien à désirer !', {
- separator: '*'
- })
- .should.eql(
- 'c*est*un*beau*titre*qui*ne*laisse*rien*a*desirer');
- getSlug(' C\'est un beau titre qui ne laisse rien à désirer !',
- '*')
- .should.eql(
- 'c*est*un*beau*titre*qui*ne*laisse*rien*a*desirer');
- done();
- });
- it('should return empty string because of non string input', function (done) {
- getSlug(true)
- .should.eql('');
- done();
- });
- });
|