extwee 2.0.6 → 2.2.0
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.
- package/.eslintrc.json +25 -25
- package/.github/FUNDING.yml +3 -0
- package/.github/dependabot.yml +11 -0
- package/.github/workflows/nodejs.yml +25 -24
- package/.travis.yml +13 -13
- package/CODE_OF_CONDUCT.md +82 -82
- package/LICENSE +21 -21
- package/README.md +173 -36
- package/SECURITY.md +12 -12
- package/babel.config.json +18 -22
- package/build/extwee +0 -0
- package/build/extwee.exe +0 -0
- package/build/extwee.web.min.js +2 -0
- package/build/extwee.web.min.js.LICENSE.txt +1 -0
- package/docs/.nojekyll +0 -0
- package/docs/README.md +167 -0
- package/docs/_sidebar.md +19 -0
- package/docs/examples/dynamicPassages.md +28 -0
- package/docs/examples/jsonToTwee.md +23 -0
- package/docs/examples/twsToTwee.md +25 -0
- package/docs/formats/json.md +17 -0
- package/docs/formats/twee.md +13 -0
- package/docs/formats/twine1HTML.md +13 -0
- package/docs/formats/twine2ArchiveHTML.md +13 -0
- package/docs/formats/twine2HTML.md +13 -0
- package/docs/formats/tws.md +9 -0
- package/docs/index.html +26 -0
- package/docs/install/binaries.md +9 -0
- package/docs/install/npm.md +20 -0
- package/docs/install/npx.md +9 -0
- package/docs/objects/passage.md +47 -0
- package/docs/objects/story.md +70 -0
- package/docs/objects/storyformat.md +27 -0
- package/index.html +22 -0
- package/index.js +29 -31
- package/package.json +65 -58
- package/src/JSON/parse.js +128 -0
- package/src/Passage.js +298 -202
- package/src/Story.js +650 -523
- package/src/StoryFormat/parse.js +134 -0
- package/src/StoryFormat.js +259 -300
- package/src/TWS/parse.js +86 -0
- package/src/Twee/parse.js +157 -0
- package/src/Twine1HTML/compile.js +58 -0
- package/src/Twine1HTML/parse.js +134 -0
- package/src/Twine2ArchiveHTML/compile.js +36 -0
- package/src/Twine2ArchiveHTML/parse.js +49 -0
- package/src/Twine2HTML/compile.js +35 -0
- package/src/Twine2HTML/parse.js +348 -0
- package/src/extwee.js +206 -0
- package/test/CLI/CLI.test.js +49 -0
- package/test/CLI/files/example.json +1 -0
- package/test/CLI/files/example6.twee +22 -0
- package/test/{Roundtrip → CLI/files}/harlowe.js +2 -2
- package/test/CLI/{input.html → files/input.html} +47 -47
- package/test/CLI/files/output/test.twee +0 -0
- package/test/CLI/{tweeExample.twee → files/tweeExample.twee} +17 -17
- package/test/CLI/files/twine1/LICENSE.txt +32 -0
- package/test/CLI/files/twine1/code.js +5 -0
- package/test/CLI/files/twine1/engine.js +43 -0
- package/test/CLI/files/twine1/header.html +325 -0
- package/test/CLI/files/twine1Test.html +371 -0
- package/test/CLI/{twineExample.html → files/twineExample.html} +16 -15
- package/test/JSON/JSON.Parse.test.js +316 -0
- package/test/Passage.test.js +175 -104
- package/test/Roundtrip/{Example1.html → Files/Example1.html} +63 -63
- package/test/Roundtrip/Files/LICENSE +19 -0
- package/test/Roundtrip/Files/example1.twee +10 -0
- package/test/Roundtrip/{example2.twee → Files/example2.twee} +27 -18
- package/test/Roundtrip/{example4.twee → Files/example4.twee} +27 -27
- package/test/{StoryFormatParser → Roundtrip/Files}/harlowe.js +2 -2
- package/test/Roundtrip/{round.html → Files/round.html} +6 -4
- package/test/Roundtrip/Roundtrip.test.js +54 -0
- package/test/Story.test.js +638 -423
- package/test/StoryFormat/StoryFormat.Parse.test.js +91 -0
- package/test/{StoryFormatParser → StoryFormat/StoryFormatParser}/example.js +3 -3
- package/test/{StoryFormatParser → StoryFormat/StoryFormatParser}/example2.js +3 -3
- package/test/{CLI → StoryFormat/StoryFormatParser}/harlowe.js +2 -2
- package/test/StoryFormat.test.js +152 -152
- package/test/TWS/Parse.test.js +78 -0
- package/test/TWS/TWSParser/Example1.tws +150 -0
- package/test/TWS/TWSParser/Example5.tws +414 -0
- package/test/TWS/TWSParser/noscale.tws +0 -0
- package/test/TWS/TWSParser/nostory.tws +0 -0
- package/test/Twee/Twee.Parse.test.js +76 -0
- package/test/{TweeParser → Twee/TweeParser}/emptytags.twee +2 -2
- package/test/{TweeParser → Twee/TweeParser}/example.twee +32 -32
- package/test/{TweeParser → Twee/TweeParser}/missing.twee +19 -19
- package/test/{TweeParser → Twee/TweeParser}/multipleScriptPassages.twee +19 -19
- package/test/{TweeParser → Twee/TweeParser}/multipleStyleTag.twee +19 -19
- package/test/{TweeParser → Twee/TweeParser}/multipletags.twee +10 -10
- package/test/{TweeParser → Twee/TweeParser}/noTitle.twee +2 -2
- package/test/{TweeParser → Twee/TweeParser}/notes.twee +16 -16
- package/test/{TweeParser → Twee/TweeParser}/pasagemetadataerror.twee +2 -2
- package/test/{TweeParser → Twee/TweeParser}/scriptPassage.twee +16 -16
- package/test/{TweeParser → Twee/TweeParser}/singletag.twee +13 -13
- package/test/{TweeParser → Twee/TweeParser}/startMetadata.twee +14 -14
- package/test/{TweeParser → Twee/TweeParser}/storydataerror.twee +25 -25
- package/test/{TweeParser → Twee/TweeParser}/stylePassage.twee +16 -16
- package/test/{Story → Twee/TweeParser}/test.twee +25 -25
- package/test/Twine1HTML/Twine1HTML.Compile.test.js +180 -0
- package/test/Twine1HTML/Twine1HTML.Parse.test.js +183 -0
- package/test/Twine1HTML/Twine1HTMLCompiler/Twine1/LICENSE +674 -0
- package/test/Twine1HTML/Twine1HTMLCompiler/Twine1/engine.js +43 -0
- package/test/Twine1HTML/Twine1HTMLCompiler/Twine1/jquery.js +4 -0
- package/test/Twine1HTML/Twine1HTMLCompiler/Twine1/modernizr.js +4 -0
- package/test/Twine1HTML/Twine1HTMLCompiler/engineTest.html +1 -0
- package/test/Twine1HTML/Twine1HTMLCompiler/jonah-1.4.2/LICENSE +32 -0
- package/test/Twine1HTML/Twine1HTMLCompiler/jonah-1.4.2/code.js +4 -0
- package/test/Twine1HTML/Twine1HTMLCompiler/jonah-1.4.2/header.html +327 -0
- package/test/Twine1HTML/Twine1HTMLCompiler/test.html +0 -0
- package/test/Twine1HTML/Twine1HTMLCompiler/test1.html +6 -0
- package/test/Twine1HTML/Twine1HTMLCompiler/test2.html +6 -0
- package/test/Twine1HTML/Twine1HTMLCompiler/test3.html +43 -0
- package/test/Twine1HTML/Twine1HTMLCompiler/test4.html +372 -0
- package/test/Twine1HTML/Twine1HTMLCompiler/test5.html +372 -0
- package/test/Twine2ArchiveHTML/Twine2ArchiveHTML.Compile.test.js +35 -0
- package/test/Twine2ArchiveHTML/Twine2ArchiveHTML.Parse.test.js +25 -0
- package/test/Twine2ArchiveHTML/Twine2ArchiveHTMLCompiler/test1.html +6 -0
- package/test/Twine2ArchiveHTML/Twine2ArchiveHTMLParser/test1.html +3 -0
- package/test/Twine2HTML/Twine2HTML.Compile.test.js +224 -0
- package/test/Twine2HTML/Twine2HTML.Parse.test.js +172 -0
- package/test/{HTMLWriter → Twine2HTML/Twine2HTMLCompiler}/creator.html +4 -4
- package/test/{CLI → Twine2HTML/Twine2HTMLCompiler}/example6.twee +15 -15
- package/test/{HTMLWriter → Twine2HTML/Twine2HTMLCompiler}/missingStoryTitle.twee +29 -29
- package/test/{HTMLWriter → Twine2HTML/Twine2HTMLCompiler}/test2.html +10 -8
- package/test/{HTMLWriter → Twine2HTML/Twine2HTMLCompiler}/test3.html +1 -1
- package/test/{HTMLWriter → Twine2HTML/Twine2HTMLCompiler}/test4.html +4 -4
- package/test/{HTMLParser → Twine2HTML/Twine2HTMLParser}/Example1.html +52 -52
- package/test/{HTMLParser → Twine2HTML/Twine2HTMLParser}/Tags.html +15 -15
- package/test/{HTMLParser → Twine2HTML/Twine2HTMLParser}/lyingStartnode.html +15 -15
- package/test/{HTMLParser → Twine2HTML/Twine2HTMLParser}/lyingTagColors.html +48 -48
- package/test/{HTMLParser → Twine2HTML/Twine2HTMLParser}/missingCreator.html +11 -11
- package/test/{HTMLParser → Twine2HTML/Twine2HTMLParser}/missingCreatorVersion.html +11 -11
- package/test/{HTMLParser → Twine2HTML/Twine2HTMLParser}/missingFormat.html +11 -11
- package/test/{HTMLParser → Twine2HTML/Twine2HTMLParser}/missingFormatVersion.html +11 -11
- package/test/{HTMLParser → Twine2HTML/Twine2HTMLParser}/missingIFID.html +11 -11
- package/test/{HTMLParser → Twine2HTML/Twine2HTMLParser}/missingName.html +33 -33
- package/test/{HTMLParser → Twine2HTML/Twine2HTMLParser}/missingPID.html +15 -15
- package/test/{HTMLParser → Twine2HTML/Twine2HTMLParser}/missingPassageName.html +15 -15
- package/test/{HTMLParser → Twine2HTML/Twine2HTMLParser}/missingPassageTags.html +15 -15
- package/test/{HTMLParser → Twine2HTML/Twine2HTMLParser}/missingPosition.html +15 -15
- package/test/{HTMLParser → Twine2HTML/Twine2HTMLParser}/missingScript.html +14 -14
- package/test/{HTMLParser → Twine2HTML/Twine2HTMLParser}/missingSize.html +35 -35
- package/test/{HTMLParser → Twine2HTML/Twine2HTMLParser}/missingStartnode.html +11 -11
- package/test/{HTMLParser → Twine2HTML/Twine2HTMLParser}/missingStyle.html +14 -14
- package/test/{HTMLParser → Twine2HTML/Twine2HTMLParser}/missingZoom.html +11 -11
- package/test/{HTMLParser → Twine2HTML/Twine2HTMLParser}/twineExample.html +23 -23
- package/test/{HTMLParser → Twine2HTML/Twine2HTMLParser}/twineExample2.html +15 -15
- package/test/{HTMLParser → Twine2HTML/Twine2HTMLParser}/twineExample3.html +15 -15
- package/web-index.js +29 -0
- package/webpack.config.js +12 -0
- package/bin/extwee.js +0 -47
- package/src/FileReader.js +0 -33
- package/src/HTMLParser.js +0 -345
- package/src/HTMLWriter.js +0 -231
- package/src/StoryFormatParser.js +0 -142
- package/src/TweeParser.js +0 -161
- package/src/TweeWriter.js +0 -121
- package/story-formats/chapbook-1.2.0/format.js +0 -1
- package/story-formats/chapbook-1.2.0/logo.svg +0 -1
- package/story-formats/harlowe-1.2.4/format.js +0 -1
- package/story-formats/harlowe-1.2.4/icon.svg +0 -78
- package/story-formats/harlowe-2.1.0/format.js +0 -2
- package/story-formats/harlowe-2.1.0/icon.svg +0 -78
- package/story-formats/harlowe-3.1.0/format.js +0 -3
- package/story-formats/harlowe-3.1.0/icon.svg +0 -78
- package/story-formats/paperthin-1.0.0/format.js +0 -1
- package/story-formats/paperthin-1.0.0/icon.svg +0 -5
- package/story-formats/snowman-1.4.0/format.js +0 -1
- package/story-formats/snowman-1.4.0/icon.svg +0 -436
- package/story-formats/snowman-2.0.2/format.js +0 -1
- package/story-formats/snowman-2.0.2/icon.svg +0 -436
- package/story-formats/sugarcube-1.0.35/LICENSE +0 -23
- package/story-formats/sugarcube-1.0.35/format.js +0 -1
- package/story-formats/sugarcube-1.0.35/icon.svg +0 -56
- package/story-formats/sugarcube-2.31.1/LICENSE +0 -22
- package/story-formats/sugarcube-2.31.1/format.js +0 -1
- package/story-formats/sugarcube-2.31.1/icon.svg +0 -56
- package/test/CLI/test2.html +0 -45
- package/test/CLI.test.js +0 -30
- package/test/FileReader/t1.txt +0 -1
- package/test/FileReader.test.js +0 -14
- package/test/HTMLParser.test.js +0 -177
- package/test/HTMLWriter/example6.twee +0 -16
- package/test/HTMLWriter.test.js +0 -287
- package/test/Roundtrip/example1.twee +0 -21
- package/test/Roundtrip.test.js +0 -48
- package/test/Story/startmeta.twee +0 -29
- package/test/StoryFormatParser.test.js +0 -91
- package/test/TweeParser/test.twee +0 -25
- package/test/TweeParser.test.js +0 -79
- package/test/TweeWriter/test1.twee +0 -18
- package/test/TweeWriter/test3.twee +0 -12
- package/test/TweeWriter/test4.twee +0 -14
- package/test/TweeWriter/test5.twee +0 -20
- package/test/TweeWriter/test6.twee +0 -15
- package/test/TweeWriter/test7.twee +0 -15
- package/test/TweeWriter.test.js +0 -107
- /package/test/CLI/{test.twee → files/test.twee} +0 -0
- /package/test/{StoryFormatParser → StoryFormat/StoryFormatParser}/format.js +0 -0
- /package/test/{StoryFormatParser → StoryFormat/StoryFormatParser}/format_doublename.js +0 -0
- /package/test/{StoryFormatParser → StoryFormat/StoryFormatParser}/missingAuthor.js +0 -0
- /package/test/{StoryFormatParser → StoryFormat/StoryFormatParser}/missingDescription.js +0 -0
- /package/test/{StoryFormatParser → StoryFormat/StoryFormatParser}/missingImage.js +0 -0
- /package/test/{StoryFormatParser → StoryFormat/StoryFormatParser}/missingLicense.js +0 -0
- /package/test/{StoryFormatParser → StoryFormat/StoryFormatParser}/missingName.js +0 -0
- /package/test/{StoryFormatParser → StoryFormat/StoryFormatParser}/missingProofing.js +0 -0
- /package/test/{StoryFormatParser → StoryFormat/StoryFormatParser}/missingSource.js +0 -0
- /package/test/{StoryFormatParser → StoryFormat/StoryFormatParser}/missingURL.js +0 -0
- /package/test/{StoryFormatParser → StoryFormat/StoryFormatParser}/missingVersion.js +0 -0
- /package/test/{StoryFormatParser → StoryFormat/StoryFormatParser}/versionWrong.js +0 -0
- /package/test/{HTMLWriter → Twine2HTML/Twine2HTMLCompiler}/TestTags.html +0 -0
- /package/test/{HTMLWriter → Twine2HTML/Twine2HTMLCompiler}/test11.html +0 -0
- /package/test/{HTMLWriter → Twine2HTML/Twine2HTMLCompiler}/test6.html +0 -0
- /package/test/{HTMLParser → Twine2HTML/Twine2HTMLParser}/tagColors.html +0 -0
package/test/Story.test.js
CHANGED
|
@@ -1,423 +1,638 @@
|
|
|
1
|
-
import Story from '../src/Story.js';
|
|
2
|
-
import Passage from '../src/Passage';
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
//
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
});
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
});
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
});
|
|
231
|
-
|
|
232
|
-
it('addPassage() - should
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
});
|
|
237
|
-
|
|
238
|
-
it('addPassage() - should
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
s.addPassage(
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
expect(
|
|
276
|
-
});
|
|
277
|
-
|
|
278
|
-
it('
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
s.
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
const
|
|
317
|
-
s.addPassage(p);
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
s
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
//
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
expect(
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
expect(
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
//
|
|
416
|
-
|
|
417
|
-
// Add a passage
|
|
418
|
-
s.addPassage(
|
|
419
|
-
//
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
});
|
|
1
|
+
import Story from '../src/Story.js';
|
|
2
|
+
import Passage from '../src/Passage';
|
|
3
|
+
import { parse as parseTwee } from '../src/Twee/parse.js';
|
|
4
|
+
import { readFileSync } from 'node:fs';
|
|
5
|
+
|
|
6
|
+
// Pull the name and version of this project from package.json.
|
|
7
|
+
// These are used as the 'creator' and 'creator-version'.
|
|
8
|
+
const { name, version } = JSON.parse(readFileSync('package.json'));
|
|
9
|
+
|
|
10
|
+
describe('Story', () => {
|
|
11
|
+
describe('constructor()', () => {
|
|
12
|
+
let s = null;
|
|
13
|
+
|
|
14
|
+
beforeEach(() => {
|
|
15
|
+
s = new Story();
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('Should have extwee name', () => {
|
|
19
|
+
expect(s.creator).toBe(name);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it('Should have extwee version', () => {
|
|
23
|
+
expect(s.creatorVersion).toBe(version);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('Should have name', () => {
|
|
27
|
+
s = new Story('Test');
|
|
28
|
+
expect(s.name).toBe('Test');
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
describe('creator', () => {
|
|
33
|
+
let s = null;
|
|
34
|
+
|
|
35
|
+
beforeEach(() => {
|
|
36
|
+
s = new Story();
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('Set using String', () => {
|
|
40
|
+
s.creator = 'New';
|
|
41
|
+
expect(s.creator).toBe('New');
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it('Should throw error if not String', () => {
|
|
45
|
+
expect(() => {
|
|
46
|
+
s.creator = 1;
|
|
47
|
+
}).toThrow();
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
describe('creatorVersion', () => {
|
|
52
|
+
let s = null;
|
|
53
|
+
|
|
54
|
+
beforeEach(() => {
|
|
55
|
+
s = new Story();
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('Set using String', () => {
|
|
59
|
+
s.creatorVersion = 'New';
|
|
60
|
+
expect(s.creatorVersion).toBe('New');
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('Should throw error if not String', () => {
|
|
64
|
+
expect(() => {
|
|
65
|
+
s.creatorVersion = 1;
|
|
66
|
+
}).toThrow();
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
describe('IFID', () => {
|
|
71
|
+
let s = null;
|
|
72
|
+
|
|
73
|
+
beforeEach(() => {
|
|
74
|
+
s = new Story();
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it('Set using String', () => {
|
|
78
|
+
s.IFID = 'New';
|
|
79
|
+
expect(s.IFID).toBe('New');
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it('Should throw error if not String', () => {
|
|
83
|
+
expect(() => {
|
|
84
|
+
s.IFID = 1;
|
|
85
|
+
}).toThrow();
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
describe('format', () => {
|
|
90
|
+
let s = null;
|
|
91
|
+
|
|
92
|
+
beforeEach(() => {
|
|
93
|
+
s = new Story();
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it('Set using String', () => {
|
|
97
|
+
s.format = 'New';
|
|
98
|
+
expect(s.format).toBe('New');
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it('Should throw error if not String', () => {
|
|
102
|
+
expect(() => {
|
|
103
|
+
s.format = 1;
|
|
104
|
+
}).toThrow();
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
describe('formatVersion', () => {
|
|
109
|
+
let s = null;
|
|
110
|
+
|
|
111
|
+
beforeEach(() => {
|
|
112
|
+
s = new Story();
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it('Set using String', () => {
|
|
116
|
+
s.formatVersion = '1.1.1';
|
|
117
|
+
expect(s.formatVersion).toBe('1.1.1');
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it('Should throw error if not String', () => {
|
|
121
|
+
expect(() => {
|
|
122
|
+
s.formatVersion = 1;
|
|
123
|
+
}).toThrow();
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
describe('name', () => {
|
|
128
|
+
let s = null;
|
|
129
|
+
|
|
130
|
+
beforeEach(() => {
|
|
131
|
+
s = new Story();
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
it('Set using String', () => {
|
|
135
|
+
s.name = 'New';
|
|
136
|
+
expect(s.name).toBe('New');
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
it('Should throw error if not String', () => {
|
|
140
|
+
expect(() => {
|
|
141
|
+
s.name = 1;
|
|
142
|
+
}).toThrow();
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
describe('zoom', () => {
|
|
147
|
+
let s = null;
|
|
148
|
+
|
|
149
|
+
beforeEach(() => {
|
|
150
|
+
s = new Story();
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
it('Set using Number', () => {
|
|
154
|
+
s.zoom = 1.0;
|
|
155
|
+
expect(s.zoom).not.toBe(0);
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
it('Should throw error if not String', () => {
|
|
159
|
+
expect(() => {
|
|
160
|
+
s.zoom = null;
|
|
161
|
+
}).toThrow();
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
describe('metadata', () => {
|
|
166
|
+
let s = null;
|
|
167
|
+
|
|
168
|
+
beforeEach(() => {
|
|
169
|
+
s = new Story();
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
it('Set metadata', () => {
|
|
173
|
+
s.metadata = {};
|
|
174
|
+
expect(s.metadata).not.toBe(null);
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
it('Should throw error if not object', () => {
|
|
178
|
+
expect(() => {
|
|
179
|
+
s.metadata = 1;
|
|
180
|
+
}).toThrow();
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
describe('start', () => {
|
|
185
|
+
let s = null;
|
|
186
|
+
|
|
187
|
+
beforeEach(() => {
|
|
188
|
+
s = new Story();
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
it('Set start', () => {
|
|
192
|
+
s.start = 'Start';
|
|
193
|
+
expect(s.start).not.toBe('');
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
it('Should throw error if not String', () => {
|
|
197
|
+
expect(() => {
|
|
198
|
+
s.start = 1;
|
|
199
|
+
}).toThrow();
|
|
200
|
+
});
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
describe('tagColors', () => {
|
|
204
|
+
let s = null;
|
|
205
|
+
|
|
206
|
+
beforeEach(() => {
|
|
207
|
+
s = new Story();
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
it('Set tagColors', () => {
|
|
211
|
+
s.tagColors = {
|
|
212
|
+
bar: 'green'
|
|
213
|
+
};
|
|
214
|
+
const count = Object.keys(s.tagColors).length;
|
|
215
|
+
expect(count).toBe(1);
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
it('Should throw error if not object', () => {
|
|
219
|
+
expect(() => {
|
|
220
|
+
s.tagColors = null;
|
|
221
|
+
}).toThrow();
|
|
222
|
+
});
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
describe('addPassage()', () => {
|
|
226
|
+
let s = null;
|
|
227
|
+
|
|
228
|
+
beforeEach(() => {
|
|
229
|
+
s = new Story();
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
it('addPassage() - should increase size', () => {
|
|
233
|
+
const p = new Passage();
|
|
234
|
+
s.addPassage(p);
|
|
235
|
+
expect(s.size()).toBe(1);
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
it('addPassage() - should throw error if non-Passage', () => {
|
|
239
|
+
expect(() => {
|
|
240
|
+
s.addPassage(null);
|
|
241
|
+
}).toThrow();
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
it('addPassage() - should prevent passages with same name being added', () => {
|
|
245
|
+
const p = new Passage('A');
|
|
246
|
+
const p2 = new Passage('A');
|
|
247
|
+
s.addPassage(p);
|
|
248
|
+
s.addPassage(p2);
|
|
249
|
+
expect(s.size()).toBe(1);
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
it('addPassage() - should override StoryData: ifid', function () {
|
|
253
|
+
// Generate object.
|
|
254
|
+
const o = {
|
|
255
|
+
ifid: 'D674C58C-DEFA-4F70-B7A2-27742230C0FC'
|
|
256
|
+
};
|
|
257
|
+
|
|
258
|
+
// Add the passage.
|
|
259
|
+
s.addPassage(new Passage('StoryData', JSON.stringify(o)));
|
|
260
|
+
|
|
261
|
+
// Test for IFID.
|
|
262
|
+
expect(s.IFID).toBe('D674C58C-DEFA-4F70-B7A2-27742230C0FC');
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
it('addPassage() - should override StoryData: format', function () {
|
|
266
|
+
// Generate object.
|
|
267
|
+
const o = {
|
|
268
|
+
format: 'SugarCube'
|
|
269
|
+
};
|
|
270
|
+
|
|
271
|
+
// Add the passage.
|
|
272
|
+
s.addPassage(new Passage('StoryData', JSON.stringify(o)));
|
|
273
|
+
|
|
274
|
+
// Test for format.
|
|
275
|
+
expect(s.format).toBe('SugarCube');
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
it('addPassage() - should override StoryData: formatVersion', function () {
|
|
279
|
+
// Generate object.
|
|
280
|
+
const o = {
|
|
281
|
+
'format-version': '2.28.2'
|
|
282
|
+
};
|
|
283
|
+
|
|
284
|
+
// Add the passage.
|
|
285
|
+
s.addPassage(new Passage('StoryData', JSON.stringify(o)));
|
|
286
|
+
|
|
287
|
+
// Test for format.
|
|
288
|
+
expect(s.formatVersion).toBe('2.28.2');
|
|
289
|
+
});
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
describe('removePassageByName()', () => {
|
|
293
|
+
let s = null;
|
|
294
|
+
|
|
295
|
+
beforeEach(() => {
|
|
296
|
+
s = new Story();
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
it('removePassageByName() - should decrease size', () => {
|
|
300
|
+
s.addPassage(new Passage('Find'));
|
|
301
|
+
s.addPassage(new Passage('Find2'));
|
|
302
|
+
s.removePassageByName('Find');
|
|
303
|
+
expect(s.size()).toBe(1);
|
|
304
|
+
});
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
describe('getPassagesByTag()', () => {
|
|
308
|
+
let s = null;
|
|
309
|
+
|
|
310
|
+
beforeEach(() => {
|
|
311
|
+
s = new Story();
|
|
312
|
+
});
|
|
313
|
+
|
|
314
|
+
it('getPassagesByTag() - should find passages', () => {
|
|
315
|
+
const p = new Passage('Find', '', ['one']);
|
|
316
|
+
const p2 = new Passage('Find2', '', ['one']);
|
|
317
|
+
s.addPassage(p);
|
|
318
|
+
s.addPassage(p2);
|
|
319
|
+
const ps = s.getPassagesByTag('one');
|
|
320
|
+
expect(ps).toHaveLength(2);
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
it('getPassagesByTag() - should find none if none in collection', () => {
|
|
324
|
+
const ps = s.getPassagesByTag('one');
|
|
325
|
+
expect(ps).toHaveLength(0);
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
it('getPassagesByTag() - should find none if no tags match search', () => {
|
|
329
|
+
const p = new Passage('Find', '', ['one']);
|
|
330
|
+
const p2 = new Passage('Find2', '', ['one']);
|
|
331
|
+
s.addPassage(p);
|
|
332
|
+
s.addPassage(p2);
|
|
333
|
+
const ps = s.getPassagesByTag('two');
|
|
334
|
+
expect(ps).toHaveLength(0);
|
|
335
|
+
});
|
|
336
|
+
});
|
|
337
|
+
|
|
338
|
+
describe('getPassageByName()', () => {
|
|
339
|
+
let s = null;
|
|
340
|
+
|
|
341
|
+
beforeEach(() => {
|
|
342
|
+
s = new Story();
|
|
343
|
+
});
|
|
344
|
+
|
|
345
|
+
it('getPassageByName() - should get passage by name', () => {
|
|
346
|
+
const p = new Passage('Find');
|
|
347
|
+
s.addPassage(p);
|
|
348
|
+
const passage = s.getPassageByName('Find');
|
|
349
|
+
expect(passage.name).toBe('Find');
|
|
350
|
+
});
|
|
351
|
+
});
|
|
352
|
+
|
|
353
|
+
describe('forEachPassage()', () => {
|
|
354
|
+
let s = null;
|
|
355
|
+
|
|
356
|
+
beforeEach(() => {
|
|
357
|
+
s = new Story();
|
|
358
|
+
});
|
|
359
|
+
|
|
360
|
+
it('forEachPassage() - should return if non-function', () => {
|
|
361
|
+
s.addPassage(new Passage('A'));
|
|
362
|
+
s.addPassage(new Passage('B'));
|
|
363
|
+
let passageNames = '';
|
|
364
|
+
s.forEachPassage((p) => {
|
|
365
|
+
passageNames += p.name;
|
|
366
|
+
});
|
|
367
|
+
expect(passageNames).toBe('AB');
|
|
368
|
+
});
|
|
369
|
+
|
|
370
|
+
it('forEachPassage() - should throw error if non-function', () => {
|
|
371
|
+
expect(() => {
|
|
372
|
+
s.forEachPassage(null);
|
|
373
|
+
}).toThrow();
|
|
374
|
+
});
|
|
375
|
+
});
|
|
376
|
+
|
|
377
|
+
describe('size()', () => {
|
|
378
|
+
let s = null;
|
|
379
|
+
|
|
380
|
+
beforeEach(() => {
|
|
381
|
+
s = new Story();
|
|
382
|
+
});
|
|
383
|
+
|
|
384
|
+
it('size() - should report number of passages', () => {
|
|
385
|
+
// Create a Passage
|
|
386
|
+
const p = new Passage('');
|
|
387
|
+
// Test initial size
|
|
388
|
+
expect(s.size()).toBe(0);
|
|
389
|
+
// Add a passage
|
|
390
|
+
s.addPassage(p);
|
|
391
|
+
// Test size after adding one
|
|
392
|
+
expect(s.size()).toBe(1);
|
|
393
|
+
});
|
|
394
|
+
});
|
|
395
|
+
|
|
396
|
+
describe('toJSON()', function () {
|
|
397
|
+
it('Should have default Story values', function () {
|
|
398
|
+
// Create a new Story.
|
|
399
|
+
const s = new Story();
|
|
400
|
+
// Convert to string and then back to object.
|
|
401
|
+
const result = JSON.parse(s.toJSON());
|
|
402
|
+
expect(result.name).toBe('');
|
|
403
|
+
expect(Object.keys(result.tagColors).length).toBe(0);
|
|
404
|
+
expect(result.ifid).toBe('');
|
|
405
|
+
expect(result.start).toBe('');
|
|
406
|
+
expect(result.formatVersion).toBe('');
|
|
407
|
+
expect(result.format).toBe('');
|
|
408
|
+
expect(result.creator).toBe('extwee');
|
|
409
|
+
expect(result.creatorVersion).toBe('2.2.0');
|
|
410
|
+
expect(result.zoom).toBe(0);
|
|
411
|
+
expect(Object.keys(result.metadata).length).toBe(0);
|
|
412
|
+
});
|
|
413
|
+
|
|
414
|
+
it('Should have passage data', function () {
|
|
415
|
+
// Create default Story.
|
|
416
|
+
const s = new Story();
|
|
417
|
+
// Add a passage.
|
|
418
|
+
s.addPassage(new Passage('Example', 'Test'));
|
|
419
|
+
// Convert to JSON and then back to object.
|
|
420
|
+
const result = JSON.parse(s.toJSON());
|
|
421
|
+
// Should have a single passage.
|
|
422
|
+
expect(result.passages.length).toBe(1);
|
|
423
|
+
});
|
|
424
|
+
});
|
|
425
|
+
|
|
426
|
+
describe('toTwee()', function () {
|
|
427
|
+
let s = null;
|
|
428
|
+
|
|
429
|
+
beforeEach(() => {
|
|
430
|
+
s = new Story();
|
|
431
|
+
});
|
|
432
|
+
|
|
433
|
+
it('Should detect StoryTitle text', function () {
|
|
434
|
+
// Add one passage.
|
|
435
|
+
s.addPassage(new Passage('StoryTitle', 'Content'));
|
|
436
|
+
|
|
437
|
+
// Convert to Twee.
|
|
438
|
+
const t = s.toTwee();
|
|
439
|
+
|
|
440
|
+
// Parse into a new story.
|
|
441
|
+
const story = parseTwee(t);
|
|
442
|
+
|
|
443
|
+
// Test for name.
|
|
444
|
+
expect(story.name).toBe('Content');
|
|
445
|
+
});
|
|
446
|
+
|
|
447
|
+
it('Should encode IFID', () => {
|
|
448
|
+
// Add passages.
|
|
449
|
+
s.addPassage(new Passage('Start'));
|
|
450
|
+
s.addPassage(new Passage('StoryTitle', 'Title'));
|
|
451
|
+
|
|
452
|
+
// Set an ifid property.
|
|
453
|
+
s.IFID = 'DE7DF8AD-E4CD-499E-A4E7-C5B98B73449A';
|
|
454
|
+
|
|
455
|
+
// Convert to Twee.
|
|
456
|
+
const t = s.toTwee();
|
|
457
|
+
|
|
458
|
+
// Parse file.
|
|
459
|
+
const tp = parseTwee(t);
|
|
460
|
+
|
|
461
|
+
// Verify IFID.
|
|
462
|
+
expect(tp.IFID).toBe('DE7DF8AD-E4CD-499E-A4E7-C5B98B73449A');
|
|
463
|
+
});
|
|
464
|
+
|
|
465
|
+
it('Should encode format, formatVersion, zoom, and start', () => {
|
|
466
|
+
// Add passages.
|
|
467
|
+
s.addPassage(new Passage('Start', 'Content'));
|
|
468
|
+
s.addPassage(new Passage('Untitled', 'Some stuff'));
|
|
469
|
+
|
|
470
|
+
s.name = 'Title';
|
|
471
|
+
s.format = 'Test';
|
|
472
|
+
s.formatVersion = '1.2.3';
|
|
473
|
+
s.zoom = 1;
|
|
474
|
+
s.start = 'Untitled';
|
|
475
|
+
|
|
476
|
+
// Convert to Twee.
|
|
477
|
+
const t = s.toTwee();
|
|
478
|
+
|
|
479
|
+
// Parse Twee.
|
|
480
|
+
const story2 = parseTwee(t);
|
|
481
|
+
|
|
482
|
+
// Test for format, formatVersion, zoom, and start.
|
|
483
|
+
expect(story2.formatVersion).toBe('1.2.3');
|
|
484
|
+
expect(story2.format).toBe('Test');
|
|
485
|
+
expect(story2.zoom).toBe(1);
|
|
486
|
+
expect(story2.start).toBe('Untitled');
|
|
487
|
+
});
|
|
488
|
+
|
|
489
|
+
it('Should write tag colors', () => {
|
|
490
|
+
// Add some passages.
|
|
491
|
+
s.addPassage(new Passage('Start', 'Content'));
|
|
492
|
+
s.addPassage(new Passage('Untitled', 'Some stuff'));
|
|
493
|
+
|
|
494
|
+
// Add tag colors.
|
|
495
|
+
s.tagColors = {
|
|
496
|
+
bar: 'green',
|
|
497
|
+
foo: 'red',
|
|
498
|
+
qaz: 'blue'
|
|
499
|
+
};
|
|
500
|
+
|
|
501
|
+
// Convert to Twee.
|
|
502
|
+
const t = s.toTwee();
|
|
503
|
+
|
|
504
|
+
// Convert back into Story.
|
|
505
|
+
const story2 = parseTwee(t);
|
|
506
|
+
|
|
507
|
+
// Test for tag colors
|
|
508
|
+
expect(story2.tagColors.bar).toBe('green');
|
|
509
|
+
expect(story2.tagColors.foo).toBe('red');
|
|
510
|
+
expect(story2.tagColors.qaz).toBe('blue');
|
|
511
|
+
});
|
|
512
|
+
|
|
513
|
+
it('Should encode "script" tag', () => {
|
|
514
|
+
// Add passages.
|
|
515
|
+
s.addPassage(new Passage('Test', 'Test', ['script']));
|
|
516
|
+
s.addPassage(new Passage('Start', 'Content'));
|
|
517
|
+
|
|
518
|
+
// Convert into Twee.
|
|
519
|
+
const t = s.toTwee();
|
|
520
|
+
|
|
521
|
+
// Convert back into Story.
|
|
522
|
+
const story = parseTwee(t);
|
|
523
|
+
|
|
524
|
+
// Search for 'script'.
|
|
525
|
+
const p = story.getPassagesByTag('script');
|
|
526
|
+
|
|
527
|
+
// Test for passage text.
|
|
528
|
+
expect(p[0].text).toBe('Test');
|
|
529
|
+
});
|
|
530
|
+
|
|
531
|
+
it('Should encode "stylesheet" tag', () => {
|
|
532
|
+
// Add passages.
|
|
533
|
+
s.addPassage(new Passage('Test', 'Test', ['stylesheet']));
|
|
534
|
+
s.addPassage(new Passage('Start', 'Content'));
|
|
535
|
+
|
|
536
|
+
// Convert into Twee.
|
|
537
|
+
const t = s.toTwee();
|
|
538
|
+
|
|
539
|
+
// Convert back into Story.
|
|
540
|
+
const story = parseTwee(t);
|
|
541
|
+
|
|
542
|
+
// Search for 'stylesheet'.
|
|
543
|
+
const p = story.getPassagesByTag('stylesheet');
|
|
544
|
+
|
|
545
|
+
// Test for passage text.
|
|
546
|
+
expect(p[0].text).toBe('Test');
|
|
547
|
+
});
|
|
548
|
+
});
|
|
549
|
+
|
|
550
|
+
describe('toTwine2HTML()', () => {
|
|
551
|
+
let s = null;
|
|
552
|
+
|
|
553
|
+
beforeEach(() => {
|
|
554
|
+
s = new Story();
|
|
555
|
+
});
|
|
556
|
+
|
|
557
|
+
it('Should throw error if no starting passage', function () {
|
|
558
|
+
// No start set.
|
|
559
|
+
expect(() => { s.toTwine2HTML(); }).toThrow();
|
|
560
|
+
});
|
|
561
|
+
|
|
562
|
+
it('Should throw error if starting passage cannot be found', function () {
|
|
563
|
+
// Set start.
|
|
564
|
+
s.start = 'Unknown';
|
|
565
|
+
// Has a start, but not part of collection.
|
|
566
|
+
expect(() => { s.toTwine2HTML(); }).toThrow();
|
|
567
|
+
});
|
|
568
|
+
|
|
569
|
+
it('Should encode name', () => {
|
|
570
|
+
// Add passage.
|
|
571
|
+
s.addPassage(new Passage('Start', 'Word'));
|
|
572
|
+
// Set start.
|
|
573
|
+
s.start = 'Start';
|
|
574
|
+
// Set name.
|
|
575
|
+
s.name = 'Test';
|
|
576
|
+
// Create HTML.
|
|
577
|
+
const result = s.toTwine2HTML();
|
|
578
|
+
// Expect the name to be encoded.
|
|
579
|
+
expect(result.includes('<tw-storydata name="Test"')).toBe(true);
|
|
580
|
+
});
|
|
581
|
+
|
|
582
|
+
it('Should encode IFID', () => {
|
|
583
|
+
// Add passage.
|
|
584
|
+
s.addPassage(new Passage('Start', 'Word'));
|
|
585
|
+
// Set start.
|
|
586
|
+
s.start = 'Start';
|
|
587
|
+
// Set IFID.
|
|
588
|
+
s.IFID = 'B94AC8AD-03E3-4496-96C8-FE958645FE61';
|
|
589
|
+
// Create HTML.
|
|
590
|
+
const result = s.toTwine2HTML();
|
|
591
|
+
// Expect the IFID to be encoded.
|
|
592
|
+
expect(result.includes('ifid="B94AC8AD-03E3-4496-96C8-FE958645FE61"')).toBe(true);
|
|
593
|
+
});
|
|
594
|
+
|
|
595
|
+
it('Should encode stylesheet passages', () => {
|
|
596
|
+
// Add passage.
|
|
597
|
+
s.addPassage(new Passage('Start', 'Word'));
|
|
598
|
+
// Set start.
|
|
599
|
+
s.start = 'Start';
|
|
600
|
+
// Add a stylesheet passage.
|
|
601
|
+
s.addPassage(new Passage('Test', 'Word', ['stylesheet']));
|
|
602
|
+
// Create HTML.
|
|
603
|
+
const result = s.toTwine2HTML();
|
|
604
|
+
// Expect the stylesheet passage text to be encoded.
|
|
605
|
+
expect(result.includes('<style role="stylesheet" id="twine-user-stylesheet" type="text/twine-css">Word')).toBe(true);
|
|
606
|
+
});
|
|
607
|
+
|
|
608
|
+
it('Should encode script passages', () => {
|
|
609
|
+
// Add passage.
|
|
610
|
+
s.addPassage(new Passage('Start', 'Word'));
|
|
611
|
+
// Set start.
|
|
612
|
+
s.start = 'Start';
|
|
613
|
+
// Add a script passage.
|
|
614
|
+
s.addPassage(new Passage('Test', 'Word', ['script']));
|
|
615
|
+
// Create HTML.
|
|
616
|
+
const result = s.toTwine2HTML();
|
|
617
|
+
// Expect the script passage text to be encoded.
|
|
618
|
+
expect(result.includes('<script role="script" id="twine-user-script" type="text/twine-javascript">Word')).toBe(true);
|
|
619
|
+
});
|
|
620
|
+
});
|
|
621
|
+
|
|
622
|
+
describe('toTwine1HTML()', function () {
|
|
623
|
+
let s = null;
|
|
624
|
+
|
|
625
|
+
beforeEach(() => {
|
|
626
|
+
s = new Story();
|
|
627
|
+
});
|
|
628
|
+
|
|
629
|
+
it('Should have correct data-size', function () {
|
|
630
|
+
// Add a passage.
|
|
631
|
+
s.addPassage(new Passage('Start', 'Word'));
|
|
632
|
+
// Create Twine 1 HTML.
|
|
633
|
+
const result = s.toTwine1HTML();
|
|
634
|
+
// Expect data-size to be 1.
|
|
635
|
+
expect(result.includes('<div tiddler="Start"')).toBe(true);
|
|
636
|
+
});
|
|
637
|
+
});
|
|
638
|
+
});
|