proskomma-core 0.9.7 → 0.9.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (300) hide show
  1. package/.eslintrc.json +79 -0
  2. package/.gitattributes +2 -0
  3. package/babel.config.js +18 -0
  4. package/docs/_config.yml +1 -0
  5. package/docs/index.md +3 -0
  6. package/docs/pk_edit_0_9.odt +0 -0
  7. package/docs/pk_edit_0_9.pdf +0 -0
  8. package/docs/proskomma_101_slideshow.odp +0 -0
  9. package/docs/proskomma_101_slideshow.pdf +0 -0
  10. package/docs/proskomma_edit_html.png +0 -0
  11. package/docs/proskomma_edit_html.svg +451 -0
  12. package/docs/proskomma_edit_reference.png +0 -0
  13. package/docs/proskomma_edit_reference.svg +349 -0
  14. package/docs/repo_logo.png +0 -0
  15. package/esm/package.json +3 -0
  16. package/esm/wrapper.mjs +5 -0
  17. package/index.js +6 -0
  18. package/package.json +19 -17
  19. package/src/graph/index.cjs +201 -0
  20. package/src/graph/lib/do_cv.cjs +249 -0
  21. package/src/graph/lib/dump.cjs +40 -0
  22. package/src/graph/lib/remake_blocks.cjs +57 -0
  23. package/src/graph/lib/sequence_chars.cjs +84 -0
  24. package/src/graph/lib/sort.cjs +39 -0
  25. package/src/graph/lib/tribos.cjs +97 -0
  26. package/src/graph/lib/tribos_expression.cjs +556 -0
  27. package/src/graph/lib/tribos_ohm_UNUSED.cjs +37 -0
  28. package/src/graph/lib/tribos_step.cjs +434 -0
  29. package/src/graph/mutations/add.cjs +91 -0
  30. package/src/graph/mutations/delete.cjs +61 -0
  31. package/src/graph/mutations/index.cjs +54 -0
  32. package/src/graph/mutations/rehash.cjs +17 -0
  33. package/src/graph/mutations/tags.cjs +120 -0
  34. package/src/graph/mutations/update.cjs +210 -0
  35. package/src/graph/mutations/versification.cjs +96 -0
  36. package/src/graph/queries/block.cjs +228 -0
  37. package/src/graph/queries/cIndex.cjs +87 -0
  38. package/src/graph/queries/cell.cjs +42 -0
  39. package/src/graph/queries/cv.cjs +19 -0
  40. package/src/graph/queries/cvBook.cjs +16 -0
  41. package/src/graph/queries/cvChapter.cjs +16 -0
  42. package/src/graph/queries/cvIndex.cjs +47 -0
  43. package/src/graph/queries/cvNavigation.cjs +116 -0
  44. package/src/graph/queries/cvVerseElement.cjs +84 -0
  45. package/src/graph/queries/cvVerses.cjs +14 -0
  46. package/src/graph/queries/doc_set.cjs +220 -0
  47. package/src/graph/queries/document.cjs +555 -0
  48. package/src/graph/queries/idParts.cjs +30 -0
  49. package/src/graph/queries/index.cjs +151 -0
  50. package/src/graph/queries/inputBlockSpec.cjs +17 -0
  51. package/src/graph/queries/inputItemObject.cjs +12 -0
  52. package/src/graph/queries/input_att_spec.cjs +14 -0
  53. package/src/graph/queries/input_key_matches.cjs +11 -0
  54. package/src/graph/queries/input_key_value.cjs +11 -0
  55. package/src/graph/queries/input_key_values.cjs +11 -0
  56. package/src/graph/queries/input_selector_spec.cjs +19 -0
  57. package/src/graph/queries/item.cjs +71 -0
  58. package/src/graph/queries/itemGroup.cjs +75 -0
  59. package/src/graph/queries/key_value.cjs +18 -0
  60. package/src/graph/queries/kv_entry.cjs +21 -0
  61. package/src/graph/queries/kv_sequence.cjs +151 -0
  62. package/src/graph/queries/node.cjs +44 -0
  63. package/src/graph/queries/orig.cjs +11 -0
  64. package/src/graph/queries/regex_index.cjs +18 -0
  65. package/src/graph/queries/row_equals_spec.cjs +11 -0
  66. package/src/graph/queries/row_match_spec.cjs +11 -0
  67. package/src/graph/queries/selector_spec.cjs +29 -0
  68. package/src/graph/queries/sequence.cjs +314 -0
  69. package/src/graph/queries/table_sequence.cjs +192 -0
  70. package/src/graph/queries/tree_sequence.cjs +58 -0
  71. package/src/graph/queries/verseNumber.cjs +44 -0
  72. package/src/graph/queries/verseRange.cjs +11 -0
  73. package/src/graph/queries/versification.cjs +25 -0
  74. package/src/index.cjs +583 -0
  75. package/src/model/doc_set.cjs +389 -0
  76. package/src/model/doc_set_helpers/block.cjs +232 -0
  77. package/src/model/doc_set_helpers/enum.cjs +87 -0
  78. package/src/model/doc_set_helpers/item.cjs +198 -0
  79. package/src/model/doc_set_helpers/rehash.cjs +53 -0
  80. package/src/model/doc_set_helpers/selectors.cjs +58 -0
  81. package/src/model/doc_set_helpers/serialize.cjs +22 -0
  82. package/src/model/doc_set_helpers/unsuccinctify.cjs +288 -0
  83. package/src/model/doc_set_helpers/update.cjs +290 -0
  84. package/src/model/document.cjs +369 -0
  85. package/src/model/document_helpers/blocks.cjs +135 -0
  86. package/src/model/document_helpers/chapter_verse.cjs +291 -0
  87. package/src/model/document_helpers/pre_enums.cjs +67 -0
  88. package/src/model/document_helpers/sequences.cjs +205 -0
  89. package/src/model/document_helpers/serialize_succinct.cjs +55 -0
  90. package/src/model/document_helpers/succinct_filter.cjs +102 -0
  91. package/src/model/versifications/eng_vrs.cjs +455 -0
  92. package/src/model/versifications/index.cjs +38 -0
  93. package/src/model/versifications/lxx_vrs.cjs +950 -0
  94. package/src/model/versifications/org_vrs.cjs +155 -0
  95. package/src/model/versifications/rsc_vrs.cjs +342 -0
  96. package/src/model/versifications/rso_vrs.cjs +541 -0
  97. package/src/model/versifications/vul_vrs.cjs +835 -0
  98. package/src/parser/index.cjs +506 -0
  99. package/src/parser/lexers/index.cjs +11 -0
  100. package/src/parser/lexers/lexingRegexes.cjs +45 -0
  101. package/src/parser/lexers/nodes.cjs +123 -0
  102. package/src/parser/lexers/object_for_fragment.cjs +123 -0
  103. package/src/parser/lexers/tsv.cjs +45 -0
  104. package/src/parser/lexers/usfm.cjs +17 -0
  105. package/src/parser/lexers/usx/index.cjs +7 -0
  106. package/src/parser/lexers/usx/usx_lexer.cjs +321 -0
  107. package/src/parser/lib/tokenize.cjs +37 -0
  108. package/src/parser/model/index.cjs +637 -0
  109. package/src/parser/parser_specs.cjs +781 -0
  110. package/src/pipelines/perf2x/index.cjs +7 -0
  111. package/src/pipelines/perf2x/perf2PkJsonPipeline.json +41 -0
  112. package/src/pipelines/perf2x/perf2usfmPipeline.json +65 -0
  113. package/src/transforms/calculateUsfmChapterPositions.cjs +106 -0
  114. package/src/transforms/index.cjs +9 -0
  115. package/src/transforms/perf2PkJson.cjs +534 -0
  116. package/src/transforms/perf2usfm.cjs +294 -0
  117. package/src/util/byteArray.cjs +251 -0
  118. package/src/util/canons.cjs +117 -0
  119. package/src/util/enums.cjs +41 -0
  120. package/src/util/generateId.cjs +6 -0
  121. package/src/util/graftDefs.cjs +15 -0
  122. package/src/util/index.cjs +29 -0
  123. package/src/util/inspectSuccinct.cjs +59 -0
  124. package/src/util/itemDefs.cjs +33 -0
  125. package/src/util/parserConstantDefs.cjs +30 -0
  126. package/src/util/scopeDefs.cjs +173 -0
  127. package/src/util/scriptlike/blocksSpec.cjs +192 -0
  128. package/src/util/scriptlike/dodson_lexicon.xsl +19 -0
  129. package/src/util/scriptlike/dodson_lexicon_to_entries.cjs +85 -0
  130. package/src/util/scriptlike/open_scriptures_hebrew_lexicon.xsl +28 -0
  131. package/src/util/scriptlike/open_scriptures_hebrew_lexicon_to_entries.cjs +85 -0
  132. package/src/util/succinct.cjs +159 -0
  133. package/src/util/tags.cjs +28 -0
  134. package/src/util/tokenDefs.cjs +27 -0
  135. package/src/util/versification.cjs +364 -0
  136. package/test/code/main/bad.cjs +79 -0
  137. package/test/code/main/basics.cjs +534 -0
  138. package/test/code/main/block.cjs +586 -0
  139. package/test/code/main/block_scope_numbers.cjs +31 -0
  140. package/test/code/main/blocks_with_atts.cjs +150 -0
  141. package/test/code/main/blocks_with_cv.cjs +250 -0
  142. package/test/code/main/break.cjs +73 -0
  143. package/test/code/main/checksum.cjs +36 -0
  144. package/test/code/main/cl_global.cjs +35 -0
  145. package/test/code/main/class_for_fragment.cjs +18 -0
  146. package/test/code/main/clean_usfm.cjs +46 -0
  147. package/test/code/main/cp_vp.cjs +158 -0
  148. package/test/code/main/custom.cjs +124 -0
  149. package/test/code/main/cv.cjs +249 -0
  150. package/test/code/main/cvMatching.cjs +155 -0
  151. package/test/code/main/cv_indexes.cjs +189 -0
  152. package/test/code/main/cv_navigation.cjs +124 -0
  153. package/test/code/main/document.cjs +382 -0
  154. package/test/code/main/empty_blocks.cjs +71 -0
  155. package/test/code/main/entries.cjs +402 -0
  156. package/test/code/main/export_lexing_regexes.cjs +19 -0
  157. package/test/code/main/fig.cjs +67 -0
  158. package/test/code/main/filter.cjs +222 -0
  159. package/test/code/main/glossary.cjs +36 -0
  160. package/test/code/main/graft_headings.cjs +36 -0
  161. package/test/code/main/graft_introduction.cjs +96 -0
  162. package/test/code/main/graft_note.cjs +104 -0
  163. package/test/code/main/graft_rems.cjs +34 -0
  164. package/test/code/main/graft_sidebars.cjs +62 -0
  165. package/test/code/main/graft_title.cjs +36 -0
  166. package/test/code/main/hello.cjs +105 -0
  167. package/test/code/main/import_document.cjs +22 -0
  168. package/test/code/main/import_usfm_int.cjs +48 -0
  169. package/test/code/main/item_groups.cjs +133 -0
  170. package/test/code/main/items_with_cv.cjs +311 -0
  171. package/test/code/main/milestone_attributes.cjs +163 -0
  172. package/test/code/main/mixed_sequence_documents.cjs +137 -0
  173. package/test/code/main/mixed_sequences.cjs +217 -0
  174. package/test/code/main/modify_sequence.cjs +29 -0
  175. package/test/code/main/multiple_chapters.cjs +58 -0
  176. package/test/code/main/multiple_content.cjs +105 -0
  177. package/test/code/main/mutate_add.cjs +180 -0
  178. package/test/code/main/mutate_delete.cjs +236 -0
  179. package/test/code/main/mutate_rehash.cjs +68 -0
  180. package/test/code/main/mutate_tags.cjs +90 -0
  181. package/test/code/main/mutate_update.cjs +538 -0
  182. package/test/code/main/selectors.cjs +289 -0
  183. package/test/code/main/sequence.cjs +361 -0
  184. package/test/code/main/serialize.cjs +104 -0
  185. package/test/code/main/spans.cjs +51 -0
  186. package/test/code/main/split_long_tokens.cjs +30 -0
  187. package/test/code/main/standard_vrs.cjs +76 -0
  188. package/test/code/main/subclass.cjs +25 -0
  189. package/test/code/main/table.cjs +119 -0
  190. package/test/code/main/tags.cjs +248 -0
  191. package/test/code/main/token_alignment.cjs +84 -0
  192. package/test/code/main/trees.cjs +211 -0
  193. package/test/code/main/tribos.cjs +865 -0
  194. package/test/code/main/tsv.cjs +385 -0
  195. package/test/code/main/usx_ref.cjs +65 -0
  196. package/test/code/main/verse_mapping.cjs +252 -0
  197. package/test/code/main/verse_range.cjs +31 -0
  198. package/test/code/main/word_likes.cjs +41 -0
  199. package/test/code/utils/byte_array.cjs +271 -0
  200. package/test/code/utils/canons.cjs +20 -0
  201. package/test/code/utils/generate_id.cjs +17 -0
  202. package/test/code/utils/graft_defs.cjs +16 -0
  203. package/test/code/utils/inspect.cjs +130 -0
  204. package/test/code/utils/items.cjs +56 -0
  205. package/test/code/utils/push_succinct.cjs +69 -0
  206. package/test/code/utils/scope_defs.cjs +79 -0
  207. package/test/code/utils/serialize.cjs +28 -0
  208. package/test/code/utils/splice.cjs +67 -0
  209. package/test/code/utils/tags.cjs +69 -0
  210. package/test/code/utils/versification.cjs +249 -0
  211. package/test/lib/load.js +110 -0
  212. package/test/skipped_code/diff.js +53 -0
  213. package/test/test_data/inputBlockSpec/dodson.json +1654 -0
  214. package/test/test_data/inputBlockSpec/kv.json +326 -0
  215. package/test/test_data/inputBlockSpec/mk1.json +1019 -0
  216. package/test/test_data/inputBlockSpec/table.json +170 -0
  217. package/test/test_data/tree/genealogy.json +55 -0
  218. package/test/test_data/tree/jude.json +15965 -0
  219. package/test/test_data/tsv/en_tn_66-JUD.tsv +75 -0
  220. package/test/test_data/tsv/twl_JUD.tsv +144 -0
  221. package/test/test_data/usfm/1pe_webbe.usfm +13 -0
  222. package/test/test_data/usfm/66-JUD-ust.usfm +1089 -0
  223. package/test/test_data/usfm/78-GALspavbl.usfm +10 -0
  224. package/test/test_data/usfm/add_test.usfm +15 -0
  225. package/test/test_data/usfm/backslash.usfm +4 -0
  226. package/test/test_data/usfm/cl.usfm +14 -0
  227. package/test/test_data/usfm/cp_vp.usfm +8 -0
  228. package/test/test_data/usfm/custom.usfm +13 -0
  229. package/test/test_data/usfm/en_ust_oba.usfm +875 -0
  230. package/test/test_data/usfm/en_ust_psa_1.usfm +20 -0
  231. package/test/test_data/usfm/fig.usfm +3 -0
  232. package/test/test_data/usfm/filter.usfm +7 -0
  233. package/test/test_data/usfm/footnote.usfm +11 -0
  234. package/test/test_data/usfm/frt.usfm +4 -0
  235. package/test/test_data/usfm/headings.usfm +7 -0
  236. package/test/test_data/usfm/hello.usfm +8 -0
  237. package/test/test_data/usfm/int.usfm +7 -0
  238. package/test/test_data/usfm/milestone_attributes.usfm +7 -0
  239. package/test/test_data/usfm/milestone_attributes_default.usfm +7 -0
  240. package/test/test_data/usfm/no_break_space.usfm +4 -0
  241. package/test/test_data/usfm/no_mt.usfm +6 -0
  242. package/test/test_data/usfm/rems.usfm +6 -0
  243. package/test/test_data/usfm/section_intros.usfm +26 -0
  244. package/test/test_data/usfm/sidebars.usfm +25 -0
  245. package/test/test_data/usfm/slash_in_att.usfm +6 -0
  246. package/test/test_data/usfm/soft_line_break.usfm +4 -0
  247. package/test/test_data/usfm/spans.usfm +5 -0
  248. package/test/test_data/usfm/split_long_tokens.usfm +6 -0
  249. package/test/test_data/usfm/table.usfm +18 -0
  250. package/test/test_data/usfm/table_at_end.usfm +11 -0
  251. package/test/test_data/usfm/table_in_intro.usfm +22 -0
  252. package/test/test_data/usfm/table_no_end_cells.usfm +18 -0
  253. package/test/test_data/usfm/tit_kitchen_sink.usfm +73 -0
  254. package/test/test_data/usfm/titus_template.usfm +58 -0
  255. package/test/test_data/usfm/ugnt_3jn.usfm +265 -0
  256. package/test/test_data/usfm/ult_3jn.usfm +335 -0
  257. package/test/test_data/usfm/unknown.usfm +5 -0
  258. package/test/test_data/usfm/ust_psa.usfm +29 -0
  259. package/test/test_data/usfm/ust_psa_verse_ranges.usfm +24 -0
  260. package/test/test_data/usfm/ust_psa_with_ts.usfm +29 -0
  261. package/test/test_data/usfm/verse_breaks_in_blocks.usfm +20 -0
  262. package/test/test_data/usfm/verse_range.usfm +7 -0
  263. package/test/test_data/usfm/web_ecc.usfm +391 -0
  264. package/test/test_data/usfm/web_psa51.usfm +71 -0
  265. package/test/test_data/usfm/whitespace.usfm +12 -0
  266. package/test/test_data/usfm/xref.usfm +11 -0
  267. package/test/test_data/usx/bad_element.usx +2 -0
  268. package/test/test_data/usx/cp_vp.usx +12 -0
  269. package/test/test_data/usx/diff1.usx +59 -0
  270. package/test/test_data/usx/diff2.usx +74 -0
  271. package/test/test_data/usx/douay_rheims_ecc.usx +58 -0
  272. package/test/test_data/usx/douay_rheims_psa.usx +5366 -0
  273. package/test/test_data/usx/douay_rheims_psa_40_60.usx +666 -0
  274. package/test/test_data/usx/douay_rheims_rut.usx +26 -0
  275. package/test/test_data/usx/esg3.usx +47 -0
  276. package/test/test_data/usx/fig.usx +6 -0
  277. package/test/test_data/usx/milestone_attributes.usx +11 -0
  278. package/test/test_data/usx/not_nfc18_glo.usx +9 -0
  279. package/test/test_data/usx/not_nfc18_phm.usx +24 -0
  280. package/test/test_data/usx/opt_break.usx +10 -0
  281. package/test/test_data/usx/sidebars.usx +29 -0
  282. package/test/test_data/usx/table.usx +23 -0
  283. package/test/test_data/usx/web_psa.usx +8489 -0
  284. package/test/test_data/usx/web_psa150.usx +33 -0
  285. package/test/test_data/usx/web_psa_40_60.usx +1079 -0
  286. package/test/test_data/usx/web_rut.usx +95 -0
  287. package/test/test_data/usx/web_rut_1.usx +17 -0
  288. package/test/test_data/utils/douay_rheims.vrs +520 -0
  289. package/test/test_data/utils/douay_rheims_PSA.usx +5366 -0
  290. package/test/test_data/utils/serialize_example.json +91 -0
  291. package/test/test_data/utils/truncated_versification.vrs +29 -0
  292. package/test/test_data/utils/web_rut_items.json +2977 -0
  293. package/test/test_data/utils/webbe.vrs +395 -0
  294. package/test/test_data/utils/webbe_PSA.usx +8489 -0
  295. package/test/test_data/vrs/douay_rheims.vrs +520 -0
  296. package/test/test_data/vrs/truncated_versification.vrs +27 -0
  297. package/test/test_data/vrs/webbe.vrs +397 -0
  298. package/webpack.prod.js +50 -0
  299. package/dist/index.js +0 -8
  300. package/dist/index.js.LICENSE.txt +0 -23
@@ -0,0 +1,104 @@
1
+ const test = require('tape');
2
+ const { Validator } = require('proskomma-json-tools');
3
+
4
+ const { Proskomma, utils } = require('../../../src/index.cjs');
5
+ const { unpackEnum } = utils.succinct;
6
+
7
+ const { pkWithDoc } = require('../../lib/load.js');
8
+
9
+ const testGroup = 'Serialize';
10
+
11
+ const pk = pkWithDoc('../test_data/usx/web_rut.usx', {
12
+ lang: 'fra',
13
+ abbr: 'hello',
14
+ })[0];
15
+
16
+ const pk3 = pkWithDoc('../test_data/usfm/78-GALspavbl.usfm', {
17
+ lang: 'spa',
18
+ abbr: 'vbl',
19
+ })[0];
20
+
21
+ test(
22
+ `Serialize WEB RUT (${testGroup})`,
23
+ async function (t) {
24
+ try {
25
+ t.plan(4);
26
+ const query = '{ docSets { id } }';
27
+ const result = await pk.gqlQuery(query);
28
+ const docSetId = result.data.docSets[0].id;
29
+ const serialized = pk.serializeSuccinct(docSetId);
30
+ t.ok(serialized);
31
+ const validationReport = new Validator().validate('proskomma',
32
+ 'succinct',
33
+ '0.2.0',
34
+ serialized
35
+ );
36
+ t.ok(validationReport.isValid);
37
+ t.equal(validationReport.errors, null);
38
+ const wordLikes = unpackEnum(pk.docSets[docSetId].enums['wordLike']);
39
+ t.ok(wordLikes.includes('Ruth'));
40
+ } catch (err) {
41
+ console.log(err);
42
+ }
43
+ },
44
+ );
45
+
46
+ test(
47
+ `Load WEB RUT (${testGroup})`,
48
+ async function (t) {
49
+ try {
50
+ t.plan(11);
51
+ let query = '{ docSets { id } }';
52
+ let result = await pk.gqlQuery(query);
53
+ const docSetId = result.data.docSets[0].id;
54
+ const serialized = pk.serializeSuccinct(docSetId);
55
+ // console.log(JSON.stringify(serialized, null, 2));
56
+ const pk2 = new (Proskomma);
57
+ pk2.loadSuccinctDocSet(serialized);
58
+ t.equal(pk2.nDocSets(), 1);
59
+ t.equal(pk2.nDocuments(), 1);
60
+ const wordLikes = unpackEnum(pk2.docSets[docSetId].enums['wordLike']);
61
+ t.ok(wordLikes.includes('Ruth'));
62
+ query = '{ docSets { id documents { id } } documents { cv(chapter:"1") { text } cv2: cv(chapter:"1" verses:"1") { text } mainSequence { id blocks { text items { type } } } } }';
63
+ result = await pk2.gqlQuery(query);
64
+ t.equal(result.errors, undefined);
65
+ t.equal(result.data.docSets.length, 1);
66
+ t.equal(result.data.docSets[0].documents.length, 1);
67
+ t.equal(result.data.documents.length, 1);
68
+ t.ok(result.data.documents[0].cv[0].text.startsWith('In the days'));
69
+ t.ok(result.data.documents[0].cv2[0].text.startsWith('In the days'));
70
+ const firstBlock = result.data.documents[0].mainSequence.blocks[0];
71
+ t.ok(firstBlock.text.startsWith('In the days when the judges judged'));
72
+ t.throws(() => pk2.loadSuccinctDocSet(serialized), /already loaded/);
73
+ } catch (err) {
74
+ console.log(err);
75
+ }
76
+ },
77
+ );
78
+
79
+ test(
80
+ `Load Text with Accents (${testGroup})`,
81
+ async function (t) {
82
+ try {
83
+ t.plan(7);
84
+ let query = '{ docSets { id } }';
85
+ let result = await pk3.gqlQuery(query);
86
+ const docSetId = result.data.docSets[0].id;
87
+ const serialized = pk3.serializeSuccinct(docSetId);
88
+ const pk2 = new (Proskomma);
89
+ pk2.loadSuccinctDocSet(serialized);
90
+ t.equal(pk2.nDocSets(), 1);
91
+ t.equal(pk2.nDocuments(), 1);
92
+ const wordLikes = unpackEnum(pk2.docSets[docSetId].enums['wordLike']);
93
+ t.ok(wordLikes.includes('Gálatas'));
94
+ query = '{ documents { header(id:"h") headers {key value} } }';
95
+ result = await pk2.gqlQuery(query);
96
+ t.equal(result.errors, undefined);
97
+ t.equal(result.data.documents.length, 1);
98
+ t.ok(result.data.documents[0].header === 'Gálatas');
99
+ t.ok(result.data.documents[0].headers.filter(h => h.key === 'h')[0].value === 'Gálatas');
100
+ } catch (err) {
101
+ console.log(err);
102
+ }
103
+ },
104
+ );
@@ -0,0 +1,51 @@
1
+ const test = require('tape');
2
+
3
+ const { pkWithDoc } = require('../../lib/load.js');
4
+
5
+ const testGroup = 'Spans';
6
+
7
+ const pk = pkWithDoc('../test_data/usfm/spans.usfm', {
8
+ lang: 'fra',
9
+ abbr: 'hello',
10
+ })[0];
11
+
12
+ test(
13
+ `Spans via Dump (${testGroup})`,
14
+ async function (t) {
15
+ try {
16
+ t.plan(4);
17
+ const query =
18
+ '{ documents { mainSequence { blocks { dump } } } }';
19
+ const result = await pk.gqlQuery(query);
20
+ t.equal(result.errors, undefined);
21
+ const block = result.data.documents[0].mainSequence.blocks[0];
22
+ t.ok(block.dump.includes('+span/nd+|Lord-span/nd-'));
23
+ t.ok(block.dump.includes('+span/it++span/bd+|Joel-span/bd-'));
24
+ t.ok(block.dump.includes('Pethuel-span/it-'));
25
+ } catch (err) {
26
+ console.log(err);
27
+ }
28
+ },
29
+ );
30
+
31
+ test(
32
+ `Spans via items with context (${testGroup})`,
33
+ async function (t) {
34
+ try {
35
+ t.plan(8);
36
+ const query =
37
+ `{ documents { mainSequence { blocks { tokens(includeContext:true) { subType payload position scopes } } } } }`;
38
+ const result = await pk.gqlQuery(query);
39
+ t.equal(result.errors, undefined);
40
+ const joel = result.data.documents[0].mainSequence.blocks[0].tokens.filter(t => t.payload === 'Joel')[0];
41
+ t.ok('position' in joel);
42
+ t.ok('scopes' in joel);
43
+
44
+ for (const scope of ['chapter/1', 'verse/1', 'verses/1', 'span/it', 'span/bd']) {
45
+ t.ok(joel.scopes.includes(scope));
46
+ }
47
+ } catch (err) {
48
+ console.log(err);
49
+ }
50
+ },
51
+ );
@@ -0,0 +1,30 @@
1
+ const test = require('tape');
2
+
3
+ const { pkWithDoc } = require('../../lib/load.js');
4
+
5
+ const testGroup = 'Split Long Tokens';
6
+
7
+ const pk = pkWithDoc('../test_data/usfm/split_long_tokens.usfm', {
8
+ lang: 'fra',
9
+ abbr: 'hello',
10
+ })[0];
11
+
12
+ test(
13
+ `300-Char Word (${testGroup})`,
14
+ async function (t) {
15
+ try {
16
+ t.plan(6);
17
+ const query = `{ documents { mainSequence { blocks { items {type subType payload} } } } }`;
18
+ const result = await pk.gqlQuery(query);
19
+ t.ok('data' in result);
20
+ const words = result.data.documents[0].mainSequence.blocks[0].items.filter(i => i.subType === 'wordLike');
21
+ t.equal(words.length, 4);
22
+ t.equal(words[0].payload.length, 127);
23
+ t.equal(words[1].payload.length, 127);
24
+ t.equal(words[2].payload.length, 46);
25
+ t.equal(words[3].payload.length, 3);
26
+ } catch (err) {
27
+ console.log(err);
28
+ }
29
+ },
30
+ );
@@ -0,0 +1,76 @@
1
+ const test = require('tape');
2
+
3
+ const testGroup = 'Standard VRS';
4
+
5
+ const { Proskomma } = require('../../../src/index.cjs');
6
+
7
+ const pk = new Proskomma();
8
+
9
+ test(
10
+ `versifications (${testGroup})`,
11
+ async function (t) {
12
+ try {
13
+ t.plan(3);
14
+ let query = '{versifications { id } }';
15
+ let result = await pk.gqlQuery(query);
16
+ t.equal(result.errors, undefined);
17
+ const versifications = result.data.versifications;
18
+ t.equal(versifications.length, 6);
19
+ t.equal(versifications.filter(v => v.id === 'eng').length, 1);
20
+ } catch (err) {
21
+ console.log(err);
22
+ }
23
+ },
24
+ );
25
+
26
+ test(
27
+ `raw vrs (${testGroup})`,
28
+ async function (t) {
29
+ try {
30
+ t.plan(3);
31
+ let query = '{versification(id: "eng") { id vrs } }';
32
+ let result = await pk.gqlQuery(query);
33
+ t.equal(result.errors, undefined);
34
+ const versification = result.data.versification;
35
+ t.equal(versification.id, 'eng');
36
+ t.ok(versification.vrs.includes('English'));
37
+ } catch (err) {
38
+ console.log(err);
39
+ }
40
+ },
41
+ );
42
+
43
+ test(
44
+ `cvBooks (${testGroup})`,
45
+ async function (t) {
46
+ try {
47
+ t.plan(2);
48
+ let query = '{versification(id: "eng") { cvBooks { bookCode } } }';
49
+ let result = await pk.gqlQuery(query);
50
+ t.equal(result.errors, undefined);
51
+ const cvBooks = result.data.versification.cvBooks;
52
+ t.equal(cvBooks.filter(b => b.bookCode === 'TIT').length, 1);
53
+ } catch (err) {
54
+ console.log(err);
55
+ }
56
+ },
57
+ );
58
+
59
+ test(
60
+ `cvBook details (${testGroup})`,
61
+ async function (t) {
62
+ try {
63
+ t.plan(5);
64
+ let query = '{versification(id: "eng") { cvBook(bookCode: "TIT") { bookCode chapters { chapter maxVerse } } } }';
65
+ let result = await pk.gqlQuery(query);
66
+ t.equal(result.errors, undefined);
67
+ const cvBook = result.data.versification.cvBook;
68
+ t.equal(cvBook.bookCode, 'TIT');
69
+ t.equal(cvBook.chapters.length, 3);
70
+ t.equal(cvBook.chapters[0].chapter, 1);
71
+ t.equal(cvBook.chapters[0].maxVerse, 16);
72
+ } catch (err) {
73
+ console.log(err);
74
+ }
75
+ },
76
+ );
@@ -0,0 +1,25 @@
1
+ const test = require('tape');
2
+ const { Proskomma } = require('../../../src/index.cjs');
3
+
4
+ const testGroup = 'Subclass test';
5
+
6
+ test(
7
+ `Creating a subclass from lib (${testGroup})`,
8
+ function (t) {
9
+ try {
10
+ t.plan(1);
11
+ t.doesNotThrow(() => {
12
+ class SubClassProskomma extends Proskomma {
13
+ constructor() {
14
+ super();
15
+ this.test = 'test';
16
+ }
17
+ }
18
+ const sbClass = new SubClassProskomma();
19
+ sbClass.test = 'othertest';
20
+ });
21
+ } catch (err) {
22
+ console.log(err);
23
+ }
24
+ },
25
+ );
@@ -0,0 +1,119 @@
1
+ const test = require('tape');
2
+
3
+ const { pkWithDoc } = require('../../lib/load.js');
4
+
5
+ const testGroup = 'Tables';
6
+
7
+ const pk = pkWithDoc('../test_data/usx/table.usx', {
8
+ lang: 'fra',
9
+ abbr: 'hello',
10
+ })[0];
11
+ const pk2 = pkWithDoc('../test_data/usfm/table.usfm', {
12
+ lang: 'fra',
13
+ abbr: 'hello',
14
+ })[0];
15
+ const pk3 = pkWithDoc('../test_data/usfm/table_at_end.usfm', {
16
+ lang: 'fra',
17
+ abbr: 'hello',
18
+ })[0];
19
+ const pk4 = pkWithDoc('../test_data/usfm/table_no_end_cells.usfm', {
20
+ lang: 'fra',
21
+ abbr: 'hello',
22
+ })[0];
23
+
24
+ const pk5 = pkWithDoc('../test_data/usfm/table_in_intro.usfm', {
25
+ lang: 'fra',
26
+ abbr: 'hello',
27
+ })[0];
28
+
29
+ const checkResult = (t, result) => {
30
+ const blocks = result.data.documents[0].mainSequence.blocks;
31
+ t.equal(blocks.length, 6);
32
+ t.equal(blocks[0].bs.payload, 'blockTag/p');
33
+ t.false(blocks[0].scopeLabels.includes('table'));
34
+ t.equal(blocks[1].bs.payload, 'blockTag/tr');
35
+ t.ok(blocks[1].scopeLabels.includes('cell/body/left/2'));
36
+ t.ok(blocks[1].scopeLabels.includes('table'));
37
+ t.ok(blocks[2].scopeLabels.includes('cell/body/left/1'));
38
+ t.ok(blocks[2].scopeLabels.includes('cell/body/right/1'));
39
+ t.equal(blocks[5].bs.payload, 'blockTag/p');
40
+ t.false(blocks[5].scopeLabels.includes('table'));
41
+ };
42
+
43
+ const query = `{ documents { sequences { id nBlocks } mainSequence { blocks { scopeLabels bs { payload } bg { subType payload } text items { type subType payload } } } } }`;
44
+
45
+ test(
46
+ `USX (${testGroup})`,
47
+ async function (t) {
48
+ try {
49
+ t.plan(11);
50
+ const result = await pk.gqlQuery(query);
51
+ t.equal(result.errors, undefined);
52
+ checkResult(t, result);
53
+ } catch (err) {
54
+ console.log(err);
55
+ }
56
+ },
57
+ );
58
+
59
+ test(
60
+ `USFM (${testGroup})`,
61
+ async function (t) {
62
+ try {
63
+ t.plan(11);
64
+ const result = await pk2.gqlQuery(query);
65
+ t.equal(result.errors, undefined);
66
+ checkResult(t, result);
67
+ } catch (err) {
68
+ console.log(err);
69
+ }
70
+ },
71
+ );
72
+
73
+ test(
74
+ `USFM in intro (${testGroup})`,
75
+ async function (t) {
76
+ try {
77
+ t.plan(4);
78
+ const result = await pk5.gqlQuery(query);
79
+ t.equal(result.errors, undefined);
80
+ const mainSequence = result.data.documents[0].mainSequence;
81
+ t.equal(mainSequence.blocks.length, 1);
82
+ const firstMainBlock = mainSequence.blocks[0];
83
+ t.equal(firstMainBlock.text, 'First verse!');
84
+ const introId = firstMainBlock.bg.filter(g => g.subType === 'introduction')[0].payload;
85
+ t.equal(result.data.documents[0].sequences.filter(s => s.id === introId)[0].nBlocks, 6);
86
+ } catch (err) {
87
+ console.log(err);
88
+ }
89
+ },
90
+ );
91
+
92
+ test(
93
+ `USFM no cell end tags (${testGroup})`,
94
+ async function (t) {
95
+ try {
96
+ t.plan(11);
97
+ const result = await pk4.gqlQuery(query);
98
+ t.equal(result.errors, undefined);
99
+ checkResult(t, result);
100
+ } catch (err) {
101
+ console.log(err);
102
+ }
103
+ },
104
+ );
105
+
106
+ test(
107
+ `USFM Table at End of Doc (${testGroup})`,
108
+ async function (t) {
109
+ try {
110
+ t.plan(2);
111
+ const result = await pk3.gqlQuery(query);
112
+ t.equal(result.errors, undefined);
113
+ const lastBlockItems = result.data.documents[0].mainSequence.blocks[2].items;
114
+ t.equal(lastBlockItems.filter(i => i.subType === 'end' && i.payload === 'table').length, 1);
115
+ } catch (err) {
116
+ console.log(err);
117
+ }
118
+ },
119
+ );
@@ -0,0 +1,248 @@
1
+ const test = require('tape');
2
+ const { utils } = require('../../../src/index.cjs');
3
+ const { validateTags } = utils.tags;
4
+ const { pkWithDoc } = require('../../lib/load.js');
5
+
6
+ const pk = pkWithDoc('../test_data/usx/web_rut.usx', {
7
+ lang: 'eng',
8
+ abbr: 'web',
9
+ }, {}, {}, [], ['frob', 'frob2'])[0];
10
+ pk.docSetList()[0].tags.add('foo');
11
+ pk.docSetList()[0].tags.add('foo2');
12
+ const document = Object.values(pk.documents)[0];
13
+ document.sequences[document.mainId].tags.add('banana');
14
+ document.sequences[document.mainId].tags.add('split');
15
+
16
+ const testGroup = 'Graph Tags';
17
+
18
+ test(
19
+ `DocSet accessors (${testGroup})`,
20
+ async function (t) {
21
+ try {
22
+ t.plan(5);
23
+ const query = '{ docSets { tags hasFoo: hasTag(tagName:"foo") hasBaa: hasTag(tagName:"baa")} }';
24
+ const result = await pk.gqlQuery(query);
25
+ t.equal(result.errors, undefined);
26
+ const docSet = result.data.docSets[0];
27
+ t.equal(docSet.tags.length, 2);
28
+ t.ok(docSet.tags.includes('foo'));
29
+ t.ok(docSet.hasFoo);
30
+ t.false(docSet.hasBaa);
31
+ } catch (err) {
32
+ console.log(err);
33
+ }
34
+ },
35
+ );
36
+
37
+ test(
38
+ `DocSet selectors (${testGroup})`,
39
+ async function (t) {
40
+ try {
41
+ t.plan(8);
42
+ let query = '{ docSets(withTags:"foo" withoutTags:"oof") { id } }';
43
+ let result = await pk.gqlQuery(query);
44
+ t.equal(result.errors, undefined);
45
+ t.equal(result.data.docSets.length, 1);
46
+ query = '{ docSets(withTags:["foo" "foo2"]) { id } }';
47
+ result = await pk.gqlQuery(query);
48
+ t.equal(result.errors, undefined);
49
+ t.equal(result.data.docSets.length, 1);
50
+ query = '{ docSets(withTags:["foo" "oof"]) { id } }';
51
+ result = await pk.gqlQuery(query);
52
+ t.equal(result.errors, undefined);
53
+ t.equal(result.data.docSets.length, 0);
54
+ query = '{ docSets(withoutTags:["foo" "oof"]) { id } }';
55
+ result = await pk.gqlQuery(query);
56
+ t.equal(result.errors, undefined);
57
+ t.equal(result.data.docSets.length, 0);
58
+ } catch (err) {
59
+ console.log(err);
60
+ }
61
+ },
62
+ );
63
+
64
+ test(
65
+ `Document accessors (${testGroup})`,
66
+ async function (t) {
67
+ try {
68
+ t.plan(5);
69
+ const query = '{ docSets { documents { tags hasFrob: hasTag(tagName:"frob") hasBrof: hasTag(tagName:"brof")} } }';
70
+ const result = await pk.gqlQuery(query);
71
+ t.equal(result.errors, undefined);
72
+ const document = result.data.docSets[0].documents[0];
73
+ t.equal(document.tags.length, 2);
74
+ t.ok(document.tags.includes('frob'));
75
+ t.ok(document.hasFrob);
76
+ t.false(document.hasBrof);
77
+ } catch (err) {
78
+ console.log(err);
79
+ }
80
+ },
81
+ );
82
+
83
+ test(
84
+ `Root-level Document selectors (${testGroup})`,
85
+ async function (t) {
86
+ try {
87
+ t.plan(8);
88
+ let query = '{ documents(withTags:"frob" withoutTags:"brof") { id } }';
89
+ let result = await pk.gqlQuery(query);
90
+ t.equal(result.errors, undefined);
91
+ t.equal(result.data.documents.length, 1);
92
+ query = '{ documents(withTags:["frob" "frob2"]) { id } }';
93
+ result = await pk.gqlQuery(query);
94
+ t.equal(result.errors, undefined);
95
+ t.equal(result.data.documents.length, 1);
96
+ query = '{ documents(withTags:["frob" "brof"]) { id } }';
97
+ result = await pk.gqlQuery(query);
98
+ t.equal(result.errors, undefined);
99
+ t.equal(result.data.documents.length, 0);
100
+ query = '{ documents(withoutTags:["frob" "brof"]) { id } }';
101
+ result = await pk.gqlQuery(query);
102
+ t.equal(result.errors, undefined);
103
+ t.equal(result.data.documents.length, 0);
104
+ } catch (err) {
105
+ console.log(err);
106
+ }
107
+ },
108
+ );
109
+
110
+ test(
111
+ `Document in docSet selectors (${testGroup})`,
112
+ async function (t) {
113
+ try {
114
+ t.plan(8);
115
+ let query = '{ docSet(id:"eng_web") { documents(withTags:"frob" withoutTags:"brof") { id } } }';
116
+ let result = await pk.gqlQuery(query);
117
+ t.equal(result.errors, undefined);
118
+ t.equal(result.data.docSet.documents.length, 1);
119
+ query = '{ docSet(id:"eng_web") { documents(withTags:["frob" "frob2"]) { id } } }';
120
+ result = await pk.gqlQuery(query);
121
+ t.equal(result.errors, undefined);
122
+ t.equal(result.data.docSet.documents.length, 1);
123
+ query = '{ docSet(id:"eng_web") { documents(withTags:["frob" "brof"]) { id } } }';
124
+ result = await pk.gqlQuery(query);
125
+ t.equal(result.errors, undefined);
126
+ t.equal(result.data.docSet.documents.length, 0);
127
+ query = '{ docSet(id:"eng_web") { documents(withoutTags:["frob" "brof"]) { id } } }';
128
+ result = await pk.gqlQuery(query);
129
+ t.equal(result.errors, undefined);
130
+ t.equal(result.data.docSet.documents.length, 0);
131
+ } catch (err) {
132
+ console.log(err);
133
+ }
134
+ },
135
+ );
136
+
137
+ test(
138
+ `Sequence accessors (${testGroup})`,
139
+ async function (t) {
140
+ try {
141
+ t.plan(5);
142
+ const query = '{ docSets { documents { mainSequence { tags hasBanana: hasTag(tagName:"banana") hasApple: hasTag(tagName:"apple") } } } }';
143
+ const result = await pk.gqlQuery(query);
144
+ t.equal(result.errors, undefined);
145
+ const sequence = result.data.docSets[0].documents[0].mainSequence;
146
+ t.equal(sequence.tags.length, 2);
147
+ t.ok(sequence.tags.includes('banana'));
148
+ t.ok(sequence.hasBanana);
149
+ t.false(sequence.hasApple);
150
+ } catch (err) {
151
+ console.log(err);
152
+ }
153
+ },
154
+ );
155
+
156
+ test(
157
+ `Sequence selectors (${testGroup})`,
158
+ async function (t) {
159
+ try {
160
+ t.plan(8);
161
+ let query = '{ documents { sequences(withTags:"banana" withoutTags:"melba") { id } } } ';
162
+ let result = await pk.gqlQuery(query);
163
+ t.equal(result.errors, undefined);
164
+ t.equal(result.data.documents[0].sequences.length, 1);
165
+ query = '{ documents { sequences(withTags: ["banana" "split"]) { id } } }';
166
+ result = await pk.gqlQuery(query);
167
+ t.equal(result.errors, undefined);
168
+ t.equal(result.data.documents[0].sequences.length, 1);
169
+ query = '{ documents { sequences(withTags: ["banana" "melba"]) { id } } }';
170
+ result = await pk.gqlQuery(query);
171
+ t.equal(result.errors, undefined);
172
+ t.equal(result.data.documents[0].sequences.length, 0);
173
+ query = '{ documents { sequences(withTags:"banana" withoutTags: ["peach" "split"]) { id } } }';
174
+ result = await pk.gqlQuery(query);
175
+ t.equal(result.errors, undefined);
176
+ t.equal(result.data.documents[0].sequences.length, 0);
177
+ } catch (err) {
178
+ console.log(err);
179
+ }
180
+ },
181
+ );
182
+
183
+ test(
184
+ `Throw on bad tag format (${testGroup})`,
185
+ // Destructive!
186
+ function (t) {
187
+ try {
188
+ t.plan(2);
189
+ const importFn = () =>
190
+ pkWithDoc('../test_data/usx/web_rut.usx', {
191
+ lang: 'eng',
192
+ abbr: 'ust',
193
+ }, {}, {}, [], ['FROB']);
194
+ t.throws(importFn, /Tag 'FROB' is not valid/);
195
+ const addTagFn = () => {
196
+ pk.docSetList()[0].tags.add('FROB');
197
+ validateTags(pk.docSetList()[0].tags);
198
+ };
199
+ t.throws(addTagFn, /Tag 'FROB' is not valid/);
200
+ } catch (err) {
201
+ console.log(err);
202
+ }
203
+ },
204
+ );
205
+
206
+ test(
207
+ `Support colon tag format (${testGroup})`,
208
+ // Destructive!
209
+ function (t) {
210
+ try {
211
+ t.plan(2);
212
+ const importFn = () =>
213
+ pkWithDoc('../test_data/usx/web_rut.usx', {
214
+ lang: 'eng',
215
+ abbr: 'ust',
216
+ }, {}, {}, [], ['FROB']);
217
+ t.throws(importFn, /Tag 'FROB' is not valid/);
218
+ const addTagFn = () => {
219
+ pk.docSetList()[0].tags.delete('FROB');
220
+ pk.docSetList()[0].tags.add('frob:Fooie!! §');
221
+ validateTags(pk.docSetList()[0].tags);
222
+ };
223
+ t.doesNotThrow(addTagFn);
224
+ } catch (err) {
225
+ console.log(err);
226
+ }
227
+ },
228
+ );
229
+
230
+ test(
231
+ `tagsKv on docSet (${testGroup})`,
232
+ // Relies on destructive tests above
233
+ function (t) {
234
+ try {
235
+ t.plan(5);
236
+ pk.docSetList()[0].tags.add('baa');
237
+ const result = pk.gqlQuerySync('{ docSets { tagsKv { key value } } }');
238
+ t.equal(result.errors, undefined);
239
+ const tagsKv = result.data.docSets[0].tagsKv;
240
+ t.equal(tagsKv.filter(kv => kv.key === 'baa').length, 1);
241
+ t.equal(tagsKv.filter(kv => kv.key === 'frob').length, 1);
242
+ t.equal(tagsKv.filter(kv => kv.key === 'baa')[0].value, '');
243
+ t.ok(tagsKv.filter(kv => kv.key === 'frob')[0].value.startsWith('Fooie'));
244
+ } catch (err) {
245
+ console.log(err);
246
+ }
247
+ },
248
+ );