Skip to content

Commit

Permalink
lint testcases
Browse files Browse the repository at this point in the history
  • Loading branch information
mnater committed May 30, 2018
1 parent 2883e10 commit b27a765
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 86 deletions.
10 changes: 6 additions & 4 deletions hyphenopoly.module.js
Original file line number Diff line number Diff line change
Expand Up @@ -381,11 +381,13 @@ const hpb = [];
function prepare(lang) {
if (lang === "*") {
engineInstantiator = instantiateWasmEngine;

/*
hpb.forEach(function eachHbp(hpbLang) {
engineInstantiator(hpbLang);
});
*/
* Deleted:
* hpb.forEach(function eachHbp(hpbLang) {
* engineInstantiator(hpbLang);
*});
*/
} else if (engineInstantiator) {
engineInstantiator(lang);
} else {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@
"compilewasm": "sh ./tools/compileWASM.sh hyphenEngine",
"test": "tap test/*.js",
"testsuite": "open http://127.0.0.1/~mnater/Hyphenopoly/testsuite/ && open http://127.0.0.1/~mnater/Hyphenopoly/min/testsuite/",
"lint": "eslint Hyphenopoly_Loader.js Hyphenopoly.js hyphenopoly.module.js",
"lint": "eslint --parser-options=ecmaVersion:8 Hyphenopoly_Loader.js Hyphenopoly.js hyphenopoly.module.js test/*.js",
"prepare": "npm run minify",
"minify": "sh ./tools/minify.sh"
},
Expand Down
42 changes: 22 additions & 20 deletions test/basic.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// test/hello-world.js
var t = require("tap");
// const H9Y = require("../hyphenopoly.module");
/* eslint-env node */
/* eslint global-require: 0, func-names: 0, no-shadow: 0 */
"use strict";
const t = require("tap");

let H9Y = null;
const H9YKey = require.resolve("../hyphenopoly.module");
t.beforeEach(function setup(done) {
Expand All @@ -14,75 +16,75 @@ t.afterEach(function tearDown(done) {
done();
});

t.test("run config with one language", async function(t) {
t.test("run config with one language", async function (t) {
const deHyphenator = await H9Y.config({"require": ["de"]});
t.test("return a function", function(t) {
t.test("return a function", function (t) {
t.equal(typeof deHyphenator, "function", typeof deHyphenator);
t.end();
});
t.test("hyphenate one word", function(t) {
t.test("hyphenate one word", function (t) {
t.equal(deHyphenator("Silbentrennung"), "Sil\u00ADben\u00ADtren\u00ADnung", deHyphenator("Silbentrennung"));
t.end();
});
t.test("hyphenate two words", function(t) {
t.test("hyphenate two words", function (t) {
t.equal(deHyphenator("Silbentrennung Algorithmus"), "Sil\u00ADben\u00ADtren\u00ADnung Al\u00ADgo\u00ADrith\u00ADmus", deHyphenator("Silbentrennung Algorithmus"));
t.end();
});
t.end();
});

t.test("run config with two languages", async function(t) {
t.test("run config with two languages", async function (t) {
const hyphenators = await H9Y.config({"require": ["de", "en-us"]});
t.test("return a Map", function(t) {
t.test("return a Map", function (t) {
t.type(hyphenators, Map);
t.end();
});
t.test("get the hyphenator function promise for a language", function(t) {
t.test("get the hyphenator function promise for a language", function (t) {
const deHyphenator = hyphenators.get("de");
t.type(deHyphenator, Promise);
t.end();
});
t.test("get the hyphenator function for a language", async function(t) {
t.test("get the hyphenator function for a language", async function (t) {
const deHyphenator = await hyphenators.get("de");
t.type(deHyphenator, Function);
t.end();
});
t.test("hyphenate one word of the first language", async function(t) {
t.test("hyphenate one word of the first language", async function (t) {
const deHyphenator = await hyphenators.get("de");
t.equal(deHyphenator("Silbentrennung"), "Sil\u00ADben\u00ADtren\u00ADnung", deHyphenator("Silbentrennung"));
t.end();
});
t.test("hyphenate two words of the first language", async function(t) {
t.test("hyphenate two words of the first language", async function (t) {
const deHyphenator = await hyphenators.get("de");
t.equal(deHyphenator("Silbentrennung Algorithmus"), "Sil\u00ADben\u00ADtren\u00ADnung Al\u00ADgo\u00ADrith\u00ADmus", deHyphenator("Silbentrennung Algorithmus"));
t.end();
});
t.test("hyphenate one word of the second language", async function(t) {
t.test("hyphenate one word of the second language", async function (t) {
const deHyphenator = await hyphenators.get("de");
t.equal(deHyphenator("Silbentrennung"), "Sil\u00ADben\u00ADtren\u00ADnung", deHyphenator("Silbentrennung"));
t.end();
});
t.test("hyphenate two words of the second language", async function(t) {
t.test("hyphenate two words of the second language", async function (t) {
const deHyphenator = await hyphenators.get("de");
t.equal(deHyphenator("Silbentrennung Algorithmus"), "Sil\u00ADben\u00ADtren\u00ADnung Al\u00ADgo\u00ADrith\u00ADmus", deHyphenator("Silbentrennung Algorithmus"));
t.end();
});
t.end();
});

t.test("run config with two same language", async function(t) {
t.test("run config with two same language", async function (t) {
const deHyphenator = await H9Y.config({"require": ["de", "de"]});
t.test("return a function", function(t) {
t.test("return a function", function (t) {
t.equal(typeof deHyphenator, "function", typeof deHyphenator);
t.end();
});
t.test("hyphenate one word", function(t) {
t.test("hyphenate one word", function (t) {
t.equal(deHyphenator("Silbentrennung"), "Sil\u00ADben\u00ADtren\u00ADnung", deHyphenator("Silbentrennung"));
t.end();
});
t.test("hyphenate two words", function(t) {
t.test("hyphenate two words", function (t) {
t.equal(deHyphenator("Silbentrennung Algorithmus"), "Sil\u00ADben\u00ADtren\u00ADnung Al\u00ADgo\u00ADrith\u00ADmus", deHyphenator("Silbentrennung Algorithmus"));
t.end();
});
t.end();
});
});
68 changes: 33 additions & 35 deletions test/configurations.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
// test/hello-world.js
var t = require("tap");
// const H9Y = require("../hyphenopoly.module");
/* eslint-env node */
/* eslint global-require: 0, func-names: 0, no-shadow: 0 */
"use strict";
const t = require("tap");

let H9Y = null;
const H9YKey = require.resolve("../hyphenopoly.module");

t.test("set options: compound", function(t) {
t.test("set options: compound", function (t) {
t.beforeEach(function setup(done) {
H9Y = require("../hyphenopoly.module");
done();
Expand All @@ -16,7 +18,7 @@ t.test("set options: compound", function(t) {
done();
});

t.test("compound: all", async function(t) {
t.test("compound: all", async function (t) {
const hyphenator = await H9Y.config({
"compound": "all",
"hyphen": "•",
Expand All @@ -25,7 +27,7 @@ t.test("set options: compound", function(t) {
t.equal(hyphenator("Silbentrennungs-Algorithmus"), "Sil•ben•tren•nungs-\u200BAl•go•rith•mus");
t.end();
});
t.test("compound: auto", async function(t) {
t.test("compound: auto", async function (t) {
const hyphenator = await H9Y.config({
"compound": "auto",
"hyphen": "•",
Expand All @@ -34,7 +36,7 @@ t.test("set options: compound", function(t) {
t.equal(hyphenator("Silbentrennungs-Algorithmus"), "Sil•ben•tren•nungs-Al•go•rith•mus");
t.end();
});
t.test("compound: hyphen", async function(t) {
t.test("compound: hyphen", async function (t) {
const hyphenator = await H9Y.config({
"compound": "hyphen",
"hyphen": "•",
Expand All @@ -43,7 +45,7 @@ t.test("set options: compound", function(t) {
t.equal(hyphenator("Silbentrennungs-Algorithmus"), "Silbentrennungs-\u200BAlgorithmus");
t.end();
});
t.test("compound: auto, one part too small", async function(t) {
t.test("compound: auto, one part too small", async function (t) {
const hyphenator = await H9Y.config({
"compound": "auto",
"hyphen": "•",
Expand All @@ -52,7 +54,7 @@ t.test("set options: compound", function(t) {
t.equal(hyphenator("Test-Algorithmus"), "Test-Al•go•rith•mus");
t.end();
});
t.test("compound: all, one part too small", async function(t) {
t.test("compound: all, one part too small", async function (t) {
const hyphenator = await H9Y.config({
"compound": "all",
"hyphen": "•",
Expand All @@ -64,7 +66,7 @@ t.test("set options: compound", function(t) {
t.end();
});

t.test("set options: exceptions", function(t) {
t.test("set options: exceptions", function (t) {
t.beforeEach(function setup(done) {
H9Y = require("../hyphenopoly.module");
done();
Expand All @@ -76,18 +78,16 @@ t.test("set options: exceptions", function(t) {
done();
});

t.test("exceptions: global (only)", async function(t) {
t.test("exceptions: global (only)", async function (t) {
const hyphenator = await H9Y.config({
"exceptions": {
"global": "Silben-trennung"
},
"exceptions": {"global": "Silben-trennung"},
"hyphen": "•",
"require": ["de"]
});
t.equal(hyphenator("Silbentrennung"), "Silben•trennung");
t.end();
});
t.test("exceptions: global and lang", async function(t) {
t.test("exceptions: global and lang", async function (t) {
const hyphenator = await H9Y.config({
"exceptions": {
"de": "Algo-rithmus",
Expand All @@ -99,11 +99,9 @@ t.test("set options: exceptions", function(t) {
t.equal(hyphenator("Silbentrennung Algorithmus"), "Silben•trennung Algo•rithmus");
t.end();
});
t.test("exceptions: double entry", async function(t) {
t.test("exceptions: double entry", async function (t) {
const hyphenator = await H9Y.config({
"exceptions": {
"de": "Algo-rithmus, Algo-rithmus"
},
"exceptions": {"de": "Algo-rithmus, Algo-rithmus"},
"hyphen": "•",
"require": ["de"]
});
Expand All @@ -113,7 +111,7 @@ t.test("set options: exceptions", function(t) {
t.end();
});

t.test("set options: hyphen", function(t) {
t.test("set options: hyphen", function (t) {
t.beforeEach(function setup(done) {
H9Y = require("../hyphenopoly.module");
done();
Expand All @@ -125,15 +123,15 @@ t.test("set options: hyphen", function(t) {
done();
});

t.test("hyphen: •", async function(t) {
t.test("hyphen: •", async function (t) {
const hyphenator = await H9Y.config({
"hyphen": "•",
"require": ["de"]
});
t.equal(hyphenator("Silbentrennung"), "Sil•ben•tren•nung");
t.end();
});
t.test("hyphen: |", async function(t) {
t.test("hyphen: |", async function (t) {
const hyphenator = await H9Y.config({
"hyphen": "|",
"require": ["de"]
Expand All @@ -144,7 +142,7 @@ t.test("set options: hyphen", function(t) {
t.end();
});

t.test("set options: left-/rightmin", function(t) {
t.test("set options: left-/rightmin", function (t) {
t.beforeEach(function setup(done) {
H9Y = require("../hyphenopoly.module");
done();
Expand All @@ -156,7 +154,7 @@ t.test("set options: left-/rightmin", function(t) {
done();
});

t.test("left-/rightmin: 4, 5", async function(t) {
t.test("left-/rightmin: 4, 5", async function (t) {
const hyphenator = await H9Y.config({
"hyphen": "•",
"leftmin": 4,
Expand All @@ -169,7 +167,7 @@ t.test("set options: left-/rightmin", function(t) {
t.end();
});

t.test("set options: minWordLength", function(t) {
t.test("set options: minWordLength", function (t) {
t.beforeEach(function setup(done) {
H9Y = require("../hyphenopoly.module");
done();
Expand All @@ -181,7 +179,7 @@ t.test("set options: minWordLength", function(t) {
done();
});

t.test("minWordLength: 7", async function(t) {
t.test("minWordLength: 7", async function (t) {
const hyphenator = await H9Y.config({
"hyphen": "•",
"minWordLength": 7,
Expand All @@ -193,7 +191,7 @@ t.test("set options: minWordLength", function(t) {
t.end();
});

t.test("set options: normalize", function(t) {
t.test("set options: normalize", function (t) {
t.beforeEach(function setup(done) {
H9Y = require("../hyphenopoly.module");
done();
Expand All @@ -205,7 +203,7 @@ t.test("set options: normalize", function(t) {
done();
});

t.test("normalize: true", async function(t) {
t.test("normalize: true", async function (t) {
const hyphenator = await H9Y.config({
"hyphen": "•",
"normalize": true,
Expand All @@ -217,7 +215,7 @@ t.test("set options: normalize", function(t) {
t.end();
});

t.test("set options: orphanControl", function(t) {
t.test("set options: orphanControl", function (t) {
t.beforeEach(function setup(done) {
H9Y = require("../hyphenopoly.module");
done();
Expand All @@ -229,15 +227,15 @@ t.test("set options: orphanControl", function(t) {
done();
});

t.test("orphanControl: 1 (default)", async function(t) {
t.test("orphanControl: 1 (default)", async function (t) {
const hyphenator = await H9Y.config({
"hyphen": "•",
"require": ["de"]
});
t.equal(hyphenator("Die Asse essen lieber gesunde Esswaren"), "Die Asse essen lie•ber ge•sun•de Ess•wa•ren");
t.end();
});
t.test("orphanControl: 2", async function(t) {
t.test("orphanControl: 2", async function (t) {
const hyphenator = await H9Y.config({
"hyphen": "•",
"orphanControl": 2,
Expand All @@ -246,7 +244,7 @@ t.test("set options: orphanControl", function(t) {
t.equal(hyphenator("Die Asse essen lieber gesunde Esswaren"), "Die Asse essen lie•ber ge•sun•de Esswaren");
t.end();
});
t.test("orphanControl: 2, hyphen: |", async function(t) {
t.test("orphanControl: 2, hyphen: |", async function (t) {
const hyphenator = await H9Y.config({
"hyphen": "|",
"orphanControl": 2,
Expand All @@ -255,14 +253,14 @@ t.test("set options: orphanControl", function(t) {
t.equal(hyphenator("Die Asse essen lieber gesunde Esswaren"), "Die Asse essen lie|ber ge|sun|de Esswaren");
t.end();
});
t.test("orphanControl: 3", async function(t) {
t.test("orphanControl: 3", async function (t) {
const hyphenator = await H9Y.config({
"hyphen": "•",
"orphanControl": 3,
"require": ["de"]
});
t.equal(hyphenator("Die Asse essen lieber gesunde Esswaren"), `Die Asse essen lie•ber ge•sun•de\u00A0Esswaren`);
t.equal(hyphenator("Die Asse essen lieber gesunde Esswaren"), "Die Asse essen lie•ber ge•sun•de\u00A0Esswaren");
t.end();
});
t.end();
});
});
Loading

0 comments on commit b27a765

Please sign in to comment.