-
Notifications
You must be signed in to change notification settings - Fork 15
/
test.js
66 lines (54 loc) · 2.37 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
'use strict';
require('mocha');
const assert = require('assert');
const dashify = require('./');
describe('dashify', () => {
it('should convert camelcase to dashes:', () => {
assert.strictEqual(dashify('fooBar'), 'foo-bar');
assert.strictEqual(dashify('fooBarBaz'), 'foo-bar-baz');
});
it('should support diacritics', () => {
assert.strictEqual(dashify('São Tomé and Príncipe'), 'são-tomé-and-príncipe');
});
it('should condense multiple subsequent dashes to one', () => {
assert.strictEqual(dashify('Foo----Bar'), 'foo----bar');
assert.strictEqual(dashify('Foo----Bar', {condense: true}), 'foo-bar');
});
it('should strip dashes from oes and sos', () => {
assert.strictEqual(dashify('-foo'), 'foo');
assert.strictEqual(dashify('foo-'), 'foo');
assert.strictEqual(dashify('-foo-'), 'foo');
});
it('should convert slashes to dashes', () => {
assert.strictEqual(dashify('/foo'), 'foo');
assert.strictEqual(dashify('foo/'), 'foo');
assert.strictEqual(dashify('foo/bar'), 'foo-bar');
});
it('should convert spaces to dashes:', () => {
assert.strictEqual(dashify('foo bar'), 'foo-bar');
assert.strictEqual(dashify('foo barBaz'), 'foo-bar-baz');
assert.strictEqual(dashify('foo barBaz quux'), 'foo-bar-baz-quux');
});
it('should convert space followed by uppercase letter to a single dash:', () => {
assert.strictEqual(dashify('foo Bar'), 'foo-bar');
assert.strictEqual(dashify('Foo BarBaz quux'), 'foo-bar-baz-quux');
});
it('should convert non-word characters to dashes:', () => {
assert.strictEqual(dashify('foo*bar'), 'foo-bar');
assert.strictEqual(dashify('foo`barBaz'), 'foo-bar-baz');
assert.strictEqual(dashify('foo^barBaz^quux'), 'foo-bar-baz-quux');
});
it('should strip leading non-word characters:', () => {
assert.strictEqual(dashify('#^foo*bar'), 'foo-bar');
assert.strictEqual(dashify('#^foo`barBaz'), 'foo-bar-baz');
assert.strictEqual(dashify('#^foo^barBaz^quux'), 'foo-bar-baz-quux');
});
it('should work when leading character is uppercase:', () => {
assert.strictEqual(dashify('Foo barBaz quux'), 'foo-bar-baz-quux');
assert.strictEqual(dashify('FooBarBaz'), 'foo-bar-baz');
assert.strictEqual(dashify('Foo Bar'), 'foo-bar');
});
it('should throw an error if a string is not passed:', () => {
assert.throws(() => dashify(), /expected/);
});
});