Skip to content

Commit

Permalink
fix: cleanup mess after merging PRs.
Browse files Browse the repository at this point in the history
*   reintegrate eachKey()
*   correctly handle errors
*   cleanup test44
*   reuse test16

[skip travis-ci]
  • Loading branch information
mnater committed Apr 16, 2020
1 parent ecdd7c8 commit 937af4b
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 30 deletions.
32 changes: 21 additions & 11 deletions Hyphenopoly.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@
return Object.create(null);
}

/**
* Shorthand for Object.keys(obj).forEach(() => {})
* @param {Object} obj the object to iterate
* @param {function} fn the function to execute
* @returns {undefined}
*/
function eachKey(obj, fn) {
Object.keys(obj).forEach(fn);
}

/**
* Set value and properties of object member
* Argument <props> is a bit pattern:
Expand Down Expand Up @@ -644,9 +654,12 @@
function createStringHyphenator(lang) {
return ((entity, sel = ".hyphenate") => {
if (typeof entity !== "string") {
H.events.get("error").resolve({
"msg": "This use of hyphenators is deprecated. See https://mnater.github.io/Hyphenopoly/Hyphenators.html"
});
event.fire(
"error",
{
"msg": "This use of hyphenators is deprecated. See https://mnater.github.io/Hyphenopoly/Hyphenators.html"
}
);
}
return hyphenate(lang, sel, entity);
});
Expand Down Expand Up @@ -935,14 +948,6 @@
elements.rem(lang);
});
/* eslint-disable security/detect-object-injection */
H.hyphenators[lang].catch((e) => {
event.fire(
"error",
{
"msg": e.msg
}
);
});
H.hyphenators[lang].reject({
"msg": `File ${lang}.wasm can't be loaded from ${H.paths.patterndir}`
});
Expand Down Expand Up @@ -984,6 +989,11 @@
}, [])
).then(() => {
H.hyphenators.HTML.resolve(createDOMHyphenator());
}, (e) => {
event.fire(
"error",
e
);
});
})(Hyphenopoly);
})(window);
29 changes: 15 additions & 14 deletions testsuite/test16.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
<script>
var Hyphenopoly = {
require: {
"en-us": "FORCEHYPHENOPOLY"
"en-us": "FORCEHYPHENOPOLY",
"de": "FORCEHYPHENOPOLY",
"it": "FORCEHYPHENOPOLY"
},
setup: {
selectors: {
Expand All @@ -16,26 +18,25 @@
}
},
handleEvent: {
myFantasyEvent: function (e) {
console.log(e);
},
error: function (e) {
e.preventDefault();
//e.preventDefault();
assert(e);
}
}
};

let test = true;
let count = 0;
function assert(e) {
console.log(e);
var test = "unknown Event \"myFantasyEvent\" discarded";
count += 1;
var test1 = "engine for language 'it' loaded, but no elements found.";
var test2 = "engine for language 'de' loaded, but no elements found.";
var ref = e.msg;
var result = true;
if (test === ref) {
document.getElementById("result").innerHTML += "<span style=\"background-color: #d6ffd6\">passed</span> ";
if (test1 === ref || test2 === ref) {
document.getElementById("result").innerHTML += `<span style="background-color: #d6ffd6">${count}</span> `;
result = result && true;
} else {
document.getElementById("result").innerHTML += "<span style=\"background-color: #ffd6d6\">failed</span> ";
document.getElementById("result").innerHTML += `<span style="background-color: #ffd6d6">${count}</span> `;
result = false;
}
if (parent != window) {
Expand Down Expand Up @@ -74,11 +75,11 @@
<div id="navigate"><a href="index.html">&Larr;&nbsp;Index</a>&nbsp;|&nbsp;<a href="test15.html">&larr;&nbsp;Prev</a>&nbsp;|&nbsp;<a href="test17.html">Next&nbsp;&rarr;</a></div>

<h1>Test 016</h1>
<p id="desc">Discard unknown Events</p>
<p id="desc">Warn about unnecessary loaded patterns.</p>
<div id="result"></div>
<hr>
<p id="test1" class="test hyphenate" lang="en-us">unknown Event "myFantasyEvent" discarded</p>
<p id="ref1" class="ref" lang="en">unknown Event "myFantasyEvent" discarded</p>
<p id="test1" class="test hyphenate" lang="en-us">See console.</p>
<p id="ref1" class="ref" lang="en">See con•sole.</p>
<hr>
<div><span class="test">Test</span> <span class="ref">Ref</span></div>

Expand Down
5 changes: 1 addition & 4 deletions testsuite/test44.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@
<script>
var Hyphenopoly = {
require: {
"en-us": "FORCEHYPHENOPOLY",
"de": "FORCEHYPHENOPOLY",
"fr": "FORCEHYPHENOPOLY",
"it": "FORCEHYPHENOPOLY",
"en-us": "FORCEHYPHENOPOLY"
},
handleEvent: {
hyphenopolyEnd: function (e) {
Expand Down
2 changes: 1 addition & 1 deletion testsuite/testdriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
{"exec": true, "path": "test13.html"},
{"exec": true, "path": "test14.html"},
{"exec": true, "path": "test15.html"},
{"exec": false, "path": "test16.html"},
{"exec": true, "path": "test16.html"},
{"exec": true, "path": "test17.html"},
{"exec": true, "path": "test18.html"},
{"exec": true, "path": "test19.html"},
Expand Down

0 comments on commit 937af4b

Please sign in to comment.