configurations.js 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. /* eslint-env node */
  2. /* eslint global-require: 0, func-names: 0, no-shadow: 0 */
  3. "use strict";
  4. const t = require("tap");
  5. t.test("set options: compound", function (t) {
  6. let H9Y = null;
  7. t.beforeEach(function setup(done) {
  8. H9Y = require("../hyphenopoly.module");
  9. done();
  10. });
  11. t.afterEach(function tearDown(done) {
  12. H9Y = null;
  13. delete require.cache[require.resolve("../hyphenopoly.module")];
  14. done();
  15. });
  16. t.test("compound: all", async function (t) {
  17. const hyphenator = await H9Y.config({
  18. "compound": "all",
  19. "hyphen": "•",
  20. "require": ["de"]
  21. });
  22. t.equal(hyphenator("Silbentrennungs-Algorithmus"), "Sil•ben•tren•nungs-\u200BAl•go•rith•mus");
  23. t.end();
  24. });
  25. t.test("compound: auto", async function (t) {
  26. const hyphenator = await H9Y.config({
  27. "compound": "auto",
  28. "hyphen": "•",
  29. "require": ["de"]
  30. });
  31. t.equal(hyphenator("Silbentrennungs-Algorithmus"), "Sil•ben•tren•nungs-Al•go•rith•mus");
  32. t.end();
  33. });
  34. t.test("compound: hyphen", async function (t) {
  35. const hyphenator = await H9Y.config({
  36. "compound": "hyphen",
  37. "hyphen": "•",
  38. "require": ["de"]
  39. });
  40. t.equal(hyphenator("Silbentrennungs-Algorithmus"), "Silbentrennungs-\u200BAlgorithmus");
  41. t.end();
  42. });
  43. t.test("compound: auto, one part too small", async function (t) {
  44. const hyphenator = await H9Y.config({
  45. "compound": "auto",
  46. "hyphen": "•",
  47. "require": ["de"]
  48. });
  49. t.equal(hyphenator("Test-Algorithmus"), "Test-Al•go•rith•mus");
  50. t.end();
  51. });
  52. t.test("compound: all, one part too small", async function (t) {
  53. const hyphenator = await H9Y.config({
  54. "compound": "all",
  55. "hyphen": "•",
  56. "require": ["de"]
  57. });
  58. t.equal(hyphenator("Test-Algorithmus"), "Test-\u200BAl•go•rith•mus");
  59. t.end();
  60. });
  61. t.end();
  62. });
  63. t.test("set options: exceptions", function (t) {
  64. let H9Y = null;
  65. t.beforeEach(function setup(done) {
  66. H9Y = require("../hyphenopoly.module");
  67. done();
  68. });
  69. t.afterEach(function tearDown(done) {
  70. H9Y = null;
  71. delete require.cache[require.resolve("../hyphenopoly.module")];
  72. done();
  73. });
  74. t.test("exceptions: global (only)", async function (t) {
  75. const hyphenator = await H9Y.config({
  76. "exceptions": {"global": "Silben-trennung"},
  77. "hyphen": "•",
  78. "require": ["de"]
  79. });
  80. t.equal(hyphenator("Silbentrennung"), "Silben•trennung");
  81. t.end();
  82. });
  83. t.test("exceptions: global and lang", async function (t) {
  84. const hyphenator = await H9Y.config({
  85. "exceptions": {
  86. "de": "Algo-rithmus",
  87. "global": "Silben-trennung"
  88. },
  89. "hyphen": "•",
  90. "require": ["de"]
  91. });
  92. t.equal(hyphenator("Silbentrennung Algorithmus"), "Silben•trennung Algo•rithmus");
  93. t.end();
  94. });
  95. t.test("exceptions: double entry", async function (t) {
  96. const hyphenator = await H9Y.config({
  97. "exceptions": {"de": "Algo-rithmus, Algo-rithmus"},
  98. "hyphen": "•",
  99. "require": ["de"]
  100. });
  101. t.equal(hyphenator("Algorithmus"), "Algo•rithmus");
  102. t.end();
  103. });
  104. t.end();
  105. });
  106. t.test("set options: hyphen", function (t) {
  107. let H9Y = null;
  108. t.beforeEach(function setup(done) {
  109. H9Y = require("../hyphenopoly.module");
  110. done();
  111. });
  112. t.afterEach(function tearDown(done) {
  113. H9Y = null;
  114. delete require.cache[require.resolve("../hyphenopoly.module")];
  115. done();
  116. });
  117. t.test("hyphen: •", async function (t) {
  118. const hyphenator = await H9Y.config({
  119. "hyphen": "•",
  120. "require": ["de"]
  121. });
  122. t.equal(hyphenator("Silbentrennung"), "Sil•ben•tren•nung");
  123. t.end();
  124. });
  125. t.test("hyphen: |", async function (t) {
  126. const hyphenator = await H9Y.config({
  127. "hyphen": "|",
  128. "require": ["de"]
  129. });
  130. t.equal(hyphenator("Silbentrennung"), "Sil|ben|tren|nung");
  131. t.end();
  132. });
  133. t.end();
  134. });
  135. t.test("set options: left-/rightmin (patterns: 2/2)", function (t) {
  136. let H9Y = null;
  137. t.beforeEach(function setup(done) {
  138. H9Y = require("../hyphenopoly.module");
  139. done();
  140. });
  141. t.afterEach(function tearDown(done) {
  142. H9Y = null;
  143. delete require.cache[require.resolve("../hyphenopoly.module")];
  144. done();
  145. });
  146. t.test("left-/rightmin: 4, 5", async function (t) {
  147. const hyphenator = await H9Y.config({
  148. "hyphen": "•",
  149. "leftmin": 4,
  150. "require": ["de"],
  151. "rightmin": 5
  152. });
  153. t.equal(hyphenator("Silbentrennung"), "Silben•trennung");
  154. t.end();
  155. });
  156. t.end();
  157. });
  158. t.test("set options: left-/rightmin (patterns: 2/3)", function (t) {
  159. let H9Y = null;
  160. t.beforeEach(function setup(done) {
  161. H9Y = require("../hyphenopoly.module");
  162. done();
  163. });
  164. t.afterEach(function tearDown(done) {
  165. H9Y = null;
  166. delete require.cache[require.resolve("../hyphenopoly.module")];
  167. done();
  168. });
  169. t.test("left-/rightmin: 2, 2", async function (t) {
  170. const hyphenator = await H9Y.config({
  171. "hyphen": "•",
  172. "leftmin": 2,
  173. "require": ["pt"],
  174. "rightmin": 2
  175. });
  176. t.equal(hyphenator("relativo"), "re•la•ti•vo");
  177. t.end();
  178. });
  179. t.test("left-/rightmin: def, def", async function (t) {
  180. const hyphenator = await H9Y.config({
  181. "hyphen": "•",
  182. "require": ["pt"]
  183. });
  184. t.equal(hyphenator("relativo"), "re•la•tivo");
  185. t.end();
  186. });
  187. t.end();
  188. });
  189. t.test("set options: minWordLength", function (t) {
  190. let H9Y = null;
  191. t.beforeEach(function setup(done) {
  192. H9Y = require("../hyphenopoly.module");
  193. done();
  194. });
  195. t.afterEach(function tearDown(done) {
  196. H9Y = null;
  197. delete require.cache[require.resolve("../hyphenopoly.module")];
  198. done();
  199. });
  200. t.test("minWordLength: 7", async function (t) {
  201. const hyphenator = await H9Y.config({
  202. "hyphen": "•",
  203. "minWordLength": 7,
  204. "require": ["de"]
  205. });
  206. t.equal(hyphenator("Die Asse essen lieber gesunde Esswaren"), "Die Asse essen lieber ge•sun•de Ess•wa•ren");
  207. t.end();
  208. });
  209. t.end();
  210. });
  211. t.test("set options: mixedCase", function (t) {
  212. let H9Y = null;
  213. t.beforeEach(function setup(done) {
  214. H9Y = require("../hyphenopoly.module");
  215. done();
  216. });
  217. t.afterEach(function tearDown(done) {
  218. H9Y = null;
  219. delete require.cache[require.resolve("../hyphenopoly.module")];
  220. done();
  221. });
  222. t.test("mixedCase: false", async function (t) {
  223. const hyphenator = await H9Y.config({
  224. "hyphen": "•",
  225. "mixedCase": false,
  226. "require": ["de"]
  227. });
  228. t.equal(hyphenator("silbentrennen Silbentrennung camelCase"), "sil•ben•tren•nen Silbentrennung camelCase");
  229. t.end();
  230. });
  231. t.end();
  232. });
  233. t.test("set options: normalize", function (t) {
  234. let H9Y = null;
  235. t.beforeEach(function setup(done) {
  236. H9Y = require("../hyphenopoly.module");
  237. done();
  238. });
  239. t.afterEach(function tearDown(done) {
  240. H9Y = null;
  241. delete require.cache[require.resolve("../hyphenopoly.module")];
  242. done();
  243. });
  244. t.test("normalize: true", async function (t) {
  245. const hyphenator = await H9Y.config({
  246. "hyphen": "•",
  247. "normalize": true,
  248. "require": ["de"]
  249. });
  250. t.equal(hyphenator("Ba\u0308rento\u0308ter"), "Bä•ren•tö•ter");
  251. t.end();
  252. });
  253. t.end();
  254. });
  255. t.test("set options: orphanControl", function (t) {
  256. let H9Y = null;
  257. t.beforeEach(function setup(done) {
  258. H9Y = require("../hyphenopoly.module");
  259. done();
  260. });
  261. t.afterEach(function tearDown(done) {
  262. H9Y = null;
  263. delete require.cache[require.resolve("../hyphenopoly.module")];
  264. done();
  265. });
  266. t.test("orphanControl: 1 (default)", async function (t) {
  267. const hyphenator = await H9Y.config({
  268. "hyphen": "•",
  269. "require": ["de"]
  270. });
  271. t.equal(hyphenator("Die Asse essen lieber gesunde Esswaren"), "Die Asse essen lie•ber ge•sun•de Ess•wa•ren");
  272. t.end();
  273. });
  274. t.test("orphanControl: 2", async function (t) {
  275. const hyphenator = await H9Y.config({
  276. "hyphen": "•",
  277. "orphanControl": 2,
  278. "require": ["de"]
  279. });
  280. t.equal(hyphenator("Die Asse essen lieber gesunde Esswaren"), "Die Asse essen lie•ber ge•sun•de Esswaren");
  281. t.end();
  282. });
  283. t.test("orphanControl: 2, hyphen: |", async function (t) {
  284. const hyphenator = await H9Y.config({
  285. "hyphen": "|",
  286. "orphanControl": 2,
  287. "require": ["de"]
  288. });
  289. t.equal(hyphenator("Die Asse essen lieber gesunde Esswaren"), "Die Asse essen lie|ber ge|sun|de Esswaren");
  290. t.end();
  291. });
  292. t.test("orphanControl: 3", async function (t) {
  293. const hyphenator = await H9Y.config({
  294. "hyphen": "•",
  295. "orphanControl": 3,
  296. "require": ["de"]
  297. });
  298. t.equal(hyphenator("Die Asse essen lieber gesunde Esswaren"), "Die Asse essen lie•ber ge•sun•de\u00A0Esswaren");
  299. t.end();
  300. });
  301. t.end();
  302. });