123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337 |
- /* global describe,it */
- var getSlug = require('../lib/speakingurl');
- describe('getSlug create', function () {
- 'use strict';
- it('with symbols', function (done) {
- var getSlug = require('../lib/speakingurl')
- .createSlug({
- lang: 'en',
- uric: true,
- uricNoSlash: true,
- mark: true
- });
- getSlug('Foo (♥) ; Baz=Bar')
- .should.eql('foo-(love)-;-baz=bar');
- done();
- });
- it('without options', function (done) {
- var getSlug = require('../lib/speakingurl')
- .createSlug();
- getSlug('Foo Bar Baz')
- .should.eql('foo-bar-baz');
- done();
- });
- it('with empty options', function (done) {
- var getSlug = require('../lib/speakingurl')
- .createSlug({});
- getSlug('Foo Bar Baz')
- .should.eql('foo-bar-baz');
- done();
- });
- it('with maintainCase', function (done) {
- var getSlug = require('../lib/speakingurl')
- .createSlug({
- maintainCase: true
- });
- getSlug('Foo Bar Baz')
- .should.eql('Foo-Bar-Baz');
- done();
- });
- it('with uric', function (done) {
- var getSlug = require('../lib/speakingurl')
- .createSlug({
- uric: true
- });
- getSlug(' :80:/Foo/Bar/Baz:Foo')
- .should.eql(':80:/foo/bar/baz:foo');
- done();
- });
- it('with uricNoSlash', function (done) {
- var getSlug = require('../lib/speakingurl')
- .createSlug({
- uricNoSlash: true
- });
- getSlug('Foo/ Bar= Baz')
- .should.eql('foo-bar=-baz');
- done();
- });
- it('with mark', function (done) {
- var getSlug = require('../lib/speakingurl')
- .createSlug({
- mark: true
- });
- getSlug('Foo* Bar Baz')
- .should.eql('foo*-bar-baz');
- done();
- });
- it('with truncate', function (done) {
- var getSlug = require('../lib/speakingurl')
- .createSlug({
- truncate: 15
- });
- getSlug('Foo* Foobar FooBarBaz')
- .should.eql('foo-foobar');
- done();
- });
- it('with separator', function (done) {
- var getSlug = require('../lib/speakingurl')
- .createSlug({
- separator: '_'
- });
- getSlug('Foo* Foobar FooBarBaz')
- .should.eql('foo_foobar_foobarbaz');
- done();
- });
- it('with mark and maintainCase', function (done) {
- var getSlug = require('../lib/speakingurl')
- .createSlug({
- mark: true,
- maintainCase: true
- });
- getSlug('Foo* Bar Baz')
- .should.eql('Foo*-Bar-Baz');
- done();
- });
- it('with custom chars replacement', function (done) {
- var getSlug = require('../lib/speakingurl')
- .createSlug({
- custom: {
- '*': 'o'
- }
- });
- getSlug('xyl*ph*n')
- .should.eql('xylophon');
- done();
- });
- it('with custom chars leet replacement', function (done) {
- var getSlug = require('../lib/speakingurl')
- .createSlug({
- custom: {
- 'a': '4',
- 'b': '8',
- 'e': '3',
- 'g': '6',
- 'l': '1',
- 'o': '0',
- 's': '5',
- 't': '7'
- },
- lang: false
- });
- getSlug('apbpepgplpopspt')
- .should.eql('4p8p3p6p1p0p5p7');
- getSlug('papbpepgplpopsptp')
- .should.eql('p4p8p3p6p1p0p5p7p');
- getSlug('qabqegqloqst')
- .should.eql('q48q36q10q57');
- getSlug('abeglost')
- .should.eql('48361057');
- done();
- });
- it('with custom chars replacement with not allowed target char', function (done) {
- var getSlug = require('../lib/speakingurl')
- .createSlug({
- custom: {
- 'o': '*'
- }
- });
- getSlug('xylophon')
- .should.eql('xyl-ph-n');
- done();
- });
- it('with custom chars replacement with allowed target char, option mark', function (done) {
- var getSlug = require('../lib/speakingurl')
- .createSlug({
- custom: {
- 'o': '*'
- },
- mark: true
- });
- getSlug('xylophon')
- .should.eql('xyl*ph*n');
- done();
- });
- it('with custom chars replacement with option mark', function (done) {
- var getSlug = require('../lib/speakingurl')
- .createSlug({
- custom: {
- '*': 'o'
- },
- mark: true
- });
- getSlug('xyl*ph*n')
- .should.eql('xylophon');
- done();
- });
- it('with custom char to string replacement', function (done) {
- var getSlug = require('../lib/speakingurl')
- .createSlug({
- custom: {
- '*': 'STAR',
- 'q': 'qqq',
- 'and': '',
- 'or': ''
- }
- });
- getSlug('xyl*ph*n')
- .should.eql('xylstarphstarn');
- getSlug('quack')
- .should.eql('qqquack');
- getSlug('Foo and Bar or Baz')
- .should.eql('foo-bar-baz');
- done();
- });
- it('with custom string replacement', function (done) {
- var getSlug = require('../lib/speakingurl')
- .createSlug({
- custom: {
- 'and': 'und',
- 'or': 'oder',
- '*': ' and '
- }
- });
- getSlug('bus and train')
- .should.eql('bus-und-train');
- getSlug('bus or train')
- .should.eql('bus-oder-train');
- getSlug('busandtrain')
- .should.eql('busandtrain');
- getSlug('busortrain')
- .should.eql('busortrain');
- getSlug('bus*train')
- .should.eql('bus-and-train');
- getSlug('bus and train bus and train')
- .should.eql('bus-und-train-bus-und-train');
- getSlug('bus or train bus or train')
- .should.eql('bus-oder-train-bus-oder-train');
- getSlug('busandtrain busandtrain')
- .should.eql('busandtrain-busandtrain');
- getSlug('busortrain busortrain')
- .should.eql('busortrain-busortrain');
- done();
- });
- it('with custom string replacement with option mark', function (done) {
- var getSlug = require('../lib/speakingurl')
- .createSlug({
- custom: {
- '*': 'STAR',
- 'q': 'qqq',
- 'z': ''
- },
- mark: true
- });
- getSlug('xyl*ph*n')
- .should.eql('xylstarphstarn');
- getSlug('qxxx')
- .should.eql('qqqxxx');
- getSlug('xxxqxxx')
- .should.eql('xxxqqqxxx');
- getSlug('qqq')
- .should.eql('qqqqqqqqq');
- getSlug('*q*')
- .should.eql('starqqqstar');
- getSlug('zoo')
- .should.eql('oo');
- getSlug('zooz')
- .should.eql('oo');
- done();
- });
- it('with custom string replacement with option maintainCase', function (done) {
- var getSlug = require('../lib/speakingurl')
- .createSlug({
- custom: {
- '*': 'STAR',
- 'q': 'qqq',
- },
- maintainCase: true
- });
- getSlug('xyl*ph*n')
- .should.eql('xylSTARphSTARn');
- getSlug('qXXX')
- .should.eql('qqqXXX');
- getSlug('qqq')
- .should.eql('qqqqqqqqq');
- getSlug('*q*')
- .should.eql('STARqqqSTAR');
- done();
- });
- });
|