errors.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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("path to maindir not resolvable", async function (t) {
  16. await H9Y.config({
  17. "paths": {
  18. "maindir": "fail/",
  19. "patterndir": "./patterns/"
  20. },
  21. "require": ["de"]
  22. }).catch(
  23. function (e) {
  24. t.equal(e, "fail/hyphenEngine.wasm not found.");
  25. t.end();
  26. }
  27. );
  28. });
  29. t.test("path to patternfile not resolvable", async function (t) {
  30. await H9Y.config({
  31. "paths": {
  32. "maindir": "./",
  33. "patterndir": "./patterns/"
  34. },
  35. "require": ["en"]
  36. }).catch(
  37. function (e) {
  38. t.equal(e, "./patterns/en.hpb not found.");
  39. t.end();
  40. }
  41. );
  42. });
  43. t.test("run config with two languages", async function (t) {
  44. const hyphenators = await H9Y.config({"require": ["de", "en"]});
  45. t.test("get the hyphenator function for a language", async function (t) {
  46. await hyphenators.get("en").catch(
  47. function (e) {
  48. t.equal(e.slice(-27), "/patterns/en.hpb not found.");
  49. }
  50. );
  51. t.end();
  52. });
  53. });
  54. t.test("incomplete setup (forget require)", async function (t) {
  55. const laHyphenator = await H9Y.config({});
  56. t.test("get empty map", function (t) {
  57. t.equal(laHyphenator.size, 0);
  58. t.end();
  59. });
  60. t.end();
  61. });
  62. t.test("make hyphenEngine fail", async function (t) {
  63. const laHyphenator = await H9Y.config({"require": ["la"]});
  64. t.test("hyphenate one word", function (t) {
  65. t.equal(laHyphenator("Helvetii"), "Helvetii");
  66. t.end();
  67. });
  68. t.end();
  69. });
  70. t.test("fail when word is to long", async function (t) {
  71. const nlHyphenator = await H9Y.config({"require": ["nl"]});
  72. t.test("hyphenate one word", function (t) {
  73. t.equal(nlHyphenator("Kindercarnavalsoptochtvoorbereidingswerkzaamhedenplankindercarnavals"), "Kindercarnavalsoptochtvoorbereidingswerkzaamhedenplankindercarnavals");
  74. t.end();
  75. });
  76. t.end();
  77. });