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,189 +0,0 @@
1
- const test = require('tape');
2
-
3
- const { pkWithDoc } = require('../../lib/load.js');
4
-
5
- const testGroup = 'CV Indexes';
6
-
7
- const pk = pkWithDoc('../test_data/usx/web_rut.usx', {
8
- lang: 'eng',
9
- abbr: 'web',
10
- })[0];
11
-
12
- const pk2 = pkWithDoc('../test_data/usfm/web_psa51.usfm', {
13
- lang: 'eng',
14
- abbr: 'web',
15
- })[0];
16
-
17
- const pk3 = pkWithDoc('../test_data/usfm/verse_range.usfm', {
18
- lang: 'eng',
19
- abbr: 'web',
20
- })[0];
21
-
22
- const rangeQuery = 'startBlock startItem endBlock endItem nextToken ' +
23
- 'items { type subType payload } ' +
24
- 'tokens { type subType payload } ' +
25
- 'wordLikes: tokens(withSubTypes:"wordLike") { type subType payload } ' +
26
- 'text normalized: text(normalizeSpace:true) dumpItems';
27
- const cvQuery = `{ chapter verseNumbers { number range } verseRanges { range numbers } verses { verse { ${rangeQuery} verseRange } } }`;
28
- const cQuery = `{ chapter ${rangeQuery} }`;
29
- const cvCharsQuery = `{ chapter verses { verse { tokens(includeContext:true withChars:["Ruth", "Boaz", "Naomi"]) { payload position} text } } }`;
30
-
31
- const checkIndexFields = (t, index) => {
32
- t.ok('startBlock' in index);
33
- t.ok('endBlock' in index);
34
- t.ok('startItem' in index);
35
- t.ok('endItem' in index);
36
- t.ok('nextToken' in index);
37
- t.ok(index.text.length > 0);
38
- t.ok(index.items.length > 0);
39
- t.ok(index.tokens.length > 0);
40
- t.ok(index.wordLikes.length > 0);
41
- t.ok(index.dumpItems.length > 0);
42
- };
43
-
44
- test(
45
- `cvIndexes (${testGroup})`,
46
- async function (t) {
47
- try {
48
- t.plan(1 + 10);
49
- const query =
50
- `{ documents { cvIndexes ${cvQuery} } }`;
51
- const result = await pk.gqlQuery(query);
52
- t.equal(result.errors, undefined);
53
- const index = result.data.documents[0].cvIndexes[0];
54
- checkIndexFields(t, index.verses[1].verse[0]);
55
- } catch (err) {
56
- console.log(err);
57
- }
58
- },
59
- );
60
-
61
- test(
62
- `cIndexes (${testGroup})`,
63
- async function (t) {
64
- try {
65
- t.plan(1 + 10);
66
- const query =
67
- `{ documents { cIndexes ${cQuery} } }`;
68
- const result = await pk.gqlQuery(query);
69
- t.equal(result.errors, undefined);
70
- const index = result.data.documents[0].cIndexes[0];
71
- checkIndexFields(t, index);
72
- // console.log(JSON.stringify(result.data.documents[0].cIndexes, null, 2));
73
- } catch (err) {
74
- console.log(err);
75
- }
76
- },
77
- );
78
-
79
- test(
80
- `cvIndex (${testGroup})`,
81
- async function (t) {
82
- try {
83
- t.plan(2 + 10 + 6);
84
- let query =
85
- `{ documents { cvIndex(chapter:3) ${cvQuery} } }`;
86
- let result = await pk.gqlQuery(query);
87
- t.equal(result.errors, undefined);
88
- let index = result.data.documents[0].cvIndex;
89
- t.equal(index.chapter, 3);
90
- checkIndexFields(t, index.verses[1].verse[0]);
91
- const verseNumbers = result.data.documents[0].cvIndex.verseNumbers;
92
- t.equal(verseNumbers.length, 18);
93
- t.equal(Math.max(...verseNumbers.map(n => n.number)), 18);
94
- t.equal(Math.min(...verseNumbers.map(n => n.number)), 1);
95
- query =
96
- `{ documents { cvIndex(chapter:9) ${cvQuery} } }`;
97
- result = await pk.gqlQuery(query);
98
- t.equal(result.errors, undefined);
99
- index = result.data.documents[0].cvIndex;
100
- t.equal(index.chapter, 9);
101
- t.equal(index.verses.length, 0);
102
- } catch (err) {
103
- console.log(err);
104
- }
105
- },
106
- );
107
-
108
- test(
109
- `cvIndex v0 (${testGroup})`,
110
- async function (t) {
111
- try {
112
- t.plan(4);
113
- let query =
114
- `{ documents { cvIndex(chapter:51) ${cvQuery} } }`;
115
- let result = await pk2.gqlQuery(query);
116
- t.equal(result.errors, undefined);
117
- const verseNumbers = result.data.documents[0].cvIndex.verseNumbers;
118
- t.equal(verseNumbers.length, 20);
119
- t.equal(Math.max(...verseNumbers.map(n => n.number)), 19);
120
- t.equal(Math.min(...verseNumbers.map(n => n.number)), 0);
121
- // console.log(JSON.stringify(result.data.documents[0].cvIndex.verses.map(v => v.verse[0].dumpItems), null, 2));
122
- } catch (err) {
123
- console.log(err);
124
- }
125
- },
126
- );
127
-
128
- test(
129
- `cvIndex verseRanges (${testGroup})`,
130
- async function (t) {
131
- try {
132
- t.plan(6);
133
- let query =
134
- `{ documents { cvIndex(chapter:1) ${cvQuery} } }`;
135
- let result = await pk3.gqlQuery(query);
136
- t.equal(result.errors, undefined);
137
- // console.log(JSON.stringify(result.data.documents[0].cvIndex.verseRanges, null, 2));
138
- const verseRanges = result.data.documents[0].cvIndex.verseRanges;
139
- t.equal(verseRanges.length, 1);
140
- t.equal(verseRanges[0].range, '1-2');
141
- t.equal(verseRanges[0].numbers.length, 2);
142
- t.equal(verseRanges[0].numbers[0], 1);
143
- t.equal(verseRanges[0].numbers[1], 2);
144
- } catch (err) {
145
- console.log(err);
146
- }
147
- },
148
- );
149
-
150
- test(
151
- `cIndex (${testGroup})`,
152
- async function (t) {
153
- try {
154
- t.plan(2 + 10 + 3);
155
- let query =
156
- `{ documents { cIndex(chapter:3) ${cQuery} } }`;
157
- let result = await pk.gqlQuery(query);
158
- t.equal(result.errors, undefined);
159
- let index = result.data.documents[0].cIndex;
160
- t.equal(index.chapter, 3);
161
- checkIndexFields(t, index);
162
- query =
163
- `{ documents { cIndex(chapter:9) ${cQuery} } }`;
164
- result = await pk.gqlQuery(query);
165
- t.equal(result.errors, undefined);
166
- index = result.data.documents[0].cIndex;
167
- t.equal(index.chapter, 9);
168
- t.equal(index.startBlock, null);
169
- } catch (err) {
170
- console.log(err);
171
- }
172
- },
173
- );
174
-
175
- test(
176
- `cvIndexes withChars (${testGroup})`,
177
- async function (t) {
178
- try {
179
- t.plan(1);
180
- let query =
181
- `{ documents { cvIndexes ${cvCharsQuery} } }`;
182
- let result = await pk.gqlQuery(query);
183
- t.equal(result.errors, undefined);
184
- // console.log(JSON.stringify(result.data, null, 2));
185
- } catch (err) {
186
- console.log(err);
187
- }
188
- },
189
- );
@@ -1,124 +0,0 @@
1
- /* eslint-disable no-await-in-loop */
2
- const test = require('tape');
3
-
4
- const { pkWithDoc } = require('../../lib/load.js');
5
-
6
- const testGroup = 'cv Navigation';
7
-
8
- const pk = pkWithDoc('../test_data/usx/web_rut.usx', {
9
- lang: 'eng',
10
- abbr: 'web',
11
- })[0];
12
-
13
- const pk2 = pkWithDoc('../test_data/usx/web_psa_40_60.usx', {
14
- lang: 'eng',
15
- abbr: 'web',
16
- })[0];
17
-
18
- const pk3 = pkWithDoc('../test_data/usfm/ust_psa_verse_ranges.usfm', {
19
- lang: 'eng',
20
- abbr: 'ust',
21
- })[0];
22
-
23
- test(
24
- `Next/Previous Chapter (${testGroup})`,
25
- async function (t) {
26
- try {
27
- const expected = [
28
- ['2', '1', '3'],
29
- ['1', null, '2'],
30
- ['4', '3', null],
31
- ['5', null, null],
32
- ];
33
- t.plan(3 * expected.length);
34
-
35
- for (const [chap, prev, next] of expected) {
36
- const query =
37
- '{ documents { nav: cvNavigation(chapter:"%c%" verse:"3") { previousChapter nextChapter } } }'
38
- .replace('%c%', chap);
39
- const result = await pk.gqlQuery(query);
40
- t.equal(result.errors, undefined);
41
- const nav = result.data.documents[0].nav;
42
- t.equal(nav.previousChapter, prev);
43
- t.equal(nav.nextChapter, next);
44
- }
45
- } catch (err) {
46
- console.log(err);
47
- }
48
- },
49
- );
50
-
51
- test(
52
- `Next/Previous Verse (${testGroup})`,
53
- async function (t) {
54
- try {
55
- const expected = [
56
- [pk, 2, 3, 2, 2, 2, 4],
57
- [pk, 1, 22, 1, 21, 2, 1],
58
- [pk, 2, 1, 1, 22, 2, 2],
59
- [pk, 1, 1, null, null, 1, 2],
60
- [pk, 5, 1, null, null, null, null],
61
- [pk, 1, 0, null, null, null, null],
62
- [pk, 1, 50, null, null, null, null],
63
- [pk2, 50, 23, 50, 22, 51, 0],
64
- [pk2, 51, 1, 51, 0, 51, 2],
65
- [pk2, 51, 0, 50, 23, 51, 1],
66
- ];
67
- t.plan(5 * expected.length);
68
-
69
- for (const [pros, chap, verse, prevChap, prevVerse, nextChap, nextVerse] of expected) {
70
- const query =
71
- '{ documents { nav: cvNavigation(chapter:"%c%" verse:"%v%") { previousVerse { chapter verse } nextVerse { chapter verse } } } }'
72
- .replace('%c%', chap)
73
- .replace('%v%', verse);
74
- const result = await pros.gqlQuery(query);
75
- t.equal(result.errors, undefined);
76
- const nav = result.data.documents[0].nav;
77
- t.equal(nav.nextVerse && nav.nextVerse.chapter, nextChap);
78
- t.equal(nav.nextVerse && nav.nextVerse.verse, nextVerse);
79
- t.equal(nav.previousVerse && nav.previousVerse.chapter, prevChap);
80
- t.equal(nav.previousVerse && nav.previousVerse.verse, prevVerse);
81
- }
82
- } catch (err) {
83
- console.log(err);
84
- }
85
- },
86
- );
87
-
88
- test(
89
- `Next/Previous VerseRangeVerse (${testGroup})`,
90
- async function (t) {
91
- try {
92
- const expected = [
93
- [pk, 2, 3, 2, 2, 2, 4],
94
- [pk, 1, 22, 1, 21, 2, 1],
95
- [pk, 2, 1, 1, 22, 2, 2],
96
- [pk, 1, 1, null, null, 1, 2],
97
- [pk, 5, 1, null, null, null, null],
98
- [pk, 1, 0, null, null, null, null],
99
- [pk, 1, 50, null, null, null, null],
100
- [pk2, 50, 23, 50, 22, 51, 0],
101
- [pk2, 51, 1, 51, 0, 51, 2],
102
- [pk2, 51, 0, 50, 23, 51, 1],
103
- [pk3, 150, 4, 150, 2, 150, 6],
104
- ];
105
- t.plan(5 * expected.length);
106
-
107
- for (const [pros, chap, verse, prevChap, prevVerse, nextChap, nextVerse] of expected) {
108
- const query =
109
- '{ documents { nav: cvNavigation(chapter:"%c%" verse:"%v%") { previousVerseRangeVerse { chapter verse } nextVerseRangeVerse { chapter verse } } } }'
110
- .replace('%c%', chap)
111
- .replace('%v%', verse);
112
- const result = await pros.gqlQuery(query);
113
- t.equal(result.errors, undefined);
114
- const nav = result.data.documents[0].nav;
115
- t.equal(nav.nextVerseRangeVerse && nav.nextVerseRangeVerse.chapter, nextChap);
116
- t.equal(nav.nextVerseRangeVerse && nav.nextVerseRangeVerse.verse, nextVerse);
117
- t.equal(nav.previousVerseRangeVerse && nav.previousVerseRangeVerse.chapter, prevChap);
118
- t.equal(nav.previousVerseRangeVerse && nav.previousVerseRangeVerse.verse, prevVerse);
119
- }
120
- } catch (err) {
121
- console.log(err);
122
- }
123
- },
124
- );
@@ -1,382 +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 { Proskomma } = require('../../../src/index.cjs');
7
-
8
- const { pkWithDoc } = require('../../lib/load.js');
9
-
10
- const testGroup = 'Graph Document';
11
-
12
- const pk = pkWithDoc('../test_data/usx/web_rut.usx', {
13
- lang: 'eng',
14
- abbr: 'web',
15
- })[0];
16
-
17
- const pk2 = new Proskomma();
18
- const fp = '../../test_data/usfm/int.usfm';
19
- const content = fse.readFileSync(path.resolve(__dirname, fp));
20
-
21
- pk2.importUsfmPeriph(
22
- { lang: 'eng', abbr: 'abc' },
23
- content,
24
- {},
25
- );
26
-
27
- const pk3 = pkWithDoc('../test_data/usfm/78-GALspavbl.usfm', {
28
- lang: 'spa',
29
- abbr: 'vbl',
30
- })[0];
31
-
32
- test(
33
- `DocSetId (${testGroup})`,
34
- async function (t) {
35
- try {
36
- t.plan(3);
37
- const query = '{ documents { docSetId } }';
38
- const result = await pk.gqlQuery(query);
39
- t.equal(result.errors, undefined);
40
- t.ok('documents' in result.data);
41
- t.ok('docSetId' in result.data.documents[0]);
42
- } catch
43
- (err) {
44
- console.log(err);
45
- }
46
- },
47
- );
48
-
49
- test(
50
- `Headers (${testGroup})`,
51
- async function (t) {
52
- try {
53
- t.plan(6);
54
- const query = '{ documents { headers { key value } toc: header(id:"toc") } }';
55
- const result = await pk.gqlQuery(query);
56
- t.equal(result.errors, undefined);
57
- t.ok('documents' in result.data);
58
- t.ok('headers' in result.data.documents[0]);
59
- t.equal(result.data.documents[0].headers.length, 7);
60
- t.equal(result.data.documents[0].headers.filter(h => h.key === 'toc')[0].value, 'The Book of Ruth');
61
- t.equal(result.data.documents[0].toc, 'The Book of Ruth');
62
- } catch
63
- (err) {
64
- console.log(err);
65
- }
66
- },
67
- );
68
-
69
- test(
70
- `Headers with accents (${testGroup})`,
71
- async function (t) {
72
- try {
73
- t.plan(6);
74
- const query = '{ documents { headers { key value } toc: header(id:"toc") } }';
75
- const result = await pk3.gqlQuery(query);
76
- t.equal(result.errors, undefined);
77
- t.ok('documents' in result.data);
78
- t.ok('headers' in result.data.documents[0]);
79
- t.equal(result.data.documents[0].headers.length, 5);
80
- t.equal(result.data.documents[0].headers.filter(h => h.key === 'toc')[0].value, 'Gálatas');
81
- t.equal(result.data.documents[0].toc, 'Gálatas');
82
- } catch (err) {
83
- console.log(err);
84
- }
85
- },
86
- );
87
-
88
- test(
89
- `ID Parts (${testGroup})`,
90
- async function (t) {
91
- try {
92
- t.plan(14);
93
- const query = '{ documents { idParts { type parts part(index:0) nullPart: part(index:9) } } }';
94
- let result = await pk.gqlQuery(query);
95
- t.equal(result.errors, undefined);
96
- let idParts = result.data.documents[0].idParts;
97
- t.equal(idParts.type, 'book');
98
- t.equal(idParts.parts.length, 2);
99
- t.equal(idParts.parts[0], 'RUT');
100
- t.equal(idParts.part, 'RUT');
101
- t.ok(!idParts.nullPart);
102
- result = await pk2.gqlQuery(query);
103
- t.equal(result.errors, undefined);
104
- idParts = result.data.documents[0].idParts;
105
- t.equal(idParts.type, 'periph');
106
- t.equal(idParts.parts.length, 4);
107
- t.equal(idParts.parts[0], 'P00');
108
- t.equal(idParts.parts[1], 'INT');
109
- t.equal(idParts.parts[2], 'intbible');
110
- t.equal(idParts.part, 'P00');
111
- t.ok(!idParts.nullPart);
112
- } catch (err) {
113
- console.log(err);
114
- }
115
- },
116
- );
117
-
118
- test(
119
- `mainSequence (${testGroup})`,
120
- async function (t) {
121
- try {
122
- t.plan(4);
123
- const query = '{ documents { mainSequence { id } } }';
124
- const result = await pk.gqlQuery(query);
125
- t.equal(result.errors, undefined);
126
- t.ok('documents' in result.data);
127
- t.ok('mainSequence' in result.data.documents[0]);
128
- t.ok('id' in result.data.documents[0].mainSequence);
129
- } catch
130
- (err) {
131
- console.log(err);
132
- }
133
- },
134
- );
135
-
136
- test(
137
- `Sequences (${testGroup})`,
138
- async function (t) {
139
- try {
140
- t.plan(4);
141
- const query = '{ documents { sequences { id } } }';
142
- const result = await pk.gqlQuery(query);
143
- t.equal(result.errors, undefined);
144
- t.ok('documents' in result.data);
145
- t.ok('sequences' in result.data.documents[0]);
146
- t.ok('id' in result.data.documents[0].sequences[0]);
147
- } catch (err) {
148
- console.log(err);
149
- }
150
- },
151
- );
152
-
153
- test(
154
- `Sequences by type and ids (${testGroup})`,
155
- async function (t) {
156
- try {
157
- t.plan(11);
158
- let query = '{ documents { sequences(types:"main") { id type } } }';
159
- let result = await pk.gqlQuery(query);
160
- t.equal(result.errors, undefined);
161
- t.ok('documents' in result.data);
162
- t.ok('sequences' in result.data.documents[0]);
163
- t.equal(result.data.documents[0].sequences.length, 1);
164
- const mainSequence = result.data.documents[0].sequences[0];
165
- t.equal(mainSequence.type, 'main');
166
- const mainId = mainSequence.id;
167
- query = `{ documents { sequences(ids:"${mainId}") { id type } } }`;
168
- result = await pk.gqlQuery(query);
169
- t.equal(result.errors, undefined);
170
- t.ok('documents' in result.data);
171
- t.ok('sequences' in result.data.documents[0]);
172
- t.equal(result.data.documents[0].sequences.length, 1);
173
- const foundSequence = result.data.documents[0].sequences[0];
174
- t.equal(foundSequence.id, mainId);
175
- t.equal(foundSequence.type, 'main');
176
- } catch (err) {
177
- console.log(err);
178
- }
179
- },
180
- );
181
-
182
- test(
183
- `Sequence (${testGroup})`,
184
- async function (t) {
185
- try {
186
- t.plan(10);
187
- let query = '{ documents { mainSequence { id } } }';
188
- let result = await pk.gqlQuery(query);
189
- t.equal(result.errors, undefined);
190
- const mainId = result.data.documents[0].mainSequence.id;
191
- query = `{ documents { sequence(id:"${mainId}") { id type } } }`;
192
- result = await pk.gqlQuery(query);
193
- t.equal(result.errors, undefined);
194
- t.ok('documents' in result.data);
195
- t.ok('sequence' in result.data.documents[0]);
196
- const foundSequence = result.data.documents[0].sequence;
197
- t.equal(foundSequence.id, mainId);
198
- t.equal(foundSequence.type, 'main');
199
- query = `{ documents { sequence(id:"banana") { id type } } }`;
200
- result = await pk.gqlQuery(query);
201
- t.equal(result.errors, undefined);
202
- t.ok('documents' in result.data);
203
- t.ok('sequence' in result.data.documents[0]);
204
- t.equal(result.data.documents[0].sequence, null);
205
- } catch (err) {
206
- console.log(err);
207
- }
208
- },
209
- );
210
-
211
- test(
212
- `mainBlocks (${testGroup})`,
213
- async function (t) {
214
- try {
215
- t.plan(4);
216
- const query = '{ documents { mainBlocks { text } } }';
217
- const result = await pk.gqlQuery(query);
218
- t.equal(result.errors, undefined);
219
- t.ok('documents' in result.data);
220
- t.ok('mainBlocks' in result.data.documents[0]);
221
- t.ok(result.data.documents[0].mainBlocks[0].text.startsWith('In the days when'));
222
- } catch (err) {
223
- console.log(err);
224
- }
225
- },
226
- );
227
-
228
- test(
229
- `mainBlocksText (${testGroup})`,
230
- async function (t) {
231
- try {
232
- t.plan(5);
233
- const query = '{ documents { mainBlocksText normalized: mainBlocksText(normalizeSpace:true) } }';
234
- const result = await pk.gqlQuery(query);
235
- t.equal(result.errors, undefined);
236
- t.ok('documents' in result.data);
237
- t.ok('mainBlocksText' in result.data.documents[0]);
238
- t.ok(result.data.documents[0].mainBlocksText[0].startsWith('In the days when'));
239
- t.ok(result.data.documents[0].normalized[0].startsWith('In the days when'));
240
- } catch (err) {
241
- console.log(err);
242
- }
243
- },
244
- );
245
-
246
- test(
247
- `mainBlocksItems (${testGroup})`,
248
- async function (t) {
249
- try {
250
- t.plan(7);
251
- const query = '{ documents { mainBlocksItems { type subType payload } } }';
252
- const result = await pk.gqlQuery(query);
253
- t.equal(result.errors, undefined);
254
- t.ok('documents' in result.data);
255
- t.ok('mainBlocksItems' in result.data.documents[0]);
256
- t.equal(result.data.documents[0].mainBlocksItems[0][0].payload, 'chapter/1');
257
- t.equal(result.data.documents[0].mainBlocksItems[0][1].payload, 'verse/1');
258
- t.equal(result.data.documents[0].mainBlocksItems[0][2].payload, 'verses/1');
259
- t.equal(result.data.documents[0].mainBlocksItems[0][3].payload, 'In');
260
- } catch (err) {
261
- console.log(err);
262
- }
263
- },
264
- );
265
-
266
- test(
267
- `mainBlocksTokens (${testGroup})`,
268
- async function (t) {
269
- try {
270
- t.plan(4);
271
- const query = '{ documents { mainBlocksTokens { type subType payload } } }';
272
- const result = await pk.gqlQuery(query);
273
- t.equal(result.errors, undefined);
274
- t.ok('documents' in result.data);
275
- t.ok('mainBlocksTokens' in result.data.documents[0]);
276
- t.equal(result.data.documents[0].mainBlocksTokens[0][0].payload, 'In');
277
- } catch (err) {
278
- console.log(err);
279
- }
280
- },
281
- );
282
-
283
- test(
284
- `mainText (${testGroup})`,
285
- async function (t) {
286
- try {
287
- t.plan(5);
288
- const query = '{ documents { mainText normalized: mainText(normalizeSpace:true) } }';
289
- const result = await pk.gqlQuery(query);
290
- t.equal(result.errors, undefined);
291
- t.ok('documents' in result.data);
292
- t.ok('mainText' in result.data.documents[0]);
293
- t.ok(result.data.documents[0].mainText.startsWith('In the days when'));
294
- t.ok(result.data.documents[0].normalized.startsWith('In the days when'));
295
- } catch (err) {
296
- console.log(err);
297
- }
298
- },
299
- );
300
-
301
- test(
302
- `perf (${testGroup})`,
303
- async function (t) {
304
- try {
305
- t.plan(9);
306
- let query = '{ documents { perf } }';
307
- let result = await pk.gqlQuery(query);
308
- t.equal(result.errors, undefined);
309
- t.ok('documents' in result.data);
310
- t.ok('perf' in result.data.documents[0]);
311
- let perfJSON;
312
- t.doesNotThrow(() => perfJSON = JSON.parse(result.data.documents[0].perf));
313
- query = '{ documents { perf(indent:2) } }';
314
- result = await pk.gqlQuery(query);
315
- t.equal(result.errors, undefined);
316
- t.ok('documents' in result.data);
317
- t.ok('perf' in result.data.documents[0]);
318
- let perfJSON2;
319
- t.doesNotThrow(() => perfJSON2 = JSON.parse(result.data.documents[0].perf));
320
- t.ok(deepEqual(perfJSON, perfJSON2));
321
- } catch (err) {
322
- console.log(err);
323
- }
324
- },
325
- );
326
-
327
- test(
328
- `sofria (${testGroup})`,
329
- async function (t) {
330
- try {
331
- t.plan(9);
332
- let query = '{ documents { sofria } }';
333
- let result = await pk3.gqlQuery(query);
334
- t.equal(result.errors, undefined);
335
- t.ok('documents' in result.data);
336
- t.ok('sofria' in result.data.documents[0]);
337
- let sofriaJSON;
338
- t.doesNotThrow(() => sofriaJSON = JSON.parse(result.data.documents[0].sofria));
339
- query = '{ documents { sofria(indent:2) } }';
340
- result = await pk3.gqlQuery(query);
341
- t.equal(result.errors, undefined);
342
- t.ok('documents' in result.data);
343
- t.ok('sofria' in result.data.documents[0]);
344
- let sofriaJSON2;
345
- t.doesNotThrow(() => sofriaJSON2 = JSON.parse(result.data.documents[0].sofria));
346
- t.ok(deepEqual(sofriaJSON, sofriaJSON2));
347
- } catch (err) {
348
- console.log(err);
349
- }
350
- },
351
- );
352
-
353
- test(
354
- `usfm (${testGroup})`,
355
- async function (t) {
356
- try {
357
- t.plan(4);
358
- let query = '{ documents { usfm } }';
359
- let result = await pk3.gqlQuery(query);
360
- t.equal(result.errors, undefined);
361
- t.ok('documents' in result.data);
362
- t.ok('usfm' in result.data.documents[0]);
363
-
364
- let rawUsfm = fse.readFileSync(path.resolve(__dirname, '../../test_data/usfm/78-GALspavbl.usfm')).toString();
365
- let tabRawUsfm = rawUsfm.split(/(\\[a-z]+[\d\*]?|\n)/g).filter((e) => e !== '' && e !== ' ' && e !== '\n');
366
-
367
- let outputUsfm = result.data.documents[0].usfm;
368
- let tabOutputUsfm = outputUsfm.split(/(\\[a-z]+[\d\*]?|\n)/g).filter((e) => e !== '' && e !== ' ' && e !== '\n');
369
-
370
- let diff = [];
371
-
372
- tabRawUsfm.forEach((elem, i) => {
373
- if (!tabOutputUsfm[i] || elem.trim() !== tabOutputUsfm[i].trim()) {
374
- diff.push([tabOutputUsfm[i], elem]);
375
- }
376
- });
377
- t.equal(diff.join(''), '');
378
- } catch (err) {
379
- console.log(err);
380
- }
381
- },
382
- );