basic.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /* eslint-env node */
  2. /* eslint global-require: 0, func-names: 0, no-shadow: 0 */
  3. "use strict";
  4. const t = require("tap");
  5. let H9Y = null;
  6. t.beforeEach(function setup(done) {
  7. H9Y = require("../hyphenopoly.module");
  8. done();
  9. });
  10. t.afterEach(function tearDown(done) {
  11. H9Y = null;
  12. delete require.cache[require.resolve("../hyphenopoly.module")];
  13. done();
  14. });
  15. t.test("run config with one language", async function (t) {
  16. const deHyphenator = await H9Y.config({"require": ["de"]});
  17. t.test("return a function", function (t) {
  18. t.equal(typeof deHyphenator, "function", typeof deHyphenator);
  19. t.end();
  20. });
  21. t.test("hyphenate one word", function (t) {
  22. t.equal(deHyphenator("Silbentrennung"), "Sil\u00ADben\u00ADtren\u00ADnung", deHyphenator("Silbentrennung"));
  23. t.end();
  24. });
  25. t.test("hyphenate two words", function (t) {
  26. t.equal(deHyphenator("Silbentrennung Algorithmus"), "Sil\u00ADben\u00ADtren\u00ADnung Al\u00ADgo\u00ADrith\u00ADmus", deHyphenator("Silbentrennung Algorithmus"));
  27. t.end();
  28. });
  29. t.end();
  30. });
  31. t.test("run config with two languages", async function (t) {
  32. const hyphenators = await H9Y.config({"require": ["de", "en-us"]});
  33. t.test("return a Map", function (t) {
  34. t.type(hyphenators, Map);
  35. t.end();
  36. });
  37. t.test("get the hyphenator function promise for a language", function (t) {
  38. const deHyphenator = hyphenators.get("de");
  39. t.type(deHyphenator, Promise);
  40. t.end();
  41. });
  42. t.test("get the hyphenator function for a language", async function (t) {
  43. const deHyphenator = await hyphenators.get("de");
  44. t.type(deHyphenator, Function);
  45. t.end();
  46. });
  47. t.test("hyphenate one word of the first language", async function (t) {
  48. const deHyphenator = await hyphenators.get("de");
  49. t.equal(deHyphenator("Silbentrennung"), "Sil\u00ADben\u00ADtren\u00ADnung", deHyphenator("Silbentrennung"));
  50. t.end();
  51. });
  52. t.test("hyphenate two words of the first language", async function (t) {
  53. const deHyphenator = await hyphenators.get("de");
  54. t.equal(deHyphenator("Silbentrennung Algorithmus"), "Sil\u00ADben\u00ADtren\u00ADnung Al\u00ADgo\u00ADrith\u00ADmus", deHyphenator("Silbentrennung Algorithmus"));
  55. t.end();
  56. });
  57. t.test("hyphenate one word of the second language", async function (t) {
  58. const enHyphenator = await hyphenators.get("en-us");
  59. t.equal(enHyphenator("hyphenation"), "hy\u00ADphen\u00ADation", enHyphenator("hyphenation"));
  60. t.end();
  61. });
  62. t.test("hyphenate two words of the second language", async function (t) {
  63. const deHyphenator = await hyphenators.get("en-us");
  64. t.equal(deHyphenator("hyphenation algorithm"), "hy\u00ADphen\u00ADation al\u00ADgo\u00ADrithm", deHyphenator("hyphenation algorithm"));
  65. t.end();
  66. });
  67. t.end();
  68. });
  69. t.test("run config with two same languages", async function (t) {
  70. const deHyphenator2 = await H9Y.config({"require": ["de", "de"]});
  71. t.test("return a function", function (t) {
  72. t.equal(typeof deHyphenator2, "function", typeof deHyphenator2);
  73. t.end();
  74. });
  75. t.test("hyphenate one word", function (t) {
  76. t.equal(deHyphenator2("Silbentrennung"), "Sil\u00ADben\u00ADtren\u00ADnung", deHyphenator2("Silbentrennung"));
  77. t.end();
  78. });
  79. t.test("hyphenate two words", function (t) {
  80. t.equal(deHyphenator2("Silbentrennung Algorithmus"), "Sil\u00ADben\u00ADtren\u00ADnung Al\u00ADgo\u00ADrith\u00ADmus", deHyphenator2("Silbentrennung Algorithmus"));
  81. t.end();
  82. });
  83. t.end();
  84. });
  85. t.test("execute synchronically with one language", function (t) {
  86. const deHyphenator = H9Y.config({
  87. "require": ["de"],
  88. "sync": true
  89. });
  90. t.test("return a function", function (t) {
  91. t.equal(typeof deHyphenator, "function", typeof deHyphenator);
  92. t.end();
  93. });
  94. t.test("hyphenate one word", function (t) {
  95. t.equal(deHyphenator("Silbentrennung"), "Sil\u00ADben\u00ADtren\u00ADnung", deHyphenator("Silbentrennung"));
  96. t.end();
  97. });
  98. t.test("hyphenate two words", function (t) {
  99. t.equal(deHyphenator("Silbentrennung Algorithmus"), "Sil\u00ADben\u00ADtren\u00ADnung Al\u00ADgo\u00ADrith\u00ADmus", deHyphenator("Silbentrennung Algorithmus"));
  100. t.end();
  101. });
  102. t.end();
  103. });
  104. t.test("execute synchronically with two languages", function (t) {
  105. const hyphenators = H9Y.config({
  106. "require": ["de", "en-us"],
  107. "sync": true
  108. });
  109. t.test("return a Map", function (t) {
  110. t.type(hyphenators, Map);
  111. t.end();
  112. });
  113. t.test("get the hyphenator function for a language", function (t) {
  114. const deHyphenator = hyphenators.get("de");
  115. t.type(deHyphenator, Function);
  116. t.end();
  117. });
  118. t.test("hyphenate one word of the first language", function (t) {
  119. const deHyphenator = hyphenators.get("de");
  120. t.equal(deHyphenator("Silbentrennung"), "Sil\u00ADben\u00ADtren\u00ADnung", deHyphenator("Silbentrennung"));
  121. t.end();
  122. });
  123. t.end();
  124. });