|
| 1 | +const normalizer = require('./normalizer') |
| 2 | + |
| 3 | +module.exports.tests = {} |
| 4 | + |
| 5 | +module.exports.tests.normalizer = (test) => { |
| 6 | + test('normalizerr: hyphen', (t) => { |
| 7 | + const value = ' Value-With-Some-Hyphen ' |
| 8 | + const expected = 'Value With Some Hyphen' |
| 9 | + const normalize = normalizer({ removeHyphen: true }) |
| 10 | + |
| 11 | + t.deepEquals(normalize(value), expected) |
| 12 | + t.end() |
| 13 | + }) |
| 14 | + |
| 15 | + test('normalizer: accents', (t) => { |
| 16 | + const value = ' Vâlüé-Wìth-Sômê-Accents ' |
| 17 | + const expected = 'Value-With-Some-Accents' |
| 18 | + const normalize = normalizer({ removeAccents: true }) |
| 19 | + |
| 20 | + t.deepEquals(normalize(value), expected) |
| 21 | + t.end() |
| 22 | + }) |
| 23 | + |
| 24 | + test('normalizer: lowercase', (t) => { |
| 25 | + const value = 'Value-With-Some-UpperCases' |
| 26 | + const expected = 'value-with-some-uppercases' |
| 27 | + const normalize = normalizer({ lowercase: true }) |
| 28 | + |
| 29 | + t.deepEquals(normalize(value), expected) |
| 30 | + t.end() |
| 31 | + }) |
| 32 | + |
| 33 | + test('normalizer: spaces', (t) => { |
| 34 | + const value = 'Value With Some Spaces' |
| 35 | + const expected = 'ValueWithSomeSpaces' |
| 36 | + const normalize = normalizer({ removeSpaces: true }) |
| 37 | + |
| 38 | + t.deepEquals(normalize(value), expected) |
| 39 | + t.end() |
| 40 | + }) |
| 41 | + |
| 42 | + test('normalizer: option mix', (t) => { |
| 43 | + const value = 'Vâlüé-Mìxèd' |
| 44 | + const expected = 'value mixed' |
| 45 | + const normalize = normalizer({ lowercase: true, removeHyphen: true, removeAccents: true }) |
| 46 | + |
| 47 | + t.deepEquals(normalize(value), expected) |
| 48 | + t.end() |
| 49 | + }) |
| 50 | + |
| 51 | + test('normalizer: no options', (t) => { |
| 52 | + const value = 'Value-With-Some-Hyphen' |
| 53 | + const normalize = normalizer() |
| 54 | + |
| 55 | + t.deepEquals(normalize(value), value) |
| 56 | + t.end() |
| 57 | + }) |
| 58 | +} |
| 59 | + |
| 60 | +module.exports.all = (tape, common) => { |
| 61 | + function test (name, testFunction) { |
| 62 | + return tape(`normalizer: ${name}`, testFunction) |
| 63 | + } |
| 64 | + |
| 65 | + for (var testCase in module.exports.tests) { |
| 66 | + module.exports.tests[testCase](test, common) |
| 67 | + } |
| 68 | +} |
0 commit comments