proskomma-core 0.9.12 → 0.9.14

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 (178) hide show
  1. package/esm/wrapper.mjs +1 -1
  2. package/{index.js → index.cjs} +1 -1
  3. package/package.json +2 -3
  4. package/babel.config.js +0 -18
  5. package/docs/_config.yml +0 -1
  6. package/docs/index.md +0 -3
  7. package/docs/pk_edit_0_9.odt +0 -0
  8. package/docs/pk_edit_0_9.pdf +0 -0
  9. package/docs/proskomma_101_slideshow.odp +0 -0
  10. package/docs/proskomma_101_slideshow.pdf +0 -0
  11. package/docs/proskomma_edit_html.png +0 -0
  12. package/docs/proskomma_edit_html.svg +0 -451
  13. package/docs/proskomma_edit_reference.png +0 -0
  14. package/docs/proskomma_edit_reference.svg +0 -349
  15. package/docs/repo_logo.png +0 -0
  16. package/test/code/main/bad.cjs +0 -79
  17. package/test/code/main/basics.cjs +0 -534
  18. package/test/code/main/block.cjs +0 -586
  19. package/test/code/main/block_scope_numbers.cjs +0 -31
  20. package/test/code/main/blocks_with_atts.cjs +0 -150
  21. package/test/code/main/blocks_with_cv.cjs +0 -250
  22. package/test/code/main/break.cjs +0 -73
  23. package/test/code/main/checksum.cjs +0 -36
  24. package/test/code/main/cl_global.cjs +0 -35
  25. package/test/code/main/class_for_fragment.cjs +0 -18
  26. package/test/code/main/clean_usfm.cjs +0 -46
  27. package/test/code/main/cp_vp.cjs +0 -158
  28. package/test/code/main/custom.cjs +0 -124
  29. package/test/code/main/cv.cjs +0 -249
  30. package/test/code/main/cvMatching.cjs +0 -155
  31. package/test/code/main/cv_indexes.cjs +0 -189
  32. package/test/code/main/cv_navigation.cjs +0 -124
  33. package/test/code/main/document.cjs +0 -382
  34. package/test/code/main/empty_blocks.cjs +0 -71
  35. package/test/code/main/entries.cjs +0 -402
  36. package/test/code/main/export_lexing_regexes.cjs +0 -19
  37. package/test/code/main/fig.cjs +0 -67
  38. package/test/code/main/filter.cjs +0 -222
  39. package/test/code/main/glossary.cjs +0 -36
  40. package/test/code/main/graft_headings.cjs +0 -36
  41. package/test/code/main/graft_introduction.cjs +0 -96
  42. package/test/code/main/graft_note.cjs +0 -104
  43. package/test/code/main/graft_rems.cjs +0 -34
  44. package/test/code/main/graft_sidebars.cjs +0 -62
  45. package/test/code/main/graft_title.cjs +0 -36
  46. package/test/code/main/hello.cjs +0 -105
  47. package/test/code/main/import_document.cjs +0 -22
  48. package/test/code/main/import_usfm_int.cjs +0 -48
  49. package/test/code/main/item_groups.cjs +0 -133
  50. package/test/code/main/items_with_cv.cjs +0 -311
  51. package/test/code/main/milestone_attributes.cjs +0 -163
  52. package/test/code/main/mixed_sequence_documents.cjs +0 -137
  53. package/test/code/main/mixed_sequences.cjs +0 -217
  54. package/test/code/main/modify_sequence.cjs +0 -29
  55. package/test/code/main/multiple_chapters.cjs +0 -58
  56. package/test/code/main/multiple_content.cjs +0 -105
  57. package/test/code/main/mutate_add.cjs +0 -180
  58. package/test/code/main/mutate_delete.cjs +0 -236
  59. package/test/code/main/mutate_rehash.cjs +0 -68
  60. package/test/code/main/mutate_tags.cjs +0 -90
  61. package/test/code/main/mutate_update.cjs +0 -538
  62. package/test/code/main/selectors.cjs +0 -289
  63. package/test/code/main/sequence.cjs +0 -361
  64. package/test/code/main/serialize.cjs +0 -104
  65. package/test/code/main/spans.cjs +0 -51
  66. package/test/code/main/split_long_tokens.cjs +0 -30
  67. package/test/code/main/standard_vrs.cjs +0 -76
  68. package/test/code/main/subclass.cjs +0 -25
  69. package/test/code/main/table.cjs +0 -119
  70. package/test/code/main/tags.cjs +0 -248
  71. package/test/code/main/token_alignment.cjs +0 -84
  72. package/test/code/main/trees.cjs +0 -211
  73. package/test/code/main/tribos.cjs +0 -865
  74. package/test/code/main/tsv.cjs +0 -385
  75. package/test/code/main/usx_ref.cjs +0 -65
  76. package/test/code/main/verse_mapping.cjs +0 -252
  77. package/test/code/main/verse_range.cjs +0 -31
  78. package/test/code/main/word_likes.cjs +0 -41
  79. package/test/code/utils/byte_array.cjs +0 -271
  80. package/test/code/utils/canons.cjs +0 -20
  81. package/test/code/utils/generate_id.cjs +0 -17
  82. package/test/code/utils/graft_defs.cjs +0 -16
  83. package/test/code/utils/inspect.cjs +0 -130
  84. package/test/code/utils/items.cjs +0 -56
  85. package/test/code/utils/push_succinct.cjs +0 -69
  86. package/test/code/utils/scope_defs.cjs +0 -79
  87. package/test/code/utils/serialize.cjs +0 -28
  88. package/test/code/utils/splice.cjs +0 -67
  89. package/test/code/utils/tags.cjs +0 -69
  90. package/test/code/utils/versification.cjs +0 -249
  91. package/test/lib/load.js +0 -110
  92. package/test/skipped_code/diff.js +0 -53
  93. package/test/test_data/inputBlockSpec/dodson.json +0 -1654
  94. package/test/test_data/inputBlockSpec/kv.json +0 -326
  95. package/test/test_data/inputBlockSpec/mk1.json +0 -1019
  96. package/test/test_data/inputBlockSpec/table.json +0 -170
  97. package/test/test_data/tree/genealogy.json +0 -55
  98. package/test/test_data/tree/jude.json +0 -15965
  99. package/test/test_data/tsv/en_tn_66-JUD.tsv +0 -75
  100. package/test/test_data/tsv/twl_JUD.tsv +0 -144
  101. package/test/test_data/usfm/1pe_webbe.usfm +0 -13
  102. package/test/test_data/usfm/66-JUD-ust.usfm +0 -1089
  103. package/test/test_data/usfm/78-GALspavbl.usfm +0 -10
  104. package/test/test_data/usfm/add_test.usfm +0 -15
  105. package/test/test_data/usfm/backslash.usfm +0 -4
  106. package/test/test_data/usfm/cl.usfm +0 -14
  107. package/test/test_data/usfm/cp_vp.usfm +0 -8
  108. package/test/test_data/usfm/custom.usfm +0 -13
  109. package/test/test_data/usfm/en_ust_oba.usfm +0 -875
  110. package/test/test_data/usfm/en_ust_psa_1.usfm +0 -20
  111. package/test/test_data/usfm/fig.usfm +0 -3
  112. package/test/test_data/usfm/filter.usfm +0 -7
  113. package/test/test_data/usfm/footnote.usfm +0 -11
  114. package/test/test_data/usfm/frt.usfm +0 -4
  115. package/test/test_data/usfm/headings.usfm +0 -7
  116. package/test/test_data/usfm/hello.usfm +0 -8
  117. package/test/test_data/usfm/int.usfm +0 -7
  118. package/test/test_data/usfm/milestone_attributes.usfm +0 -7
  119. package/test/test_data/usfm/milestone_attributes_default.usfm +0 -7
  120. package/test/test_data/usfm/no_break_space.usfm +0 -4
  121. package/test/test_data/usfm/no_mt.usfm +0 -6
  122. package/test/test_data/usfm/rems.usfm +0 -6
  123. package/test/test_data/usfm/section_intros.usfm +0 -26
  124. package/test/test_data/usfm/sidebars.usfm +0 -25
  125. package/test/test_data/usfm/slash_in_att.usfm +0 -6
  126. package/test/test_data/usfm/soft_line_break.usfm +0 -4
  127. package/test/test_data/usfm/spans.usfm +0 -5
  128. package/test/test_data/usfm/split_long_tokens.usfm +0 -6
  129. package/test/test_data/usfm/table.usfm +0 -18
  130. package/test/test_data/usfm/table_at_end.usfm +0 -11
  131. package/test/test_data/usfm/table_in_intro.usfm +0 -22
  132. package/test/test_data/usfm/table_no_end_cells.usfm +0 -18
  133. package/test/test_data/usfm/tit_kitchen_sink.usfm +0 -73
  134. package/test/test_data/usfm/titus_template.usfm +0 -58
  135. package/test/test_data/usfm/ugnt_3jn.usfm +0 -265
  136. package/test/test_data/usfm/ult_3jn.usfm +0 -335
  137. package/test/test_data/usfm/unknown.usfm +0 -5
  138. package/test/test_data/usfm/ust_psa.usfm +0 -29
  139. package/test/test_data/usfm/ust_psa_verse_ranges.usfm +0 -24
  140. package/test/test_data/usfm/ust_psa_with_ts.usfm +0 -29
  141. package/test/test_data/usfm/verse_breaks_in_blocks.usfm +0 -20
  142. package/test/test_data/usfm/verse_range.usfm +0 -7
  143. package/test/test_data/usfm/web_ecc.usfm +0 -391
  144. package/test/test_data/usfm/web_psa51.usfm +0 -71
  145. package/test/test_data/usfm/whitespace.usfm +0 -12
  146. package/test/test_data/usfm/xref.usfm +0 -11
  147. package/test/test_data/usx/bad_element.usx +0 -2
  148. package/test/test_data/usx/cp_vp.usx +0 -12
  149. package/test/test_data/usx/diff1.usx +0 -59
  150. package/test/test_data/usx/diff2.usx +0 -74
  151. package/test/test_data/usx/douay_rheims_ecc.usx +0 -58
  152. package/test/test_data/usx/douay_rheims_psa.usx +0 -5366
  153. package/test/test_data/usx/douay_rheims_psa_40_60.usx +0 -666
  154. package/test/test_data/usx/douay_rheims_rut.usx +0 -26
  155. package/test/test_data/usx/esg3.usx +0 -47
  156. package/test/test_data/usx/fig.usx +0 -6
  157. package/test/test_data/usx/milestone_attributes.usx +0 -11
  158. package/test/test_data/usx/not_nfc18_glo.usx +0 -9
  159. package/test/test_data/usx/not_nfc18_phm.usx +0 -24
  160. package/test/test_data/usx/opt_break.usx +0 -10
  161. package/test/test_data/usx/sidebars.usx +0 -29
  162. package/test/test_data/usx/table.usx +0 -23
  163. package/test/test_data/usx/web_psa.usx +0 -8489
  164. package/test/test_data/usx/web_psa150.usx +0 -33
  165. package/test/test_data/usx/web_psa_40_60.usx +0 -1079
  166. package/test/test_data/usx/web_rut.usx +0 -95
  167. package/test/test_data/usx/web_rut_1.usx +0 -17
  168. package/test/test_data/utils/douay_rheims.vrs +0 -520
  169. package/test/test_data/utils/douay_rheims_PSA.usx +0 -5366
  170. package/test/test_data/utils/serialize_example.json +0 -91
  171. package/test/test_data/utils/truncated_versification.vrs +0 -29
  172. package/test/test_data/utils/web_rut_items.json +0 -2977
  173. package/test/test_data/utils/webbe.vrs +0 -395
  174. package/test/test_data/utils/webbe_PSA.usx +0 -8489
  175. package/test/test_data/vrs/douay_rheims.vrs +0 -520
  176. package/test/test_data/vrs/truncated_versification.vrs +0 -27
  177. package/test/test_data/vrs/webbe.vrs +0 -397
  178. package/webpack.prod.js +0 -50
@@ -1,586 +0,0 @@
1
- const test = require('tape');
2
-
3
- const { pkWithDoc } = require('../../lib/load.js');
4
-
5
- const testGroup = 'Graph Block';
6
-
7
- const pk = pkWithDoc('../test_data/usfm/hello.usfm', {
8
- lang: 'eng',
9
- abbr: 'ust',
10
- })[0];
11
- const pk2 = pkWithDoc('../test_data/usfm/headings.usfm', {
12
- lang: 'eng',
13
- abbr: 'ust',
14
- })[0];
15
- const pk3 = pkWithDoc('../test_data/usx/web_rut.usx', {
16
- lang: 'eng',
17
- abbr: 'web',
18
- })[0];
19
- const pk4 = pkWithDoc('../test_data/usfm/footnote.usfm', {
20
- lang: 'eng',
21
- abbr: 'ust',
22
- })[0];
23
- const pk5 = pkWithDoc('../test_data/usfm/verse_breaks_in_blocks.usfm', {
24
- lang: 'eng',
25
- abbr: 'ust',
26
- })[0];
27
- const pk6 = pkWithDoc('../test_data/usfm/whitespace.usfm', {
28
- lang: 'eng',
29
- abbr: 'ust',
30
- })[0];
31
- const pk7 = pkWithDoc('../test_data/usx/web_psa.usx', {
32
- lang: 'eng',
33
- abbr: 'web',
34
- })[0];
35
- const pk8 = pkWithDoc('../test_data/usfm/add_test.usfm', {
36
- lang: 'eng',
37
- abbr: 'ust',
38
- })[0];
39
-
40
- const blocksText = blocks => blocks.map(
41
- b => b.items.map(
42
- i => i.type === 'token' ? i.payload : '',
43
- ).map(
44
- t => t.replace(/[ \n\r\t]+/, ' '),
45
- ).join(''),
46
- ).join(' ')
47
- .trim();
48
-
49
- test(
50
- `Length (${testGroup})`,
51
- async function (t) {
52
- try {
53
- const lengths = {
54
- cBL: 78,
55
- bgBL: 0,
56
- osBL: 0,
57
- isBL: 9,
58
- ntBL: 1,
59
- };
60
- t.plan(2 + Object.keys(lengths).length);
61
- const query = '{ documents { mainSequence { blocks { cBL bgBL osBL isBL ntBL } } } }';
62
- const result = await pk.gqlQuery(query);
63
- t.equal(result.errors, undefined);
64
- t.ok('blocks' in result.data.documents[0].mainSequence);
65
-
66
- for (const [field, value] of Object.entries(lengths)) {
67
- t.equal(result.data.documents[0].mainSequence.blocks[0][field], value);
68
- }
69
- } catch (err) {
70
- console.log(err);
71
- }
72
- },
73
- );
74
-
75
- test(
76
- `Length in Items; nt (${testGroup})`,
77
- async function (t) {
78
- try {
79
- const lengths = [
80
- {
81
- cL: 578,
82
- bgL: 1,
83
- osL: 0,
84
- isL: 19,
85
- },
86
- {
87
- cL: 65,
88
- bgL: 0,
89
- osL: 3,
90
- isL: 2,
91
- },
92
- ];
93
- t.plan(4 + (lengths.length * Object.keys(lengths[0]).length));
94
- const query = '{ documents { mainSequence { blocks { cL bgL osL isL nt text } } } }';
95
- const result = await pk3.gqlQuery(query);
96
- t.equal(result.errors, undefined);
97
- t.ok('blocks' in result.data.documents[0].mainSequence);
98
-
99
- for (const blockNo of [0, 1]) {
100
- const block = result.data.documents[0].mainSequence.blocks[blockNo];
101
-
102
- for (const [field, value] of Object.entries(lengths[blockNo])) {
103
- t.equal(block[field], value);
104
- }
105
- }
106
-
107
- const nts = result.data.documents[0].mainSequence.blocks.map(b => b.nt);
108
- t.equal(nts[0], 0);
109
- t.ok(nts[1] > 0);
110
- } catch (err) {
111
- console.log(err);
112
- }
113
- },
114
- );
115
-
116
- test(
117
- `Render as Text (${testGroup})`,
118
- async function (t) {
119
- try {
120
- t.plan(3);
121
- const query = '{ documents { mainSequence { blocks { text dump } } } }';
122
- const result = await pk2.gqlQuery(query);
123
- t.equal(result.errors, undefined);
124
- const block = result.data.documents[0].mainSequence.blocks[0];
125
- t.equal(block.text, 'Dear Theophilus,');
126
- t.ok(block.dump.includes('+verse/1+'));
127
- } catch (err) {
128
- console.log(err);
129
- }
130
- },
131
- );
132
-
133
- test(
134
- `Normalize text whitespace (${testGroup})`,
135
- async function (t) {
136
- try {
137
- t.plan(2);
138
- const query = '{ documents { mainSequence { blocks { text(normalizeSpace:true) } } } }';
139
- const result = await pk6.gqlQuery(query);
140
- t.equal(result.errors, undefined);
141
- const block = result.data.documents[0].mainSequence.blocks[0];
142
- t.equal(block.text, 'This is how the Good News of JC began...');
143
- } catch (err) {
144
- console.log(err);
145
- }
146
- },
147
- );
148
-
149
- test(
150
- `Normalize token whitespace (${testGroup})`,
151
- async function (t) {
152
- try {
153
- t.plan(5);
154
- const query = '{' +
155
- ' documents {' +
156
- ' mainSequence {' +
157
- ' blocks {' +
158
- ' raw: tokens {payload(normalizeSpace:false)}' +
159
- ' normalized: tokens {payload(normalizeSpace:true)}' +
160
- ' }' +
161
- ' }' +
162
- ' }' +
163
- '}';
164
- const result = await pk6.gqlQuery(query);
165
- t.equal(result.errors, undefined);
166
- const block = result.data.documents[0].mainSequence.blocks[0];
167
- t.equal(block.raw[1].payload, ' ');
168
- t.equal(block.normalized[1].payload, ' ');
169
- t.equal(block.raw[3].payload, '\n');
170
- t.equal(block.normalized[3].payload, ' ');
171
- } catch (err) {
172
- console.log(err);
173
- }
174
- },
175
- );
176
-
177
- test(
178
- `Token includeChars (${testGroup})`,
179
- async function (t) {
180
- try {
181
- t.plan(2);
182
- const query = '{' +
183
- ' documents {' +
184
- ' mainSequence {' +
185
- ' blocks {' +
186
- ' tokens {payload(includeChars:["G", "N", "T"])}' +
187
- ' }' +
188
- ' }' +
189
- ' }' +
190
- '}';
191
- const result = await pk6.gqlQuery(query);
192
- t.equal(result.errors, undefined);
193
- const block = result.data.documents[0].mainSequence.blocks[0];
194
- const text = block.tokens.map(t => t.payload).join('');
195
- t.equal(text, 'TGN');
196
- } catch (err) {
197
- console.log(err);
198
- }
199
- },
200
- );
201
-
202
- test(
203
- `Token excludeChars (${testGroup})`,
204
- async function (t) {
205
- try {
206
- t.plan(4);
207
- const query = '{' +
208
- ' documents {' +
209
- ' mainSequence {' +
210
- ' blocks {' +
211
- ' tokens {payload(excludeChars:["a", "e", "i", "o", "u"])}' +
212
- ' }' +
213
- ' }' +
214
- ' }' +
215
- '}';
216
- const result = await pk6.gqlQuery(query);
217
- t.equal(result.errors, undefined);
218
- const tokens = result.data.documents[0].mainSequence.blocks[0].tokens;
219
- t.equal(tokens[0].payload, 'Ths');
220
- t.equal(tokens[2].payload, 's');
221
- t.equal(tokens[8].payload, 'Gd');
222
- } catch (err) {
223
- console.log(err);
224
- }
225
- },
226
- );
227
-
228
- test(
229
- `Token withSubTypes (${testGroup})`,
230
- async function (t) {
231
- try {
232
- t.plan(4);
233
- const query = '{' +
234
- ' documents {' +
235
- ' mainSequence {' +
236
- ' blocks {' +
237
- ' tokens(withSubTypes:"wordLike") {payload}' +
238
- ' }' +
239
- ' }' +
240
- ' }' +
241
- '}';
242
- const result = await pk6.gqlQuery(query);
243
- t.equal(result.errors, undefined);
244
- const tokens = result.data.documents[0].mainSequence.blocks[0].tokens;
245
- t.equal(tokens[0].payload, 'This');
246
- t.equal(tokens[1].payload, 'is');
247
- t.equal(tokens[4].payload, 'Good');
248
- } catch (err) {
249
- console.log(err);
250
- }
251
- },
252
- );
253
-
254
- test(
255
- `Scopes (${testGroup})`,
256
- async function (t) {
257
- try {
258
- const scopeLabels = [
259
- 'chapter/1',
260
- 'verse/1',
261
- 'verses/1',
262
- 'blockTag/p',
263
- ];
264
- t.plan(4 + scopeLabels.length);
265
- const query = '{ documents { mainSequence { blocks { scopeLabels verseScope: scopeLabels(startsWith:"verse/") bs { payload } } } } }';
266
- const result = await pk.gqlQuery(query);
267
- t.equal(result.errors, undefined);
268
- const block = result.data.documents[0].mainSequence.blocks[0];
269
- t.equal(block.bs.payload, 'blockTag/p');
270
-
271
- for (const scopeLabel of scopeLabels) {
272
- t.ok(block.scopeLabels.includes(scopeLabel));
273
- }
274
- t.equal(block.verseScope.length, 1);
275
- t.equal(block.verseScope[0], 'verse/1');
276
- } catch (err) {
277
- console.log(err);
278
- }
279
- },
280
- );
281
-
282
- test(
283
- `Grafts (${testGroup})`,
284
- async function (t) {
285
- try {
286
- t.plan(3);
287
- const query = '{ documents { mainSequence { blocks { bg { subType payload } } } } }';
288
- const result = await pk2.gqlQuery(query);
289
- t.equal(result.errors, undefined);
290
- const block = result.data.documents[0].mainSequence.blocks[0];
291
- t.equal(block.bg[0].subType, 'title');
292
- t.equal(block.bg[1].subType, 'heading');
293
- } catch (err) {
294
- console.log(err);
295
- }
296
- },
297
- );
298
-
299
- test(
300
- `Tokens (${testGroup})`,
301
- async function (t) {
302
- try {
303
- t.plan(5);
304
- const query = `{ documents { mainSequence { blocks { tokens { type subType payload } } } } }`;
305
- const result = await pk4.gqlQuery(query);
306
- t.equal(result.errors, undefined);
307
- t.ok('blocks' in result.data.documents[0].mainSequence);
308
- const blocks = result.data.documents[0].mainSequence.blocks;
309
- t.equal(blocks[2].tokens.filter(i => i.type === 'graft').length, 0);
310
- t.equal(blocks[0].tokens.filter(i => i.type === 'scope').length, 0);
311
- t.ok(blocks[0].tokens.filter(i => i.type === 'token').length > 0);
312
- } catch (err) {
313
- console.log(err);
314
- }
315
- },
316
- );
317
-
318
- test(
319
- `Items (${testGroup})`,
320
- async function (t) {
321
- try {
322
- const openScopes = [
323
- 'chapter/1',
324
- 'verse/9',
325
- 'verses/9',
326
- ];
327
- t.plan(15 + openScopes.length);
328
- const query = '{ documents { mainSequence { blocks {' +
329
- `items {type subType payload}` +
330
- `bg {subType}` +
331
- `os {type payload}` +
332
- `is {type payload}` +
333
- '} } } }';
334
- let result = await pk.gqlQuery(query);
335
- t.equal(result.errors, undefined);
336
- let block = result.data.documents[0].mainSequence.blocks[0];
337
- t.equal(block.items[0].type, 'scope');
338
- t.equal(block.items[0].payload, 'chapter/1');
339
- t.equal(block.items[3].subType, 'wordLike');
340
- t.equal(block.items[3].payload, 'This');
341
- t.equal(block.os.length, 0);
342
- t.equal(block.bg.length, 0);
343
- t.equal(block.is.length, 3);
344
- t.equal(block.is[0].payload, 'chapter/1');
345
- result = await pk2.gqlQuery(query);
346
- t.equal(result.errors, undefined);
347
- block = result.data.documents[0].mainSequence.blocks[0];
348
- t.equal(block.bg.length, 2);
349
- t.equal(block.bg[0].subType, 'title');
350
- t.equal(block.bg[1].subType, 'heading');
351
- result = await pk3.gqlQuery(query);
352
- t.equal(result.errors, undefined);
353
- block = result.data.documents[0].mainSequence.blocks[1];
354
- t.equal(block.os.length, 3);
355
-
356
- for (const openScope of openScopes) {
357
- t.ok(block.os.map(s => s.payload).includes(openScope));
358
- }
359
- } catch (err) {
360
- console.log(err);
361
- }
362
- },
363
- );
364
-
365
- test(
366
- `Items withScopes (${testGroup})`,
367
- async function (t) {
368
- try {
369
- t.plan(2);
370
- const requiredScopes = '["chapter/1", "verse/2"]';
371
- const query = `{ documents { mainSequence { blocks(withScopes:${requiredScopes}) { items(withScopes:${requiredScopes}) {type subType payload} } } } }`;
372
- let result = await pk5.gqlQuery(query);
373
- t.equal(result.errors, undefined);
374
- const blocks = result.data.documents[0].mainSequence.blocks;
375
- const texts = blocksText(blocks);
376
-
377
- t.equal(
378
- texts,
379
- 'Instead, those with whom Yahweh is pleased delight in understanding what he teaches us. ' +
380
- 'They read and think every day and every night about what Yahweh teaches.',
381
- );
382
- } catch (err) {
383
- console.log(err);
384
- }
385
- },
386
- );
387
-
388
- test(
389
- `Tokens withScopes (${testGroup})`,
390
- async function (t) {
391
- try {
392
- t.plan(2);
393
- const requiredScopes = '["chapter/1", "verse/2"]';
394
- const query = `{ documents { mainSequence { blocks(withScopes:${requiredScopes}) {items: tokens(withScopes:${requiredScopes}) { type subType payload } } } } }`;
395
- let result = await pk5.gqlQuery(query);
396
- t.equal(result.errors, undefined);
397
- const blocks = result.data.documents[0].mainSequence.blocks;
398
- const texts = blocksText(blocks);
399
-
400
- t.equal(
401
- texts,
402
- 'Instead, those with whom Yahweh is pleased delight in understanding what he teaches us. ' +
403
- 'They read and think every day and every night about what Yahweh teaches.',
404
- );
405
- } catch (err) {
406
- console.log(err);
407
- }
408
- },
409
- );
410
-
411
- test(
412
- `Items anyScope (${testGroup})`,
413
- async function (t) {
414
- try {
415
- t.plan(2);
416
- const requiredScopes = '["chapter/1", "verse/2"]';
417
- const query = `{ documents { mainSequence { blocks(withScopes:${requiredScopes}) { items(anyScope:true withScopes:["verse/2", "verse/2000"]) {type subType payload} } } } }`;
418
- let result = await pk5.gqlQuery(query);
419
- t.equal(result.errors, undefined);
420
- const blocks = result.data.documents[0].mainSequence.blocks;
421
- const texts = blocksText(blocks);
422
-
423
- t.equal(
424
- texts,
425
- 'Instead, those with whom Yahweh is pleased delight in understanding what he teaches us. ' +
426
- 'They read and think every day and every night about what Yahweh teaches.',
427
- );
428
- } catch (err) {
429
- console.log(err);
430
- }
431
- },
432
- );
433
-
434
- test(
435
- `Tokens anyScope (${testGroup})`,
436
- async function (t) {
437
- try {
438
- t.plan(2);
439
- const requiredScopes = '["chapter/1", "verse/2"]';
440
- const query = `{ documents { mainSequence { blocks(withScopes:${requiredScopes}) { items: tokens(anyScope:true withScopes:["verse/2", "verse/2000"]) { type subType payload } } } } }`;
441
- let result = await pk5.gqlQuery(query);
442
- t.equal(result.errors, undefined);
443
- const blocks = result.data.documents[0].mainSequence.blocks;
444
- const texts = blocksText(blocks);
445
-
446
- t.equal(
447
- texts,
448
- 'Instead, those with whom Yahweh is pleased delight in understanding what he teaches us. ' +
449
- 'They read and think every day and every night about what Yahweh teaches.',
450
- );
451
- } catch (err) {
452
- console.log(err);
453
- }
454
- },
455
- );
456
-
457
- test(
458
- `Tokens withChars (${testGroup})`,
459
- async function (t) {
460
- try {
461
- t.plan(3);
462
- const requiredChars = '["tree"]';
463
- const query = `{documents { mainSequence { blocks(withChars:${requiredChars}) {` +
464
- `tokens(withChars:${requiredChars} includeContext:true) { payload scopes(startsWith:["chapter", "verses"])} } } } }`;
465
- let result = await pk7.gqlQuery(query);
466
- t.equal(result.errors, undefined);
467
- const blocks = result.data.documents[0].mainSequence.blocks;
468
- const tokens = blocks.map(b => b.tokens.map(t => t.payload)).reduce((a, b) => a.concat(b));
469
- t.ok(tokens.filter(s => s === 'tree').length > 1);
470
- t.equal(tokens.filter(s => s !== 'tree').length, 0);
471
- } catch (err) {
472
- console.log(err);
473
- }
474
- },
475
- );
476
-
477
- test(
478
- `Tokens filtered by payload (${testGroup})`,
479
- async function (t) {
480
- try {
481
- const charClauses = [
482
- [`withChars: ["righteous", "upright"]`, 66, 23, 89],
483
- [`withMatchingChars: ["right"]`, 66, 23, 213],
484
- ];
485
- t.plan((4 * charClauses.length) + 2);
486
-
487
- let results = [];
488
-
489
- for (const charClause of charClauses) {
490
- const query = '{ documents { mainSequence { blocks {' +
491
- `text tokens(includeContext:true ${charClause[0]}) { payload position scopes(startsWith:["chapter/", "verses/"]) }` +
492
- '} } } }';
493
- results.push(pk7.gqlQuery(query));
494
- }
495
-
496
- results = await Promise.all(results);
497
- let i = 0;
498
-
499
- for (let result of results) {
500
- t.equal(result.errors, undefined);
501
- const blockEntriesWithContent = [...result.data.documents[0].mainSequence.blocks.entries()].filter(be => be[1].tokens.length > 0);
502
- const matches = [];
503
-
504
- for (const [blockN, block] of blockEntriesWithContent) {
505
- for (const token of block.tokens) {
506
- matches.push({
507
- block: blockN,
508
- token: token.position,
509
- payload: token.payload,
510
- scopes: token.scopes,
511
- });
512
- }
513
- }
514
-
515
- // console.log(JSON.stringify(matches, null, 2));
516
- t.equal(matches.filter(m => m.payload === 'righteous').length, charClauses[i][1]);
517
- t.equal(matches.filter(m => m.payload === 'upright').length, charClauses[i][2]);
518
- t.equal(matches.length, charClauses[i][3]);
519
- i++;
520
- }
521
-
522
- const query = '{ documents { mainSequence { blocks {' +
523
- `text tokens(includeContext:true ${charClauses[0][0]} ${charClauses[1][0]}) { payload position scopes(startsWith:["chapter/", "verses/"]) }` +
524
- '} } } }';
525
- let result = await pk7.gqlQuery(query);
526
- t.notEqual(result.errors, undefined);
527
- t.ok(result.errors[0].message.includes('Only one of'));
528
- } catch (err) {
529
- console.log(err);
530
- }
531
- },
532
- );
533
-
534
- test(
535
- `ItemGroups (${testGroup})`,
536
- async function (t) {
537
- try {
538
- t.plan(5);
539
- const query = `{documents {
540
- mainSequence {
541
- blocks(positions:0) {
542
- itemGroups(byScopes:["chapter/", "verse/"]) {
543
- scopeLabels(startsWith:["chapter/", "verse/"])
544
- text
545
- }
546
- }
547
- }
548
- } }`;
549
- let result = await pk3.gqlQuery(query);
550
- t.equal(result.errors, undefined);
551
- const groups = result.data.documents[0].mainSequence.blocks[0].itemGroups;
552
- t.equal(groups.length, 9);
553
- t.ok(groups[2].scopeLabels.includes('chapter/1'));
554
- t.ok(groups[2].scopeLabels.includes('verse/3'));
555
- t.ok(groups[2].text.startsWith('Elimelech'));
556
- } catch (err) {
557
- console.log(err);
558
- }
559
- },
560
- );
561
-
562
- test(
563
- `ItemGroups with multiple hits per block (${testGroup})`,
564
- async function (t) {
565
- try {
566
- t.plan(4);
567
- const query = '{ documents { mainSequence { blocks { itemGroups(byScopes:"span/add") {' +
568
- 'scopeLabels(startsWith:["chapter/", "verses/"]) text' +
569
- '} } } } }';
570
- let result = await pk8.gqlQuery(query);
571
- t.equal(result.errors, undefined);
572
- t.equal(result.data.documents[0].mainSequence.blocks[0].itemGroups.length, 2);
573
- t.equal(
574
- result.data.documents[0].mainSequence.blocks[0].itemGroups[0].text,
575
- 'Actually, one was Yahweh, and the other two were angels',
576
- );
577
- t.equal(
578
- result.data.documents[0].mainSequence.blocks[0].itemGroups[1].text,
579
- 'to one of them',
580
- );
581
- // console.log(JSON.stringify(result.data.documents[0].mainSequence.itemGroups, null, 2))
582
- } catch (err) {
583
- console.log(err);
584
- }
585
- },
586
- );
@@ -1,31 +0,0 @@
1
- const test = require('tape');
2
-
3
- const { pkWithDoc } = require('../../lib/load.js');
4
-
5
- const testGroup = 'Block Scopes';
6
-
7
- const pk = pkWithDoc('../test_data/usfm/ust_psa.usfm', {
8
- lang: 'fra',
9
- abbr: 'hello',
10
- })[0];
11
-
12
- test(
13
- `Numbers (${testGroup})`,
14
- async function (t) {
15
- try {
16
- const bsScopes = ['q', 'q', 'q2', 'q', 'q2', 'q', 'q2', 'q', 'q2', 'q', 'q2', 'q', 'q'];
17
- t.plan(1 + bsScopes.length);
18
- const query =
19
- '{ documents { mainSequence { blocks { bs { payload } } } } }';
20
- const result = await pk.gqlQuery(query);
21
- t.equal(result.errors, undefined);
22
- const blocks = result.data.documents[0].mainSequence.blocks;
23
-
24
- for (const [n, block] of blocks.entries()) {
25
- t.equal(block.bs.payload, `blockTag/${bsScopes[n]}`);
26
- }
27
- } catch (err) {
28
- console.log(err);
29
- }
30
- },
31
- );