test38.html 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  5. <title>Test 038</title>
  6. <script>
  7. var mode = window.location.search.substring(1);
  8. var path = "../patterns/";
  9. var result = false;
  10. var Hyphenopoly = {
  11. require: {
  12. "de": "FORCEHYPHENOPOLY",
  13. "en": "FORCEHYPHENOPOLY"
  14. },
  15. paths: {
  16. patterndir: path
  17. },
  18. setup: {
  19. selectors: {
  20. ".hyphenate": {
  21. hyphen: "|",
  22. minWordLength: 4
  23. }
  24. }
  25. }
  26. };
  27. window.onload = function () {
  28. if (window.Promise) {
  29. function hyphenate_en(text) {
  30. Hyphenopoly.hyphenators["en"].then(
  31. function (enhyph) {
  32. document.getElementById("test1").innerText = enhyph(text);
  33. assertAll();
  34. }).catch(function(e) {
  35. assertError(e);
  36. });
  37. }
  38. function hyphenate_de(text) {
  39. Hyphenopoly.hyphenators["de"].then(
  40. function (dehyph) {
  41. document.getElementById("test2").innerText = dehyph(text);
  42. assertAll();
  43. }).catch(function(e) {
  44. assertError(e);
  45. });
  46. }
  47. hyphenate_en("hyphenation algorithm");
  48. hyphenate_de("Silbentrennungsalgorithmus");
  49. } else {
  50. result = false
  51. if (parent != window) {
  52. parent.postMessage(JSON.stringify({
  53. desc: document.getElementById("desc").innerHTML,
  54. index: 38,
  55. result: (result ? "passed" : "failed")
  56. }), window.location.href);
  57. }
  58. }
  59. };
  60. function assertError(e) {
  61. if (e.message.indexOf("File en.hpb can't be loaded from ../patterns/") !== -1) {
  62. result = true;
  63. }
  64. if (result) {
  65. document.getElementById("result").innerHTML += "<p style=\"background-color: #d6ffd6\">" + 1 + " passed</p>";
  66. }
  67. }
  68. function assertAll() {
  69. var tests = 2;
  70. var i = 2;
  71. var test = "";
  72. var ref = "";
  73. while (i <= tests) {
  74. test = document.getElementById("test" + i).innerHTML;
  75. ref = document.getElementById("ref" + i).innerHTML;
  76. if (test === ref) {
  77. document.getElementById("result").innerHTML += "<p style=\"background-color: #d6ffd6\">" + i + " passed</p>";
  78. result = result || true;
  79. } else {
  80. document.getElementById("result").innerHTML += "<p style=\"background-color: #ffd6d6\">" + i + " failed</p>";
  81. result = result || false;
  82. }
  83. i += 1;
  84. }
  85. if (parent != window) {
  86. parent.postMessage(JSON.stringify({
  87. desc: document.getElementById("desc").innerHTML,
  88. index: 38,
  89. result: (result ? "passed" : "failed")
  90. }), window.location.href);
  91. }
  92. }
  93. </script>
  94. <script src="../Hyphenopoly_Loader.js"></script>
  95. <style type="text/css">
  96. body {
  97. width:50%;
  98. margin-left:25%;
  99. margin-right:25%;
  100. }
  101. .test {
  102. background-color: #D8E2F9;
  103. hyphens: auto;
  104. }
  105. .ref {
  106. background-color: #FEEFC0;
  107. }
  108. </style>
  109. </head>
  110. <body>
  111. <div id="navigate"><a href="index.html">&Larr;&nbsp;Index</a>&nbsp;|&nbsp;<a href="test37.html">&larr;&nbsp;Prev</a>&nbsp;|&nbsp;<a href="test39.html">Next&nbsp;&rarr;</a></div>
  112. <h1>Test 038</h1>
  113. <p id="desc">Reject only hyphenator-promise if it's pattern can't be loaded.</p>
  114. <div id="result"></div>
  115. <hr>
  116. <h2>en-us</h2>
  117. <p id="test1" lang="en-us" class="test"></p>
  118. <p id="ref1" lang="en-us" class="ref">hy|phen|ation al|go|rithm</p>
  119. <h2>de</h2>
  120. <p id="test2" lang="de" class="test"></p>
  121. <p id="ref2" lang="de" class="ref">Sil|ben|tren|nungs|al|go|rith|mus</p>
  122. <hr>
  123. <div><span class="test">Test</span> <span class="ref">Ref</span></div>
  124. </body>
  125. </html>