123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306 |
- /* eslint-env node */
- /* eslint global-require: 0, func-names: 0, no-shadow: 0 */
- "use strict";
- const t = require("tap");
- t.test("set options: compound", function (t) {
- let H9Y = null;
- t.beforeEach(function setup(done) {
- H9Y = require("../hyphenopoly.module");
- done();
- });
- t.afterEach(function tearDown(done) {
- H9Y = null;
- delete require.cache[require.resolve("../hyphenopoly.module")];
- done();
- });
- t.test("compound: all", async function (t) {
- const hyphenator = await H9Y.config({
- "compound": "all",
- "hyphen": "•",
- "require": ["de"]
- });
- t.equal(hyphenator("Silbentrennungs-Algorithmus"), "Sil•ben•tren•nungs-\u200BAl•go•rith•mus");
- t.end();
- });
- t.test("compound: auto", async function (t) {
- const hyphenator = await H9Y.config({
- "compound": "auto",
- "hyphen": "•",
- "require": ["de"]
- });
- t.equal(hyphenator("Silbentrennungs-Algorithmus"), "Sil•ben•tren•nungs-Al•go•rith•mus");
- t.end();
- });
- t.test("compound: hyphen", async function (t) {
- const hyphenator = await H9Y.config({
- "compound": "hyphen",
- "hyphen": "•",
- "require": ["de"]
- });
- t.equal(hyphenator("Silbentrennungs-Algorithmus"), "Silbentrennungs-\u200BAlgorithmus");
- t.end();
- });
- t.test("compound: auto, one part too small", async function (t) {
- const hyphenator = await H9Y.config({
- "compound": "auto",
- "hyphen": "•",
- "require": ["de"]
- });
- t.equal(hyphenator("Test-Algorithmus"), "Test-Al•go•rith•mus");
- t.end();
- });
- t.test("compound: all, one part too small", async function (t) {
- const hyphenator = await H9Y.config({
- "compound": "all",
- "hyphen": "•",
- "require": ["de"]
- });
- t.equal(hyphenator("Test-Algorithmus"), "Test-\u200BAl•go•rith•mus");
- t.end();
- });
- t.end();
- });
- t.test("set options: exceptions", function (t) {
- let H9Y = null;
- t.beforeEach(function setup(done) {
- H9Y = require("../hyphenopoly.module");
- done();
- });
- t.afterEach(function tearDown(done) {
- H9Y = null;
- delete require.cache[require.resolve("../hyphenopoly.module")];
- done();
- });
- t.test("exceptions: global (only)", async function (t) {
- const hyphenator = await H9Y.config({
- "exceptions": {"global": "Silben-trennung"},
- "hyphen": "•",
- "require": ["de"]
- });
- t.equal(hyphenator("Silbentrennung"), "Silben•trennung");
- t.end();
- });
- t.test("exceptions: global and lang", async function (t) {
- const hyphenator = await H9Y.config({
- "exceptions": {
- "de": "Algo-rithmus",
- "global": "Silben-trennung"
- },
- "hyphen": "•",
- "require": ["de"]
- });
- t.equal(hyphenator("Silbentrennung Algorithmus"), "Silben•trennung Algo•rithmus");
- t.end();
- });
- t.test("exceptions: double entry", async function (t) {
- const hyphenator = await H9Y.config({
- "exceptions": {"de": "Algo-rithmus, Algo-rithmus"},
- "hyphen": "•",
- "require": ["de"]
- });
- t.equal(hyphenator("Algorithmus"), "Algo•rithmus");
- t.end();
- });
- t.end();
- });
- t.test("set options: hyphen", function (t) {
- let H9Y = null;
- t.beforeEach(function setup(done) {
- H9Y = require("../hyphenopoly.module");
- done();
- });
- t.afterEach(function tearDown(done) {
- H9Y = null;
- delete require.cache[require.resolve("../hyphenopoly.module")];
- done();
- });
- 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) {
- const hyphenator = await H9Y.config({
- "hyphen": "|",
- "require": ["de"]
- });
- t.equal(hyphenator("Silbentrennung"), "Sil|ben|tren|nung");
- t.end();
- });
- t.end();
- });
- t.test("set options: left-/rightmin (patterns: 2/2)", function (t) {
- let H9Y = null;
- t.beforeEach(function setup(done) {
- H9Y = require("../hyphenopoly.module");
- done();
- });
- t.afterEach(function tearDown(done) {
- H9Y = null;
- delete require.cache[require.resolve("../hyphenopoly.module")];
- done();
- });
- t.test("left-/rightmin: 4, 5", async function (t) {
- const hyphenator = await H9Y.config({
- "hyphen": "•",
- "leftmin": 4,
- "require": ["de"],
- "rightmin": 5
- });
- t.equal(hyphenator("Silbentrennung"), "Silben•trennung");
- t.end();
- });
- t.end();
- });
- t.test("set options: left-/rightmin (patterns: 2/3)", function (t) {
- let H9Y = null;
- t.beforeEach(function setup(done) {
- H9Y = require("../hyphenopoly.module");
- done();
- });
- t.afterEach(function tearDown(done) {
- H9Y = null;
- delete require.cache[require.resolve("../hyphenopoly.module")];
- done();
- });
- t.test("left-/rightmin: 2, 2", async function (t) {
- const hyphenator = await H9Y.config({
- "hyphen": "•",
- "leftmin": 2,
- "require": ["pt"],
- "rightmin": 2
- });
- t.equal(hyphenator("relativo"), "re•la•ti•vo");
- t.end();
- });
- t.test("left-/rightmin: def, def", async function (t) {
- const hyphenator = await H9Y.config({
- "hyphen": "•",
- "require": ["pt"]
- });
- t.equal(hyphenator("relativo"), "re•la•tivo");
- t.end();
- });
- t.end();
- });
- t.test("set options: minWordLength", function (t) {
- let H9Y = null;
- t.beforeEach(function setup(done) {
- H9Y = require("../hyphenopoly.module");
- done();
- });
- t.afterEach(function tearDown(done) {
- H9Y = null;
- delete require.cache[require.resolve("../hyphenopoly.module")];
- done();
- });
- t.test("minWordLength: 7", async function (t) {
- const hyphenator = await H9Y.config({
- "hyphen": "•",
- "minWordLength": 7,
- "require": ["de"]
- });
- t.equal(hyphenator("Die Asse essen lieber gesunde Esswaren"), "Die Asse essen lieber ge•sun•de Ess•wa•ren");
- t.end();
- });
- t.end();
- });
- t.test("set options: normalize", function (t) {
- let H9Y = null;
- t.beforeEach(function setup(done) {
- H9Y = require("../hyphenopoly.module");
- done();
- });
- t.afterEach(function tearDown(done) {
- H9Y = null;
- delete require.cache[require.resolve("../hyphenopoly.module")];
- done();
- });
- t.test("normalize: true", async function (t) {
- const hyphenator = await H9Y.config({
- "hyphen": "•",
- "normalize": true,
- "require": ["de"]
- });
- t.equal(hyphenator("Ba\u0308rento\u0308ter"), "Bä•ren•tö•ter");
- t.end();
- });
- t.end();
- });
- t.test("set options: orphanControl", function (t) {
- let H9Y = null;
- t.beforeEach(function setup(done) {
- H9Y = require("../hyphenopoly.module");
- done();
- });
- t.afterEach(function tearDown(done) {
- H9Y = null;
- delete require.cache[require.resolve("../hyphenopoly.module")];
- done();
- });
- 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) {
- const hyphenator = await H9Y.config({
- "hyphen": "•",
- "orphanControl": 2,
- "require": ["de"]
- });
- 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) {
- const hyphenator = await H9Y.config({
- "hyphen": "|",
- "orphanControl": 2,
- "require": ["de"]
- });
- 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) {
- 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.end();
- });
- t.end();
- });
|