Skip to content

Commit

Permalink
fixes #41
Browse files Browse the repository at this point in the history
fixes #44
and some small changes

Squashed commit of the following:

commit 2df8ad62d63837435c38aee264c8f31426fda239
Author: mnater <mathiasnater@gmail.com>
Date:   Fri Nov 23 15:07:30 2018 +0100

    fix test18

commit 22ed6e0f9aa6aa5b845097a5cbc3d2a77619ec28
Author: mnater <mathiasnater@gmail.com>
Date:   Fri Nov 23 07:50:31 2018 +0100

    fix test5 (sr-latn)

commit 63cb1a018581df6a424c9ce63beb032ff1c84aec
Author: mnater <mathiasnater@gmail.com>
Date:   Thu Nov 22 23:37:08 2018 +0100

    fix removing of non exstend styles element

commit 7fee39baaef346c6182a7659fb91a43e528650fc
Author: mnater <mathiasnater@gmail.com>
Date:   Thu Nov 22 23:28:39 2018 +0100

    remove log

commit 8bb7d7f7e18ec4c4ba227706e21064756a9240c7
Author: mnater <mathiasnater@gmail.com>
Date:   Thu Nov 22 23:28:21 2018 +0100

    make langs case-insensitiv

commit 3be0877315d6da7d1e20af5caa2bc27f4f39a422
Merge: 2da4508 aae3fd2
Author: mnater <mathiasnater@gmail.com>
Date:   Tue Nov 20 21:56:37 2018 +0100

    Merge branch 'master' into lang

commit 2da4508135882ffb3127f060f1deea2d7c29f502
Author: mnater <mathiasnater@gmail.com>
Date:   Tue Nov 20 21:52:10 2018 +0100

    create testcase
  • Loading branch information
mnater committed Nov 23, 2018
1 parent aae3fd2 commit 746577e
Show file tree
Hide file tree
Showing 6 changed files with 164 additions and 39 deletions.
35 changes: 23 additions & 12 deletions Hyphenopoly_Loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,24 @@
"timeout": 1000
};
}
H.lcRequire = empty();
Object.keys(H.require).forEach(function copyRequire(k) {
H.lcRequire[k.toLowerCase()] = H.require[k];
});
if (H.fallbacks) {
H.lcFallbacks = empty();
Object.keys(H.fallbacks).forEach(function copyFallbacks(k) {
H.lcFallbacks[k.toLowerCase()] = H.fallbacks[k].toLowerCase();
});
}
}());

H.toggle = function toggle(state) {
if (state === "on") {
d.getElementsByTagName("head")[0].removeChild(d.getElementById("H9Y_Styles"));
const stylesNode = d.getElementById("H9Y_Styles");
if (stylesNode) {
stylesNode.parentNode.removeChild(stylesNode);
}
} else {
const sc = d.createElement("style");
sc.id = "H9Y_Styles";
Expand Down Expand Up @@ -341,8 +354,8 @@
* @returns {undefined}
*/
function fetchBinary(p, f, n, m) {
if (!loadedBins[f]) {
loadedBins[f] = true;
if (!loadedBins[n]) {
loadedBins[n] = true;
window.fetch(p + f).then(
function resolve(response) {
if (response.ok) {
Expand Down Expand Up @@ -383,7 +396,6 @@
xhr.send();
}
}

if (H.clientFeat.wasm) {
fetchBinary(path, fne, name, msg);
} else {
Expand Down Expand Up @@ -445,8 +457,8 @@
*/
function loadRessources(lang) {
let filename = lang + ".hpb";
if (H.fallbacks && H.fallbacks[lang]) {
filename = H.fallbacks[lang] + ".hpb";
if (H.lcFallbacks && H.lcFallbacks[lang]) {
filename = H.lcFallbacks[lang] + ".hpb";
}
if (!H.binaries) {
H.binaries = empty();
Expand Down Expand Up @@ -506,7 +518,7 @@
testDiv.lang = lang;
testDiv.id = lang;
testDiv.style.cssText = css;
testDiv.appendChild(d.createTextNode(H.require[lang]));
testDiv.appendChild(d.createTextNode(H.lcRequire[lang]));
fakeBody.appendChild(testDiv);
}

Expand Down Expand Up @@ -578,7 +590,6 @@
}
}, true);
H.events.addListener("error", function handler(e) {
e.preventDefault();
if (e.key === lang || e.key === "hyphenEngine") {
rj(e.msg);
}
Expand All @@ -602,8 +613,8 @@
}
}

Object.keys(H.require).forEach(function doReqLangs(lang) {
if (H.require[lang] === "FORCEHYPHENOPOLY") {
Object.keys(H.lcRequire).forEach(function doReqLangs(lang) {
if (H.lcRequire[lang] === "FORCEHYPHENOPOLY") {
H.clientFeat.polyfill = true;
H.clientFeat.langs[lang] = "H9Y";
loadRessources(lang);
Expand All @@ -620,8 +631,8 @@
});
const testContainer = tester.appendTests(d.documentElement);
if (testContainer !== null) {
Object.keys(H.require).forEach(function checkReqLangs(lang) {
if (H.require[lang] !== "FORCEHYPHENOPOLY") {
Object.keys(H.lcRequire).forEach(function checkReqLangs(lang) {
if (H.lcRequire[lang] !== "FORCEHYPHENOPOLY") {
const el = d.getElementById(lang);
if (checkCSSHyphensSupport(el) && el.offsetHeight > 12) {
H.clientFeat.langs[lang] = "CSS";
Expand Down
11 changes: 2 additions & 9 deletions testsuite/test18.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@
test = document.getElementById("test" + i).innerHTML;
ref = document.getElementById("ref" + i).innerHTML;
if (test === ref) {
document.getElementById("result").innerHTML += "<p style=\"background-color: #d6ffd6\">" + i + " passed</p>";
document.getElementById("result").innerHTML += "<span style=\"background-color: #d6ffd6\">" + i + "</span> ";
result = result || true;
} else {
document.getElementById("result").innerHTML += "<p style=\"background-color: #ffd6d6\">" + i + " failed</p>";
document.getElementById("result").innerHTML += "<span style=\"background-color: #ffd6d6\">" + i + "</span> ";
result = result || false;
}
i += 1;
Expand Down Expand Up @@ -80,13 +80,6 @@
.ref {
background-color: #FEEFC0;
}

.hyphenate {
hyphens: auto;
-ms-hyphens: auto;
-moz-hyphens: auto;
-webkit-hyphens: auto;
}
</style>
</head>
<body>
Expand Down
1 change: 0 additions & 1 deletion testsuite/test28.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
<script>
function assert(el) {
elCount += 1;
console.log(document.getElementById("H9Y_Styles"));
switch (hide_mode) {
case "all":
testresult = testresult && (document.getElementById("H9Y_Styles").innerHTML === "html {visibility: hidden !important}");
Expand Down
119 changes: 119 additions & 0 deletions testsuite/test29.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Test 029</title>
<script>
var Hyphenopoly = {
require: {
"en-us": "FORCEHYPHENOPOLY",
"en-au": "FORCEHYPHENOPOLY",
"de": "FORCEHYPHENOPOLY",
"de-ch": "FORCEHYPHENOPOLY",
"fr": "FORCEHYPHENOPOLY"
},
fallbacks: {
"en-au": "en-gb",
"de-ch": "de"
},
paths: {
maindir: "../",
patterndir: "../patterns/"
},
setup: {
hide: "all",
classnames: {
"hyphenate": {
hyphen: "|"
}
}
},
handleEvent: {
hyphenopolyEnd: function (e) {
assert();
}
}
};

function assert() {
var tests = 6;
var i = 1;
var test = "";
var ref = "";
var result = true;
while (i <= tests) {
test = document.getElementById("test" + i).innerHTML;
ref = document.getElementById("ref" + i).innerHTML;
if (test === ref) {
document.getElementById("result").innerHTML += "<span style=\"background-color: #d6ffd6\">" + (function (i) {
return (i < 10) ? "0" + i : i;
}(i)) + "</span> ";
result = result && true;
} else {
document.getElementById("result").innerHTML += "<span style=\"background-color: #ffd6d6\">" + (function (i) {
return (i < 10) ? "0" + i : i;
}(i)) + "</span> ";
result = false;
}
i += 1;
}
if (parent != window) {
parent.postMessage(JSON.stringify({
desc: document.getElementById("desc").innerHTML,
index: 29,
result: (result ? "passed" : "failed")
}), window.location.href);
}
}
</script>
<script src="../Hyphenopoly_Loader.js"></script>
<style type="text/css">
body {
width:50%;
margin-left:25%;
margin-right:25%;
}

.test {
background-color: #D8E2F9;
}
.ref {
background-color: #FEEFC0;
}

</style>
</head>
<body>
<div id="navigate"><a href="index.html">&Larr;&nbsp;Index</a>&nbsp;|&nbsp;<a href="test28.html">&larr;&nbsp;Prev</a>&nbsp;|&nbsp;<a href="test30.html">Next&nbsp;&rarr;</a></div>

<h1>Test 029</h1>
<p id="desc">Check case-insensitiveness of lang attributes and fallbacks.</p>
<div id="result">R: </div>
<hr>
<h2>1: en-us</h2>
<p id="test1" class="test hyphenate" lang="en-us">A hyphenation algorithm is a set of rules that decides at which points a word can be broken over two lines with a hyphen.</p>
<p id="ref1" class="ref" lang="en-us">A hy|phen|ation al|go|rithm is a set of rules that de|cides at which points a word can be bro|ken over two lines with a hy|phen.</p>

<h2>2: en-US</h2>
<p id="test2" class="test hyphenate" lang="en-US">A hyphenation algorithm is a set of rules that decides at which points a word can be broken over two lines with a hyphen.</p>
<p id="ref2" class="ref" lang="en-US">A hy|phen|ation al|go|rithm is a set of rules that de|cides at which points a word can be bro|ken over two lines with a hy|phen.</p>

<h2>3: en-au (fallback to en-gb)</h2>
<p id="test3" class="test hyphenate" lang="en-au">A hyphenation algorithm is a set of rules that decides at which points a word can be broken over two lines with a hyphen.</p>
<p id="ref3" class="ref" lang="en-au">A hy|phen|a|tion al|gorithm is a set of rules that de|cides at which points a word can be broken over two lines with a hy|phen.</p>

<h2>4: en-AU (fallback to en-gb)</h2>
<p id="test4" class="test hyphenate" lang="en-AU">A hyphenation algorithm is a set of rules that decides at which points a word can be broken over two lines with a hyphen.</p>
<p id="ref4" class="ref" lang="en-AU">A hy|phen|a|tion al|gorithm is a set of rules that de|cides at which points a word can be broken over two lines with a hy|phen.</p>

<h2>5: de</h2>
<p id="test5" class="test hyphenate" lang="de">Die Worttrennung, auch Silbentrennung genannt, bezeichnet in der Orthographie die Art und Weise, wie die Wörter insbesondere am Zeilenende getrennt werden können.</p>
<p id="ref5" class="ref" class="ref" lang="de">Die Wort|tren|nung, auch Sil|ben|tren|nung ge|nannt, be|zeich|net in der Or|tho|gra|phie die Art und Weise, wie die Wör|ter ins|be|son|de|re am Zei|len|en|de ge|trennt wer|den kön|nen.</p>

<h2>6: de-DE (fallback to de)</h2>
<p id="test6" class="test hyphenate" lang="de-CH">Die Worttrennung, auch Silbentrennung genannt, bezeichnet in der Orthographie die Art und Weise, wie die Wörter insbesondere am Zeilenende getrennt werden können.</p>
<p id="ref6" class="ref" class="ref" lang="de-CH">Die Wort|tren|nung, auch Sil|ben|tren|nung ge|nannt, be|zeich|net in der Or|tho|gra|phie die Art und Weise, wie die Wör|ter ins|be|son|de|re am Zei|len|en|de ge|trennt wer|den kön|nen.</p>
<hr>
<div><span class="test">Test</span> <span class="ref">Ref</span></div>
</body>
</html>
34 changes: 18 additions & 16 deletions testsuite/test5.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,14 @@
"ca": "FORCEHYPHENOPOLY",
"sk": "FORCEHYPHENOPOLY",
"eo": "FORCEHYPHENOPOLY",
"sr-latn": "FORCEHYPHENOPOLY",
"ro": "FORCEHYPHENOPOLY",
"et": "FORCEHYPHENOPOLY",
"ga": "FORCEHYPHENOPOLY"
},
fallbacks: {
"sr-latn": "sh-latn"
},
paths: {
maindir: "../",
patterndir: "../patterns/"
Expand All @@ -58,20 +62,18 @@
var ref = "";
var result = true;
while (i <= tests) {
if (i !== 23) {
test = document.getElementById("test" + i).innerHTML;
ref = document.getElementById("ref" + i).innerHTML;
if (test === ref) {
document.getElementById("result").innerHTML += "<span style=\"background-color: #d6ffd6\">" + (function (i) {
return (i < 10) ? "0" + i : i;
}(i)) + "</span> ";
result = result && true;
} else {
document.getElementById("result").innerHTML += "<span style=\"background-color: #ffd6d6\">" + (function (i) {
return (i < 10) ? "0" + i : i;
}(i)) + "</span> ";
result = false;
}
test = document.getElementById("test" + i).innerHTML;
ref = document.getElementById("ref" + i).innerHTML;
if (test === ref) {
document.getElementById("result").innerHTML += "<span style=\"background-color: #d6ffd6\">" + (function (i) {
return (i < 10) ? "0" + i : i;
}(i)) + "</span> ";
result = result && true;
} else {
document.getElementById("result").innerHTML += "<span style=\"background-color: #ffd6d6\">" + (function (i) {
return (i < 10) ? "0" + i : i;
}(i)) + "</span> ";
result = false;
}
i += 1;
}
Expand Down Expand Up @@ -181,9 +183,9 @@ <h2>21: sk</h2>
<h2>22: eo</h2>
<p id="test22" class="test hyphenate" lang="eo">Tipografio unuavice estas la kreo de komunikaĵo per reproduktebla skribo, sed duavice ankaŭ la dezajno de tia skriba komunikaĵo per linioj, areoj kaj la specifa aranĝo de literoj.</p>
<p id="ref22" class="ref" lang="eo">Ti|po|gra|fio unu|a|vi|ce estas la kreo de ko|mu|ni|k|aĵo per re|pro|duk|t|ebla skri|bo, sed du|a|vi|ce ankaŭ la de|zaj|no de tia skri|ba ko|mu|ni|k|aĵo per li|ni|oj, areoj kaj la spe|ci|fa aran|ĝo de li|te|roj.</p>
<!--<h2>23: sr-latn</h2>
<h2>23: sr-latn</h2>
<p id="test23" class="test hyphenate" lang="sr-latn">Tipografija se bavi izborom i organizacijom oblika slova i drugih grafičkih karakteristika štampane strane.</p>
<p id="ref23" class="ref" lang="sr-Latn">Ti|po|gra|fi|ja se bavi iz|bo|rom i or|ga|ni|za|ci|jom obli|ka slova i dru|gih gra|fič|kih ka|rak|te|ri|sti|ka štam|pa|ne stra|ne.</p>-->
<p id="ref23" class="ref" lang="sr-Latn">Ti|po|gra|fi|ja se bavi iz|bo|rom i or|ga|ni|za|ci|jom obli|ka slova i dru|gih gra|fič|kih ka|rak|te|ri|sti|ka štam|pa|ne stra|ne.</p>
<h2>24: ro</h2>
<p id="test24" class="test hyphenate" lang="ro">Tipografia reprezintă arta și tehnica tipăritului, a formei și aranjării literelor pe un document scris.</p>
<p id="ref24" class="ref" lang="ro">Ti|po|gra|fia re|pre|zin|tă arta și teh|ni|ca ti|pă|ri|tu|lui, a for|mei și aran|jă|rii li|te|re|lor pe un do|cu|ment scris.</p>
Expand Down
3 changes: 2 additions & 1 deletion testsuite/testdriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
{exec: true, path: "test25.html"},
{exec: true, path: "test26.html"},
{exec: true, path: "test27.html"},
{exec: true, path: "test28.html"}
{exec: true, path: "test28.html"},
{exec: true, path: "test29.html"}
];
var testframe = document.getElementById("testframe");
var currentTest = 1;
Expand Down

0 comments on commit 746577e

Please sign in to comment.