Skip to content

Commit

Permalink
Switch to ava test runner with nyc coverage report
Browse files Browse the repository at this point in the history
  • Loading branch information
lovell committed Jan 1, 2018
1 parent ea737d9 commit d5c2dcb
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 83 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
coverage
node_modules
.idea
.nyc_output
4 changes: 2 additions & 2 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
coverage
node_modules
test
.jshintignore
.jshintrc
.gitignore
.nyc_output
.travis.yml
appveyor.yml
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ also known as clean URLs, user-friendly URLs and SEO-friendly URLs.

The difference?

This module includes Romanisation of non-Latin scripts.
This module extends the fantastic
[speakingurl](https://www.npmjs.com/package/speakingurl)
module to include Romanisation of Chinese and Japanese scripts.

Give it a string of text in pretty much any major world language
and it will convert it to valid characters,
conforming to [RFC3986](http://www.ietf.org/rfc/rfc3986.txt),
Expand Down Expand Up @@ -96,7 +99,7 @@ Pull requests with mappings and tests for further scripts and languages are more

## Licence

Copyright 2013, 2014, 2015, 2016 Lovell Fuller and contributors.
Copyright 2013, 2014, 2015, 2016, 2017, 2018 Lovell Fuller and contributors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
8 changes: 6 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@ environment:
nodejs_arch: "x86"
- nodejs_version: "6"
nodejs_arch: "x64"
- nodejs_version: "7"
- nodejs_version: "8"
nodejs_arch: "x86"
- nodejs_version: "7"
- nodejs_version: "8"
nodejs_arch: "x64"
- nodejs_version: "9"
nodejs_arch: "x86"
- nodejs_version: "9"
nodejs_arch: "x64"
install:
- ps: Install-Product node $env:nodejs_version $env:nodejs_arch
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"node": ">=4"
},
"scripts": {
"test": "semistandard && node test/unit"
"test": "semistandard && nyc --reporter=html ava"
},
"keywords": [
"slug",
Expand Down Expand Up @@ -43,6 +43,8 @@
"speakingurl": "^14.0.1"
},
"devDependencies": {
"ava": "^0.24.0",
"nyc": "^11.4.1",
"semistandard": "^11.0.0"
}
}
167 changes: 92 additions & 75 deletions test/unit.js
Original file line number Diff line number Diff line change
@@ -1,104 +1,121 @@
'use strict';

const assert = require('assert');
const slug = require('../lib/limax');
const ava = require('ava');
const limax = require('../lib/limax');

const tests = {
'i ♥ latin': 'i-love-latin',
'Я люблю русский': 'ya-lyublyu-russkii',
'私は ひらがな が大好き': 'ha-hiragana-gaki',
'我爱官话': 'wo3-ai4-guan1-hua4',
// https://github.com/keystonejs/keystone-utils/issues/12
'one2three': 'one-2-three',
'The User\'s Guide': 'the-users-guide',
'The User’s Guide': 'the-users-guide',
// https://github.com/lovell/limax/issues/4
'弄堂里的菜品赤醬': 'nong4-tang2-li3-de-cai4-pin3-chi4-jiang4',
// https://github.com/lovell/limax/issues/12
'12345': '12345',
'one 2three': 'one-2three',
// https://github.com/lovell/limax/pull/17
'Pop brésilienne header': 'pop-bresilienne-header'
};
const testInputs = Object.keys(tests);

Object.keys(tests).forEach(function (test) {
const actual = slug(test);
const expected = tests[test];
assert.strictEqual(actual, expected);
ava('Basic usage', function (t) {
t.plan(testInputs.length);
testInputs.forEach(function (input) {
t.true(limax(input) === tests[input]);
});
});

Object.keys(tests).forEach(function (test) {
const actual = slug(test, '_');
const expected = tests[test].replace(/-/g, '_');
assert.strictEqual(actual, expected);
ava('Set separator via parameter', function (t) {
t.plan(testInputs.length);
testInputs.forEach(function (input) {
t.true(limax(input, '_') === tests[input].replace(/-/g, '_'));
});
});

Object.keys(tests).forEach(function (test) {
const actual = slug(test, {replacement: '_'});
const expected = tests[test].replace(/-/g, '_');
assert.strictEqual(actual, expected);
ava('Set separator via replacement option', function (t) {
t.plan(testInputs.length);
testInputs.forEach(function (input) {
t.true(limax(input, { replacement: '_' }) === tests[input].replace(/-/g, '_'));
});
});

Object.keys(tests).forEach(function (test) {
const actual = slug(test, {separator: '_'});
const expected = tests[test].replace(/-/g, '_');
assert.strictEqual(actual, expected);
ava('Set separator via separator option', function (t) {
t.plan(testInputs.length);
testInputs.forEach(function (input) {
t.true(limax(input, { separator: '_' }) === tests[input].replace(/-/g, '_'));
});
});

assert.strictEqual(slug('Ich ♥ Deutsch', {lang: 'de'}), 'ich-liebe-deutsch');

// https://github.com/lovell/limax/issues/4
assert.strictEqual(slug('弄堂里的菜品赤醬', {tone: true}), 'nong4-tang2-li3-de-cai4-pin3-chi4-jiang4');
assert.strictEqual(slug('弄堂里的菜品赤醬', {tone: false}), 'nong-tang-li-de-cai-pin-chi-jiang');

// https://github.com/lovell/limax/issues/14
assert.strictEqual(slug('hello2world', { separateNumbers: false }), 'hello2world');
assert.strictEqual(slug('hello2world', { separateNumbers: true }), 'hello-2-world');

// Test maintainCase option
assert.strictEqual(slug('Hello2World', { maintainCase: false }), 'hello-2-world');
assert.strictEqual(slug('Hello2World', { maintainCase: true }), 'Hello-2-World');

// Test custom option
assert.strictEqual(slug('hello.world', { custom: ['.'] }), 'hello.world');
assert.strictEqual(slug('hello-*-world', { custom: { '*': 'asterisk' } }), 'hello-asterisk-world');
ava('Set language via lang option', function (t) {
t.plan(3);
t.true(
limax('Ich ♥ Deutsch', { lang: 'de' }) === 'ich-liebe-deutsch'
);
t.true(
limax('私は ひらがな が大好き', { lang: 'jp' }) === 'ha-hiragana-gaki'
);
t.true(
limax('我爱官话', { lang: 'zh' }) === 'wo3-ai4-guan1-hua4'
);
});

// https://github.com/lovell/limax/issues/25
assert.strictEqual(
slug('404', { separateNumbers: true }),
'404'
);
assert.strictEqual(
slug('404', { separateNumbers: false }),
'404'
);
assert.strictEqual(
slug('状态404页面未找到', { separateNumbers: true }),
'zhuang4-tai4-404-ye4-mian4-wei4-zhao3-dao4'
);
assert.strictEqual(
slug('状态404页面未找到', { separateNumbers: false }),
'zhuang4-tai4-404-ye4-mian4-wei4-zhao3-dao4'
);
ava('Set Pinyin tone numbering via tone option', function (t) {
t.plan(3);
t.true(
limax('弄堂里的菜品赤醬', { tone: true }) === 'nong4-tang2-li3-de-cai4-pin3-chi4-jiang4'
);
t.true(
limax('弄堂里的菜品赤醬', { tone: false }) === 'nong-tang-li-de-cai-pin-chi-jiang'
);
t.true(
limax('特殊天-1', { tone: false }) === 'te-shu-tian-1'
);
});

// https://github.com/lovell/limax/issues/28
assert.strictEqual(
slug('特殊天-1', { tone: false }),
'te-shu-tian-1'
);
ava('Set separateNumbers via options', function (t) {
t.plan(6);
t.true(
limax('hello2world', { separateNumbers: false }) === 'hello2world'
);
t.true(
limax('hello2world', { separateNumbers: true }) === 'hello-2-world'
);
t.true(
limax('404', { separateNumbers: true }) === '404'
);
t.true(
limax('404', { separateNumbers: false }) === '404'
);
t.true(
limax('状态404页面未找到', { separateNumbers: true }) === 'zhuang4-tai4-404-ye4-mian4-wei4-zhao3-dao4'
);
t.true(
limax('状态404页面未找到', { separateNumbers: false }) === 'zhuang4-tai4-404-ye4-mian4-wei4-zhao3-dao4'
);
});

// https://github.com/lovell/limax/issues/22
assert.strictEqual(
slug('中文.pdf', { custom: ['.'] }),
'zhong1-wen2-.pdf'
);
ava('Set maintainCase via options', function (t) {
t.plan(2);
t.true(
limax('Hello2World', { maintainCase: false }) === 'hello-2-world'
);
t.true(
limax('Hello2World', { maintainCase: true }) === 'Hello-2-World'
);
});

// https://github.com/lovell/limax/issues/26
assert.strictEqual(
slug('私は ひらがな が大好き', { lang: 'jp' }),
'ha-hiragana-gaki'
);
assert.strictEqual(
slug('我爱官话', { lang: 'zh' }),
'wo3-ai4-guan1-hua4'
);
ava('Set custom via options', function (t) {
t.plan(4);
t.true(
limax('hello.world', { custom: ['.'] }) === 'hello.world'
);
t.true(
limax('hello-*-world', { custom: { '*': 'asterisk' } }) === 'hello-asterisk-world'
);
t.true(
limax('中文.pdf', { custom: ['.'] }) === 'zhong1-wen2-.pdf'
);
t.true(
limax('中文.pdf', { custom: { '.': 'dot' } }) === 'zhong1-wen2-dotpdf'
);
});

0 comments on commit d5c2dcb

Please sign in to comment.