proskomma-core 0.9.12 → 0.9.13

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 (167) hide show
  1. package/esm/wrapper.mjs +1 -1
  2. package/{index.js → index.cjs} +1 -1
  3. package/package.json +2 -2
  4. package/babel.config.js +0 -18
  5. package/test/code/main/bad.cjs +0 -79
  6. package/test/code/main/basics.cjs +0 -534
  7. package/test/code/main/block.cjs +0 -586
  8. package/test/code/main/block_scope_numbers.cjs +0 -31
  9. package/test/code/main/blocks_with_atts.cjs +0 -150
  10. package/test/code/main/blocks_with_cv.cjs +0 -250
  11. package/test/code/main/break.cjs +0 -73
  12. package/test/code/main/checksum.cjs +0 -36
  13. package/test/code/main/cl_global.cjs +0 -35
  14. package/test/code/main/class_for_fragment.cjs +0 -18
  15. package/test/code/main/clean_usfm.cjs +0 -46
  16. package/test/code/main/cp_vp.cjs +0 -158
  17. package/test/code/main/custom.cjs +0 -124
  18. package/test/code/main/cv.cjs +0 -249
  19. package/test/code/main/cvMatching.cjs +0 -155
  20. package/test/code/main/cv_indexes.cjs +0 -189
  21. package/test/code/main/cv_navigation.cjs +0 -124
  22. package/test/code/main/document.cjs +0 -382
  23. package/test/code/main/empty_blocks.cjs +0 -71
  24. package/test/code/main/entries.cjs +0 -402
  25. package/test/code/main/export_lexing_regexes.cjs +0 -19
  26. package/test/code/main/fig.cjs +0 -67
  27. package/test/code/main/filter.cjs +0 -222
  28. package/test/code/main/glossary.cjs +0 -36
  29. package/test/code/main/graft_headings.cjs +0 -36
  30. package/test/code/main/graft_introduction.cjs +0 -96
  31. package/test/code/main/graft_note.cjs +0 -104
  32. package/test/code/main/graft_rems.cjs +0 -34
  33. package/test/code/main/graft_sidebars.cjs +0 -62
  34. package/test/code/main/graft_title.cjs +0 -36
  35. package/test/code/main/hello.cjs +0 -105
  36. package/test/code/main/import_document.cjs +0 -22
  37. package/test/code/main/import_usfm_int.cjs +0 -48
  38. package/test/code/main/item_groups.cjs +0 -133
  39. package/test/code/main/items_with_cv.cjs +0 -311
  40. package/test/code/main/milestone_attributes.cjs +0 -163
  41. package/test/code/main/mixed_sequence_documents.cjs +0 -137
  42. package/test/code/main/mixed_sequences.cjs +0 -217
  43. package/test/code/main/modify_sequence.cjs +0 -29
  44. package/test/code/main/multiple_chapters.cjs +0 -58
  45. package/test/code/main/multiple_content.cjs +0 -105
  46. package/test/code/main/mutate_add.cjs +0 -180
  47. package/test/code/main/mutate_delete.cjs +0 -236
  48. package/test/code/main/mutate_rehash.cjs +0 -68
  49. package/test/code/main/mutate_tags.cjs +0 -90
  50. package/test/code/main/mutate_update.cjs +0 -538
  51. package/test/code/main/selectors.cjs +0 -289
  52. package/test/code/main/sequence.cjs +0 -361
  53. package/test/code/main/serialize.cjs +0 -104
  54. package/test/code/main/spans.cjs +0 -51
  55. package/test/code/main/split_long_tokens.cjs +0 -30
  56. package/test/code/main/standard_vrs.cjs +0 -76
  57. package/test/code/main/subclass.cjs +0 -25
  58. package/test/code/main/table.cjs +0 -119
  59. package/test/code/main/tags.cjs +0 -248
  60. package/test/code/main/token_alignment.cjs +0 -84
  61. package/test/code/main/trees.cjs +0 -211
  62. package/test/code/main/tribos.cjs +0 -865
  63. package/test/code/main/tsv.cjs +0 -385
  64. package/test/code/main/usx_ref.cjs +0 -65
  65. package/test/code/main/verse_mapping.cjs +0 -252
  66. package/test/code/main/verse_range.cjs +0 -31
  67. package/test/code/main/word_likes.cjs +0 -41
  68. package/test/code/utils/byte_array.cjs +0 -271
  69. package/test/code/utils/canons.cjs +0 -20
  70. package/test/code/utils/generate_id.cjs +0 -17
  71. package/test/code/utils/graft_defs.cjs +0 -16
  72. package/test/code/utils/inspect.cjs +0 -130
  73. package/test/code/utils/items.cjs +0 -56
  74. package/test/code/utils/push_succinct.cjs +0 -69
  75. package/test/code/utils/scope_defs.cjs +0 -79
  76. package/test/code/utils/serialize.cjs +0 -28
  77. package/test/code/utils/splice.cjs +0 -67
  78. package/test/code/utils/tags.cjs +0 -69
  79. package/test/code/utils/versification.cjs +0 -249
  80. package/test/lib/load.js +0 -110
  81. package/test/skipped_code/diff.js +0 -53
  82. package/test/test_data/inputBlockSpec/dodson.json +0 -1654
  83. package/test/test_data/inputBlockSpec/kv.json +0 -326
  84. package/test/test_data/inputBlockSpec/mk1.json +0 -1019
  85. package/test/test_data/inputBlockSpec/table.json +0 -170
  86. package/test/test_data/tree/genealogy.json +0 -55
  87. package/test/test_data/tree/jude.json +0 -15965
  88. package/test/test_data/tsv/en_tn_66-JUD.tsv +0 -75
  89. package/test/test_data/tsv/twl_JUD.tsv +0 -144
  90. package/test/test_data/usfm/1pe_webbe.usfm +0 -13
  91. package/test/test_data/usfm/66-JUD-ust.usfm +0 -1089
  92. package/test/test_data/usfm/78-GALspavbl.usfm +0 -10
  93. package/test/test_data/usfm/add_test.usfm +0 -15
  94. package/test/test_data/usfm/backslash.usfm +0 -4
  95. package/test/test_data/usfm/cl.usfm +0 -14
  96. package/test/test_data/usfm/cp_vp.usfm +0 -8
  97. package/test/test_data/usfm/custom.usfm +0 -13
  98. package/test/test_data/usfm/en_ust_oba.usfm +0 -875
  99. package/test/test_data/usfm/en_ust_psa_1.usfm +0 -20
  100. package/test/test_data/usfm/fig.usfm +0 -3
  101. package/test/test_data/usfm/filter.usfm +0 -7
  102. package/test/test_data/usfm/footnote.usfm +0 -11
  103. package/test/test_data/usfm/frt.usfm +0 -4
  104. package/test/test_data/usfm/headings.usfm +0 -7
  105. package/test/test_data/usfm/hello.usfm +0 -8
  106. package/test/test_data/usfm/int.usfm +0 -7
  107. package/test/test_data/usfm/milestone_attributes.usfm +0 -7
  108. package/test/test_data/usfm/milestone_attributes_default.usfm +0 -7
  109. package/test/test_data/usfm/no_break_space.usfm +0 -4
  110. package/test/test_data/usfm/no_mt.usfm +0 -6
  111. package/test/test_data/usfm/rems.usfm +0 -6
  112. package/test/test_data/usfm/section_intros.usfm +0 -26
  113. package/test/test_data/usfm/sidebars.usfm +0 -25
  114. package/test/test_data/usfm/slash_in_att.usfm +0 -6
  115. package/test/test_data/usfm/soft_line_break.usfm +0 -4
  116. package/test/test_data/usfm/spans.usfm +0 -5
  117. package/test/test_data/usfm/split_long_tokens.usfm +0 -6
  118. package/test/test_data/usfm/table.usfm +0 -18
  119. package/test/test_data/usfm/table_at_end.usfm +0 -11
  120. package/test/test_data/usfm/table_in_intro.usfm +0 -22
  121. package/test/test_data/usfm/table_no_end_cells.usfm +0 -18
  122. package/test/test_data/usfm/tit_kitchen_sink.usfm +0 -73
  123. package/test/test_data/usfm/titus_template.usfm +0 -58
  124. package/test/test_data/usfm/ugnt_3jn.usfm +0 -265
  125. package/test/test_data/usfm/ult_3jn.usfm +0 -335
  126. package/test/test_data/usfm/unknown.usfm +0 -5
  127. package/test/test_data/usfm/ust_psa.usfm +0 -29
  128. package/test/test_data/usfm/ust_psa_verse_ranges.usfm +0 -24
  129. package/test/test_data/usfm/ust_psa_with_ts.usfm +0 -29
  130. package/test/test_data/usfm/verse_breaks_in_blocks.usfm +0 -20
  131. package/test/test_data/usfm/verse_range.usfm +0 -7
  132. package/test/test_data/usfm/web_ecc.usfm +0 -391
  133. package/test/test_data/usfm/web_psa51.usfm +0 -71
  134. package/test/test_data/usfm/whitespace.usfm +0 -12
  135. package/test/test_data/usfm/xref.usfm +0 -11
  136. package/test/test_data/usx/bad_element.usx +0 -2
  137. package/test/test_data/usx/cp_vp.usx +0 -12
  138. package/test/test_data/usx/diff1.usx +0 -59
  139. package/test/test_data/usx/diff2.usx +0 -74
  140. package/test/test_data/usx/douay_rheims_ecc.usx +0 -58
  141. package/test/test_data/usx/douay_rheims_psa.usx +0 -5366
  142. package/test/test_data/usx/douay_rheims_psa_40_60.usx +0 -666
  143. package/test/test_data/usx/douay_rheims_rut.usx +0 -26
  144. package/test/test_data/usx/esg3.usx +0 -47
  145. package/test/test_data/usx/fig.usx +0 -6
  146. package/test/test_data/usx/milestone_attributes.usx +0 -11
  147. package/test/test_data/usx/not_nfc18_glo.usx +0 -9
  148. package/test/test_data/usx/not_nfc18_phm.usx +0 -24
  149. package/test/test_data/usx/opt_break.usx +0 -10
  150. package/test/test_data/usx/sidebars.usx +0 -29
  151. package/test/test_data/usx/table.usx +0 -23
  152. package/test/test_data/usx/web_psa.usx +0 -8489
  153. package/test/test_data/usx/web_psa150.usx +0 -33
  154. package/test/test_data/usx/web_psa_40_60.usx +0 -1079
  155. package/test/test_data/usx/web_rut.usx +0 -95
  156. package/test/test_data/usx/web_rut_1.usx +0 -17
  157. package/test/test_data/utils/douay_rheims.vrs +0 -520
  158. package/test/test_data/utils/douay_rheims_PSA.usx +0 -5366
  159. package/test/test_data/utils/serialize_example.json +0 -91
  160. package/test/test_data/utils/truncated_versification.vrs +0 -29
  161. package/test/test_data/utils/web_rut_items.json +0 -2977
  162. package/test/test_data/utils/webbe.vrs +0 -395
  163. package/test/test_data/utils/webbe_PSA.usx +0 -8489
  164. package/test/test_data/vrs/douay_rheims.vrs +0 -520
  165. package/test/test_data/vrs/truncated_versification.vrs +0 -27
  166. package/test/test_data/vrs/webbe.vrs +0 -397
  167. package/webpack.prod.js +0 -50
@@ -1,249 +0,0 @@
1
- const path = require('path');
2
- const test = require('tape');
3
- const fse = require('fs-extra');
4
- const deepEqual = require('deep-equal');
5
-
6
- const { utils } = require('../../../src/index.cjs');
7
- const {
8
- vrs2json,
9
- reverseVersification,
10
- preSuccinctVerseMapping,
11
- succinctifyVerseMappings,
12
- unsuccinctifyVerseMapping,
13
- bookCodeIndex,
14
- mapVerse,
15
- } = utils.versification;
16
-
17
- const testGroup = 'Versification';
18
-
19
- test(
20
- `vrs2json (${testGroup})`,
21
- function (t) {
22
- try {
23
- t.plan(1);
24
- const vrsString = fse.readFileSync(path.resolve(__dirname, '../../test_data/utils/truncated_versification.vrs')).toString();
25
- const vrsJson = vrs2json(vrsString);
26
- // console.log(JSON.stringify(vrsJson));
27
- t.ok(Object.keys(vrsJson.mappedVerses).length > 0);
28
- } catch (err) {
29
- console.log(err);
30
- }
31
- },
32
- );
33
-
34
- test(
35
- `reverseVersification (${testGroup})`,
36
- function (t) {
37
- try {
38
- const vrsString = fse.readFileSync(path.resolve(__dirname, '../../test_data/utils/truncated_versification.vrs')).toString();
39
- const vrsJson = vrs2json(vrsString);
40
- const vrsJsonLength = Object.keys(vrsJson.mappedVerses).length;
41
- t.plan(vrsJsonLength);
42
- // console.log(JSON.stringify(vrsJson, null, 2));
43
- const reversed = reverseVersification(vrsJson);
44
-
45
- // console.log(JSON.stringify(reversed, null, 2));
46
- for (const [key, value] of (Object.entries(vrsJson.mappedVerses))) {
47
- t.ok(value[0] in reversed.reverseMappedVerses);
48
- }
49
- } catch (err) {
50
- console.log(err);
51
- }
52
- },
53
- );
54
-
55
- test(
56
- `preSuccinctVerseMapping (${testGroup})`,
57
- function (t) {
58
- try {
59
- t.plan(18);
60
- const vrsString = fse.readFileSync(path.resolve(__dirname, '../../test_data/utils/truncated_versification.vrs')).toString();
61
- const vrsJson = vrs2json(vrsString);
62
- const preSuccinct = preSuccinctVerseMapping(vrsJson.mappedVerses);
63
- let preSuccinctBooks = ['GEN', 'LEV', 'PSA', 'ACT', 'S3Y'];
64
- t.equal(Object.keys(preSuccinct).length, preSuccinctBooks.length);
65
-
66
- for (const book of preSuccinctBooks) {
67
- t.ok(book in preSuccinct);
68
- }
69
- t.ok('31' in preSuccinct['GEN']);
70
- t.ok('32' in preSuccinct['GEN']);
71
- t.ok(preSuccinct['S3Y']['1'][0][2][0].includes('DAG'));
72
- const reversed = reverseVersification(vrsJson);
73
- const preSuccinctReversed = preSuccinctVerseMapping(reversed.reverseMappedVerses);
74
- preSuccinctBooks = ['GEN', 'LEV', 'PSA', 'ACT', 'DAG'];
75
- t.equal(Object.keys(preSuccinctReversed).length, preSuccinctBooks.length);
76
-
77
- for (const book of preSuccinctBooks) {
78
- t.ok(book in preSuccinctReversed);
79
- }
80
- t.ok('5' in preSuccinctReversed['LEV']);
81
- t.ok('6' in preSuccinctReversed['LEV']);
82
- t.ok(preSuccinctReversed['DAG']['3'][0][2][0].includes('S3Y'));
83
- // console.log(JSON.stringify(preSuccinctReversed, null, 2));
84
- } catch (err) {
85
- console.log(err);
86
- }
87
- },
88
- );
89
-
90
- test(
91
- `succinctifyVerseMappings (${testGroup})`,
92
- function (t) {
93
- try {
94
- t.plan(16);
95
- const vrsString = fse.readFileSync(path.resolve(__dirname, '../../test_data/utils/truncated_versification.vrs')).toString();
96
- const vrsJson = vrs2json(vrsString);
97
- const succinct = succinctifyVerseMappings(vrsJson.mappedVerses);
98
- let succinctBooks = ['GEN', 'LEV', 'PSA', 'ACT', 'S3Y'];
99
- t.equal(Object.keys(succinct).length, succinctBooks.length);
100
-
101
- for (const book of succinctBooks) {
102
- t.ok(book in succinct);
103
- }
104
- t.ok('31' in succinct['GEN']);
105
- t.ok('32' in succinct['GEN']);
106
- const succinctReversed = succinctifyVerseMappings(reverseVersification(vrsJson).reverseMappedVerses);
107
- succinctBooks = ['GEN', 'LEV', 'PSA', 'ACT', 'DAG'];
108
- t.equal(Object.keys(succinctReversed).length, succinctBooks.length);
109
-
110
- for (const book of succinctBooks) {
111
- t.ok(book in succinctReversed);
112
- }
113
- t.ok('5' in succinctReversed['LEV']);
114
- t.ok('6' in succinctReversed['LEV']);
115
- // console.log(JSON.stringify(succinct, null, 2));
116
- } catch (err) {
117
- console.log(err);
118
- }
119
- },
120
- );
121
-
122
- test(
123
- `unsuccinctify forward (${testGroup})`,
124
- function (t) {
125
- try {
126
- t.plan(15);
127
- const vrsString = fse.readFileSync(path.resolve(__dirname, '../../test_data/utils/truncated_versification.vrs')).toString();
128
- const vrsJson = vrs2json(vrsString);
129
- const svm = succinctifyVerseMappings(vrsJson.mappedVerses);
130
- const unsuccinctS3Y = unsuccinctifyVerseMapping(svm['S3Y']['1'], 'S3Y', bookCodeIndex());
131
- t.equal(unsuccinctS3Y[0].fromVerseStart, 1);
132
- t.equal(unsuccinctS3Y[0].fromVerseEnd, 29);
133
- t.equal(unsuccinctS3Y[0].bookCode, 'DAG');
134
- t.equal(unsuccinctS3Y[0].mapping[0].ch, 3);
135
- t.equal(unsuccinctS3Y[0].mapping[0].verseStart, 24);
136
- const unsuccinctACT = unsuccinctifyVerseMapping(svm['ACT']['19'], 'ACT', bookCodeIndex());
137
- // console.log(JSON.stringify(unsuccinctACT, null, 2));
138
- t.equal(unsuccinctACT[0].fromVerseStart, 40);
139
- t.equal(unsuccinctACT[0].fromVerseEnd, 40);
140
- t.equal(unsuccinctACT[0].bookCode, 'ACT');
141
- t.equal(unsuccinctACT[0].mapping[0].ch, 19);
142
- t.equal(unsuccinctACT[0].mapping[0].verseStart, 40);
143
- t.equal(unsuccinctACT[1].fromVerseStart, 41);
144
- t.equal(unsuccinctACT[1].fromVerseEnd, 41);
145
- t.equal(unsuccinctACT[1].bookCode, 'ACT');
146
- t.equal(unsuccinctACT[1].mapping[0].ch, 19);
147
- t.equal(unsuccinctACT[1].mapping[0].verseStart, 40);
148
- } catch (err) {
149
- console.log(err);
150
- }
151
- },
152
- );
153
-
154
- test(
155
- `unsuccinctify reverse (${testGroup})`,
156
- function (t) {
157
- try {
158
- t.plan(12);
159
- const vrsString = fse.readFileSync(path.resolve(__dirname, '../../test_data/utils/truncated_versification.vrs')).toString();
160
- const vrsJson = vrs2json(vrsString);
161
- const reversedJson = reverseVersification(vrsJson);
162
- const svm = succinctifyVerseMappings(reversedJson.reverseMappedVerses);
163
- const unsuccinctDAG = unsuccinctifyVerseMapping(svm['DAG']['3'], 'DAG', bookCodeIndex());
164
- t.equal(unsuccinctDAG[0].fromVerseStart, 24);
165
- t.equal(unsuccinctDAG[0].fromVerseEnd, 52);
166
- t.equal(unsuccinctDAG[0].bookCode, 'S3Y');
167
- t.equal(unsuccinctDAG[0].mapping[0].ch, 1);
168
- t.equal(unsuccinctDAG[0].mapping[0].verseStart, 1);
169
- const unsuccinctACT = unsuccinctifyVerseMapping(svm['ACT']['19'], 'ACT', bookCodeIndex());
170
- t.equal(unsuccinctACT[0].fromVerseStart, 40);
171
- t.equal(unsuccinctACT[0].fromVerseEnd, 40);
172
- t.equal(unsuccinctACT[0].bookCode, 'ACT');
173
- t.equal(unsuccinctACT[0].mapping[0].ch, 19);
174
- t.equal(unsuccinctACT[0].mapping[0].verseStart, 40);
175
- t.equal(unsuccinctACT[0].mapping[1].ch, 19);
176
- t.equal(unsuccinctACT[0].mapping[1].verseStart, 41);
177
- } catch (err) {
178
- console.log(err);
179
- }
180
- },
181
- );
182
-
183
- test(
184
- `mapVerse forward (${testGroup})`,
185
- function (t) {
186
- try {
187
- const vrsString = fse.readFileSync(path.resolve(__dirname, '../../test_data/utils/truncated_versification.vrs')).toString();
188
- const mappings = [
189
- [['GEN', 31, 1], ['GEN', 31, 1]],
190
- [['GEN', 31, 55], ['GEN', 32, 1]],
191
- [['GEN', 32, 17], ['GEN', 32, 18]],
192
- [['PSA', 51, 0], ['PSA', 51, 1]],
193
- [['PSA', 51, 1], ['PSA', 51, 3]],
194
- [['ACT', 19, 40], ['ACT',19, 40]],
195
- [['ACT', 19, 41], ['ACT',19, 40]],
196
- [['S3Y', 1, 2], ['DAG', 3, 25]],
197
- ];
198
- t.plan(3 * mappings.length);
199
- const vrsJson = vrs2json(vrsString);
200
- const svm = succinctifyVerseMappings(vrsJson.mappedVerses);
201
-
202
- for (const [[fromBook, fromCh, fromV], [toBook, toCh, toV]] of mappings) {
203
- const succinct = svm[fromBook][fromCh.toString()];
204
- const mapping = mapVerse(succinct, fromBook, fromCh, fromV);
205
- t.equal(mapping[0], toBook);
206
- t.equal(mapping[1][0][0], toCh);
207
- t.equal(mapping[1][0][1], toV);
208
- }
209
- } catch (err) {
210
- console.log(err);
211
- }
212
- },
213
- );
214
-
215
- test(
216
- `mapVerse reverse (${testGroup})`,
217
- function (t) {
218
- try {
219
- const vrsString = fse.readFileSync(path.resolve(__dirname, '../../test_data/utils/truncated_versification.vrs')).toString();
220
- const mappings = [
221
- [['GEN', 32, 99], ['GEN', [[32, 99]]]],
222
- [['GEN', 32, 1], ['GEN', [[31, 55]]]],
223
- [['GEN', 32, 18], ['GEN', [[32, 17]]]],
224
- [['PSA', 11, 1], ['PSA', [[10, 2]]]],
225
- [['PSA', 51, 1], ['PSA', [[51, 0]]]],
226
- [['PSA', 51, 2], ['PSA', [[51, 0]]]],
227
- [['PSA', 51, 3], ['PSA', [[51, 1]]]],
228
- [['ACT', 19, 40], ['ACT', [[19, 40], [19, 41]]]],
229
- [['DAG', 3, 25], ['S3Y', [[1, 2]]]],
230
- ];
231
- t.plan(2 * mappings.length);
232
- const forwardJson = vrs2json(vrsString);
233
- // console.log(JSON.stringify(forwardJson, null, 2))
234
- const reverseJson = reverseVersification(forwardJson);
235
- // console.log(JSON.stringify(reverseJson, null, 2))
236
- const svm = succinctifyVerseMappings(reverseJson.reverseMappedVerses);
237
-
238
- for (const [[fromBook, fromCh, fromV], [toBook, toSpecs]] of mappings) {
239
- const succinct = svm[fromBook][fromCh.toString()];
240
- const mapping = mapVerse(succinct, fromBook, fromCh, fromV);
241
- t.equal(mapping[0], toBook);
242
- t.ok(deepEqual(mapping[1], toSpecs));
243
- }
244
- } catch (err) {
245
- console.log(err);
246
- }
247
- },
248
- );
249
-
package/test/lib/load.js DELETED
@@ -1,110 +0,0 @@
1
- const path = require('path');
2
- const fse = require('fs-extra');
3
-
4
- // const pkSrc = (process.env.PKSRC) || 'dist';
5
-
6
- // const { Proskomma } = require(`../../${pkSrc}/index.cjs`);
7
- const { Proskomma } = require("../../src/index.cjs");
8
-
9
- const pkWithDoc = (fp, selectors, options, customTags, emptyBlocks, tags) => {
10
- if (!options) {
11
- options = {};
12
- }
13
-
14
- const content = fse.readFileSync(path.resolve(__dirname, fp));
15
- let contentType = fp.split('.').pop();
16
-
17
- const pk = new Proskomma();
18
- const pkDoc = pk.importDocument(
19
- selectors,
20
- contentType,
21
- content,
22
- options,
23
- customTags,
24
- emptyBlocks,
25
- tags,
26
- );
27
- return [pk, pkDoc];
28
- };
29
-
30
- const customPkWithDoc = (pkClass, fp, selectors, options) => {
31
- if (!options) {
32
- options = {};
33
- }
34
-
35
- const content = fse.readFileSync(path.resolve(__dirname, fp));
36
- let contentType = fp.split('.').pop();
37
-
38
- const pk = new pkClass();
39
- const pkDoc = pk.importDocument(
40
- selectors,
41
- contentType,
42
- content,
43
- options,
44
- );
45
- return [pk, pkDoc];
46
- };
47
-
48
- const pkWithDocs = (contentSpecs) => {
49
- const pk = new Proskomma();
50
-
51
- for (const [fp, selectors] of contentSpecs) {
52
- const content = fse.readFileSync(path.resolve(__dirname, fp));
53
- let contentType = fp.split('.').pop();
54
-
55
- pk.importDocument(
56
- selectors,
57
- contentType,
58
- content,
59
- {},
60
- );
61
- }
62
- return pk;
63
- };
64
-
65
- const customPkWithDocs = (pkClass, contentSpecs) => {
66
- const pk = new pkClass();
67
-
68
- for (const [fp, selectors] of contentSpecs) {
69
- const content = fse.readFileSync(path.resolve(__dirname, fp));
70
- let contentType = fp.split('.').pop();
71
-
72
- pk.importDocument(
73
- selectors,
74
- contentType,
75
- content,
76
- {},
77
- );
78
- }
79
- return pk;
80
- };
81
-
82
- const pkWithDocSetDocs = (fps, selectors, options) => {
83
- if (!options) {
84
- options = {};
85
- }
86
-
87
- const fpContent = [];
88
- fps.forEach(fp => fpContent.push(fse.readFileSync(path.resolve(__dirname, fp))));
89
- let contentType = fps[0].split('.').pop();
90
-
91
- const pk = new Proskomma();
92
- const pkDocs = pk.importDocuments(
93
- selectors,
94
- contentType,
95
- fpContent,
96
- options,
97
- );
98
- return [pk, pkDocs];
99
- };
100
-
101
- const escapeStringQuotes = str => str.replace(/"/g, '\\"').replace(/'/, '\\\'');
102
-
103
- module.exports = {
104
- pkWithDoc,
105
- customPkWithDoc,
106
- pkWithDocs,
107
- customPkWithDocs,
108
- pkWithDocSetDocs,
109
- escapeStringQuotes,
110
- };
@@ -1,53 +0,0 @@
1
- /* eslint-disable no-await-in-loop */
2
- const test = require('tape');
3
-
4
- const { pkWithDocs } = require('../lib/load.js');
5
-
6
- const testGroup = 'Diff';
7
-
8
- const pk = pkWithDocs([
9
- ['../test_data/usx/diff1.usx', {
10
- lang: 'eng',
11
- abbr: 'web',
12
- }],
13
- ['../test_data/usx/diff2.usx', {
14
- lang: 'eng',
15
- abbr: 'web2',
16
- }],
17
- ]);
18
-
19
- const docIds = Object.keys(pk.documents);
20
-
21
- test(
22
- `Compare 2 documents (${testGroup})`,
23
- async function (t) {
24
- try {
25
- const expected = [
26
- ['words', 1, 1, 5, 3, 2],
27
- ['tokens', 1, 1, 5, 3, 4],
28
- ];
29
- t.plan(6 * expected.length);
30
-
31
- for (const expectation of expected) {
32
- const query = `
33
- {
34
- diff(
35
- document1: "${docIds[0]}" document2: "${docIds[1]}" mode: "%mode%"
36
- ) {
37
- chapter verse diffType text1 text2 tokensDiff wordsDiff
38
- }
39
- }`.replace('%mode%', expectation[0]);
40
- const result = await pk.gqlQuery(query);
41
- t.equal(result.errors, undefined);
42
- const diff = result.data.diff;
43
- t.equal(diff.filter(d => d.diffType === 'addedChapter').length, expectation[1]);
44
- t.equal(diff.filter(d => d.diffType === 'removedChapter').length, expectation[2]);
45
- t.equal(diff.filter(d => d.diffType === 'addedVerse').length, expectation[3]);
46
- t.equal(diff.filter(d => d.diffType === 'removedVerse').length, expectation[4]);
47
- t.equal(diff.filter(d => d.diffType === 'changedVerse').length, expectation[5]);
48
- }
49
- } catch (err) {
50
- console.log(err);
51
- }
52
- },
53
- );