extwee 2.0.6 → 2.2.1
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 +20 -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 +68 -58
- package/src/JSON/parse.js +128 -0
- package/src/Passage.js +279 -202
- package/src/Story.js +653 -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 +349 -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 +244 -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 +677 -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 +173 -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/test/Twine2HTML/Twine2HTMLParser/unescaping.html +33 -0
- package/tsconfig.json +21 -0
- package/types/index.d.ts +14 -0
- package/types/src/JSON/parse.d.ts +8 -0
- package/types/src/Passage.d.ts +72 -0
- package/types/src/Story.d.ts +161 -0
- package/types/src/StoryFormat/parse.d.ts +7 -0
- package/types/src/StoryFormat.d.ts +97 -0
- package/types/src/TWS/parse.d.ts +10 -0
- package/types/src/Twee/parse.d.ts +10 -0
- package/types/src/Twine1HTML/compile.d.ts +17 -0
- package/types/src/Twine1HTML/parse.d.ts +10 -0
- package/types/src/Twine2ArchiveHTML/compile.d.ts +6 -0
- package/types/src/Twine2ArchiveHTML/parse.d.ts +6 -0
- package/types/src/Twine2HTML/compile.d.ts +9 -0
- package/types/src/Twine2HTML/parse.d.ts +17 -0
- package/types/src/extwee.d.ts +2 -0
- 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
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
import { Story, creatorVersion, creatorName } from '../../src/Story.js';
|
|
2
|
+
import Passage from '../../src/Passage.js';
|
|
3
|
+
import { parse as parseJSON } from '../../src/JSON/parse.js';
|
|
4
|
+
|
|
5
|
+
describe('JSON', () => {
|
|
6
|
+
describe('parse()', function () {
|
|
7
|
+
it('Should throw error if JSON is invalid', function () {
|
|
8
|
+
expect(() => { parseJSON('{'); }).toThrow();
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it('Should roundtrip default Story values using toJSON() and fromJSON()', function () {
|
|
12
|
+
// Create Story.
|
|
13
|
+
const r = new Story();
|
|
14
|
+
|
|
15
|
+
// Convert to JSON and back.
|
|
16
|
+
const s = parseJSON(r.toJSON());
|
|
17
|
+
|
|
18
|
+
// Check all properties.
|
|
19
|
+
expect(s.name).toBe('');
|
|
20
|
+
expect(Object.keys(s.tagColors).length).toBe(0);
|
|
21
|
+
expect(s.IFID).toBe('');
|
|
22
|
+
expect(s.start).toBe('');
|
|
23
|
+
expect(s.formatVersion).toBe('');
|
|
24
|
+
expect(s.format).toBe('');
|
|
25
|
+
expect(s.creator).toBe(creatorName);
|
|
26
|
+
expect(s.creatorVersion).toBe(creatorVersion);
|
|
27
|
+
expect(s.zoom).toBe(0);
|
|
28
|
+
expect(Object.keys(s.metadata).length).toBe(0);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it('Should parse passage data', function () {
|
|
32
|
+
// Create passage.
|
|
33
|
+
const p = new Passage('Test', 'Default');
|
|
34
|
+
|
|
35
|
+
// Create Story.
|
|
36
|
+
const s = new Story();
|
|
37
|
+
|
|
38
|
+
// Add a passage.
|
|
39
|
+
s.addPassage(p);
|
|
40
|
+
|
|
41
|
+
// Convert to JSON.
|
|
42
|
+
const js = s.toJSON(s);
|
|
43
|
+
|
|
44
|
+
// Convert back to Story.
|
|
45
|
+
const result = parseJSON(js);
|
|
46
|
+
|
|
47
|
+
// Should have a single passage.
|
|
48
|
+
expect(result.size()).toBe(1);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
describe('Partial Story Processing', function () {
|
|
52
|
+
it('Should parse everything but name', function () {
|
|
53
|
+
const s = '{"tagColors":{"r":"red"},"ifid":"dd","start":"Start","formatVersion":"1.0","metadata":{"some":"thing"},"format":"Snowman","creator":"extwee","creatorVersion":"2.2.0","zoom":1,"passages":[{"name":"Start","tags":["tag1"],"metadata":{},"text":"Word"}]}';
|
|
54
|
+
const r = parseJSON(s);
|
|
55
|
+
expect(r.name).toBe('');
|
|
56
|
+
expect(Object.keys(r.tagColors).length).toBe(1);
|
|
57
|
+
expect(r.IFID).toBe('DD');
|
|
58
|
+
expect(r.start).toBe('Start');
|
|
59
|
+
expect(r.formatVersion).toBe('1.0');
|
|
60
|
+
expect(Object.keys(r.metadata).length).toBe(1);
|
|
61
|
+
expect(r.format).toBe('Snowman');
|
|
62
|
+
expect(r.creator).toBe(creatorName);
|
|
63
|
+
expect(r.creatorVersion).toBe('2.2.0');
|
|
64
|
+
expect(r.zoom).toBe(1);
|
|
65
|
+
expect(r.size()).toBe(1);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it('Should parse everything but tagColors', function () {
|
|
69
|
+
const s = '{"name":"Test","ifid":"dd","start":"Start","formatVersion":"1.0","metadata":{"some":"thing"},"format":"Snowman","creator":"extwee","creatorVersion":"2.2.0","zoom":1,"passages":[{"name":"Start","tags":["tag1"],"metadata":{},"text":"Word"}]}';
|
|
70
|
+
const r = parseJSON(s);
|
|
71
|
+
expect(r.name).toBe('Test');
|
|
72
|
+
expect(Object.keys(r.tagColors).length).toBe(0);
|
|
73
|
+
expect(r.IFID).toBe('DD');
|
|
74
|
+
expect(r.start).toBe('Start');
|
|
75
|
+
expect(r.formatVersion).toBe('1.0');
|
|
76
|
+
expect(Object.keys(r.metadata).length).toBe(1);
|
|
77
|
+
expect(r.format).toBe('Snowman');
|
|
78
|
+
expect(r.creator).toBe(creatorName);
|
|
79
|
+
expect(r.creatorVersion).toBe('2.2.0');
|
|
80
|
+
expect(r.zoom).toBe(1);
|
|
81
|
+
expect(r.size()).toBe(1);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it('Should parse everything but ifid', function () {
|
|
85
|
+
const s = '{"name":"Test","tagColors":{"r":"red"},"start":"Start","formatVersion":"1.0","metadata":{"some":"thing"},"format":"Snowman","creator":"extwee","creatorVersion":"2.2.0","zoom":1,"passages":[{"name":"Start","tags":["tag1"],"metadata":{},"text":"Word"}]}';
|
|
86
|
+
const r = parseJSON(s);
|
|
87
|
+
expect(r.name).toBe('Test');
|
|
88
|
+
expect(Object.keys(r.tagColors).length).toBe(1);
|
|
89
|
+
expect(r.IFID).toBe('');
|
|
90
|
+
expect(r.start).toBe('Start');
|
|
91
|
+
expect(r.formatVersion).toBe('1.0');
|
|
92
|
+
expect(Object.keys(r.metadata).length).toBe(1);
|
|
93
|
+
expect(r.format).toBe('Snowman');
|
|
94
|
+
expect(r.creator).toBe(creatorName);
|
|
95
|
+
expect(r.creatorVersion).toBe('2.2.0');
|
|
96
|
+
expect(r.zoom).toBe(1);
|
|
97
|
+
expect(r.size()).toBe(1);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it('Should parse everything but start', function () {
|
|
101
|
+
const s = '{"name":"Test","tagColors":{"r":"red"},"ifid":"dd","formatVersion":"1.0","metadata":{"some":"thing"},"format":"Snowman","creator":"extwee","creatorVersion":"2.2.0","zoom":1,"passages":[{"name":"Star","tags":["tag1"],"metadata":{},"text":"Word"}]}';
|
|
102
|
+
const r = parseJSON(s);
|
|
103
|
+
expect(r.name).toBe('Test');
|
|
104
|
+
expect(Object.keys(r.tagColors).length).toBe(1);
|
|
105
|
+
expect(r.IFID).toBe('DD');
|
|
106
|
+
expect(r.start).toBe('');
|
|
107
|
+
expect(r.formatVersion).toBe('1.0');
|
|
108
|
+
expect(Object.keys(r.metadata).length).toBe(1);
|
|
109
|
+
expect(r.format).toBe('Snowman');
|
|
110
|
+
expect(r.creator).toBe(creatorName);
|
|
111
|
+
expect(r.creatorVersion).toBe('2.2.0');
|
|
112
|
+
expect(r.zoom).toBe(1);
|
|
113
|
+
expect(r.size()).toBe(1);
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it('Should parse everything but formatVersion', function () {
|
|
117
|
+
const s = '{"name":"Test","tagColors":{"r":"red"},"ifid":"dd","start":"Start","metadata":{"some":"thing"},"format":"Snowman","creator":"extwee","creatorVersion":"2.2.0","zoom":1,"passages":[{"name":"Start","tags":["tag1"],"metadata":{},"text":"Word"}]}';
|
|
118
|
+
const r = parseJSON(s);
|
|
119
|
+
expect(r.name).toBe('Test');
|
|
120
|
+
expect(Object.keys(r.tagColors).length).toBe(1);
|
|
121
|
+
expect(r.IFID).toBe('DD');
|
|
122
|
+
expect(r.start).toBe('Start');
|
|
123
|
+
expect(r.formatVersion).toBe('');
|
|
124
|
+
expect(Object.keys(r.metadata).length).toBe(1);
|
|
125
|
+
expect(r.format).toBe('Snowman');
|
|
126
|
+
expect(r.creator).toBe(creatorName);
|
|
127
|
+
expect(r.creatorVersion).toBe('2.2.0');
|
|
128
|
+
expect(r.zoom).toBe(1);
|
|
129
|
+
expect(r.size()).toBe(1);
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it('Should parse everything but format', function () {
|
|
133
|
+
const s = '{"name":"Test","tagColors":{"r":"red"},"ifid":"dd","start":"Start","formatVersion":"1.0","metadata":{"some":"thing"},"creator":"extwee","creatorVersion":"2.2.0","zoom":1,"passages":[{"name":"Start","tags":["tag1"],"metadata":{},"text":"Word"}]}';
|
|
134
|
+
const r = parseJSON(s);
|
|
135
|
+
expect(r.name).toBe('Test');
|
|
136
|
+
expect(Object.keys(r.tagColors).length).toBe(1);
|
|
137
|
+
expect(r.IFID).toBe('DD');
|
|
138
|
+
expect(r.start).toBe('Start');
|
|
139
|
+
expect(r.formatVersion).toBe('1.0');
|
|
140
|
+
expect(Object.keys(r.metadata).length).toBe(1);
|
|
141
|
+
expect(r.format).toBe('');
|
|
142
|
+
expect(r.creator).toBe(creatorName);
|
|
143
|
+
expect(r.creatorVersion).toBe('2.2.0');
|
|
144
|
+
expect(r.zoom).toBe(1);
|
|
145
|
+
expect(r.size()).toBe(1);
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
it('Should parse everything but creator', function () {
|
|
149
|
+
const s = '{"name":"Test","tagColors":{"r":"red"},"ifid":"dd","start":"Start","formatVersion":"1.0","metadata":{"some":"thing"},"format":"Snowman","creatorVersion":"2.2.0","zoom":1,"passages":[{"name":"Start","tags":["tag1"],"metadata":{},"text":"Word"}]}';
|
|
150
|
+
const r = parseJSON(s);
|
|
151
|
+
expect(r.name).toBe('Test');
|
|
152
|
+
expect(Object.keys(r.tagColors).length).toBe(1);
|
|
153
|
+
expect(r.IFID).toBe('DD');
|
|
154
|
+
expect(r.start).toBe('Start');
|
|
155
|
+
expect(r.formatVersion).toBe('1.0');
|
|
156
|
+
expect(Object.keys(r.metadata).length).toBe(1);
|
|
157
|
+
expect(r.format).toBe('Snowman');
|
|
158
|
+
expect(r.creator).toBe(creatorName);
|
|
159
|
+
expect(r.creatorVersion).toBe('2.2.0');
|
|
160
|
+
expect(r.zoom).toBe(1);
|
|
161
|
+
expect(r.size()).toBe(1);
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
it('Should parse everything but creator version', function () {
|
|
165
|
+
const s = '{"name":"Test","tagColors":{"r":"red"},"ifid":"dd","start":"Start","formatVersion":"1.0","metadata":{"some":"thing"},"format":"Snowman","creator":"extwee","zoom":1,"passages":[{"name":"Start","tags":["tag1"],"metadata":{},"text":"Word"}]}';
|
|
166
|
+
const r = parseJSON(s);
|
|
167
|
+
expect(r.name).toBe('Test');
|
|
168
|
+
expect(Object.keys(r.tagColors).length).toBe(1);
|
|
169
|
+
expect(r.IFID).toBe('DD');
|
|
170
|
+
expect(r.start).toBe('Start');
|
|
171
|
+
expect(r.formatVersion).toBe('1.0');
|
|
172
|
+
expect(Object.keys(r.metadata).length).toBe(1);
|
|
173
|
+
expect(r.format).toBe('Snowman');
|
|
174
|
+
expect(r.creator).toBe(creatorName);
|
|
175
|
+
expect(r.creatorVersion).toBe(creatorVersion);
|
|
176
|
+
expect(r.zoom).toBe(1);
|
|
177
|
+
expect(r.size()).toBe(1);
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
it('Should parse everything but zoom', function () {
|
|
181
|
+
const s = '{"name":"Test","tagColors":{"r":"red"},"ifid":"dd","start":"Start","formatVersion":"1.0","metadata":{"some":"thing"},"format":"Snowman","creator":"extwee","creatorVersion":"2.2.0","passages":[{"name":"Start","tags":["tag1"],"metadata":{},"text":"Word"}]}';
|
|
182
|
+
const r = parseJSON(s);
|
|
183
|
+
expect(r.name).toBe('Test');
|
|
184
|
+
expect(Object.keys(r.tagColors).length).toBe(1);
|
|
185
|
+
expect(r.IFID).toBe('DD');
|
|
186
|
+
expect(r.start).toBe('Start');
|
|
187
|
+
expect(r.formatVersion).toBe('1.0');
|
|
188
|
+
expect(Object.keys(r.metadata).length).toBe(1);
|
|
189
|
+
expect(r.format).toBe('Snowman');
|
|
190
|
+
expect(r.creator).toBe(creatorName);
|
|
191
|
+
expect(r.creatorVersion).toBe('2.2.0');
|
|
192
|
+
expect(r.zoom).toBe(0);
|
|
193
|
+
expect(r.size()).toBe(1);
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
it('Should parse everything but metadata', function () {
|
|
197
|
+
const s = '{"name":"Test","tagColors":{"r":"red"},"ifid":"dd","start":"Start","formatVersion":"1.0","format":"Snowman","creator":"extwee","creatorVersion":"2.2.0","zoom":1,"passages":[{"name":"Start","tags":["tag1"],"metadata":{},"text":"Word"}]}';
|
|
198
|
+
const r = parseJSON(s);
|
|
199
|
+
expect(r.name).toBe('Test');
|
|
200
|
+
expect(Object.keys(r.tagColors).length).toBe(1);
|
|
201
|
+
expect(r.IFID).toBe('DD');
|
|
202
|
+
expect(r.start).toBe('Start');
|
|
203
|
+
expect(r.formatVersion).toBe('1.0');
|
|
204
|
+
expect(Object.keys(r.metadata).length).toBe(0);
|
|
205
|
+
expect(r.format).toBe('Snowman');
|
|
206
|
+
expect(r.creator).toBe(creatorName);
|
|
207
|
+
expect(r.creatorVersion).toBe('2.2.0');
|
|
208
|
+
expect(r.zoom).toBe(1);
|
|
209
|
+
expect(r.size()).toBe(1);
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
it('Should parse everything but passages', function () {
|
|
213
|
+
const s = '{"name":"Test","tagColors":{"r":"red"},"ifid":"dd","start":"Start","formatVersion":"1.0","metadata":{"some":"thing"},"format":"Snowman","creator":"extwee","creatorVersion":"2.2.0","zoom":1}';
|
|
214
|
+
const r = parseJSON(s);
|
|
215
|
+
expect(r.name).toBe('Test');
|
|
216
|
+
expect(Object.keys(r.tagColors).length).toBe(1);
|
|
217
|
+
expect(r.IFID).toBe('DD');
|
|
218
|
+
expect(r.start).toBe('Start');
|
|
219
|
+
expect(r.formatVersion).toBe('1.0');
|
|
220
|
+
expect(Object.keys(r.metadata).length).toBe(1);
|
|
221
|
+
expect(r.format).toBe('Snowman');
|
|
222
|
+
expect(r.creator).toBe(creatorName);
|
|
223
|
+
expect(r.creatorVersion).toBe('2.2.0');
|
|
224
|
+
expect(r.zoom).toBe(1);
|
|
225
|
+
expect(r.size()).toBe(0);
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
it('Should ignore non-arrays for passages', function () {
|
|
229
|
+
const s = '{"name":"Test","tagColors":{"r":"red"},"ifid":"dd","start":"Start","formatVersion":"1.0","metadata":{"some":"thing"},"format":"Snowman","creator":"extwee","creatorVersion":"2.2.0","zoom":1,"passages":{}}';
|
|
230
|
+
const r = parseJSON(s);
|
|
231
|
+
expect(r.name).toBe('Test');
|
|
232
|
+
expect(Object.keys(r.tagColors).length).toBe(1);
|
|
233
|
+
expect(r.IFID).toBe('DD');
|
|
234
|
+
expect(r.start).toBe('Start');
|
|
235
|
+
expect(r.formatVersion).toBe('1.0');
|
|
236
|
+
expect(Object.keys(r.metadata).length).toBe(1);
|
|
237
|
+
expect(r.format).toBe('Snowman');
|
|
238
|
+
expect(r.creator).toBe(creatorName);
|
|
239
|
+
expect(r.creatorVersion).toBe('2.2.0');
|
|
240
|
+
expect(r.zoom).toBe(1);
|
|
241
|
+
expect(r.size()).toBe(0);
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
it('Should parse everything but passage name', function () {
|
|
245
|
+
const s = '{"name":"Test","tagColors":{"r":"red"},"ifid":"dd","start":"Start","formatVersion":"1.0","metadata":{"some":"thing"},"format":"Snowman","creator":"extwee","creatorVersion":"2.2.0","zoom":1,"passages":[{"tags":["tag1"],"metadata":{},"text":"Word"}]}';
|
|
246
|
+
const r = parseJSON(s);
|
|
247
|
+
expect(r.name).toBe('Test');
|
|
248
|
+
expect(Object.keys(r.tagColors).length).toBe(1);
|
|
249
|
+
expect(r.IFID).toBe('DD');
|
|
250
|
+
expect(r.start).toBe('Start');
|
|
251
|
+
expect(r.formatVersion).toBe('1.0');
|
|
252
|
+
expect(Object.keys(r.metadata).length).toBe(1);
|
|
253
|
+
expect(r.format).toBe('Snowman');
|
|
254
|
+
expect(r.creator).toBe(creatorName);
|
|
255
|
+
expect(r.creatorVersion).toBe('2.2.0');
|
|
256
|
+
expect(r.zoom).toBe(1);
|
|
257
|
+
expect(r.size()).toBe(1);
|
|
258
|
+
expect(r.getPassageByName('').name).toBe('');
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
it('Should parse everything but passage tags', function () {
|
|
262
|
+
const s = '{"name":"Test","tagColors":{"r":"red"},"ifid":"dd","start":"Start","formatVersion":"1.0","metadata":{"some":"thing"},"format":"Snowman","creator":"extwee","creatorVersion":"2.2.0","zoom":1,"passages":[{"name":"Start","metadata":{"s":"e"},"text":"Word"}]}';
|
|
263
|
+
const r = parseJSON(s);
|
|
264
|
+
expect(r.name).toBe('Test');
|
|
265
|
+
expect(Object.keys(r.tagColors).length).toBe(1);
|
|
266
|
+
expect(r.IFID).toBe('DD');
|
|
267
|
+
expect(r.start).toBe('Start');
|
|
268
|
+
expect(r.formatVersion).toBe('1.0');
|
|
269
|
+
expect(Object.keys(r.metadata).length).toBe(1);
|
|
270
|
+
expect(r.format).toBe('Snowman');
|
|
271
|
+
expect(r.creator).toBe(creatorName);
|
|
272
|
+
expect(r.creatorVersion).toBe('2.2.0');
|
|
273
|
+
expect(r.zoom).toBe(1);
|
|
274
|
+
expect(r.size()).toBe(1);
|
|
275
|
+
expect(r.getPassageByName('Start').metadata.s).toBe('e');
|
|
276
|
+
expect(r.getPassageByName('Start').tags.length).toBe(0);
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
it('Should parse everything but passage text', function () {
|
|
280
|
+
const s = '{"name":"Test","tagColors":{"r":"red"},"ifid":"dd","start":"Start","formatVersion":"1.0","metadata":{"some":"thing"},"format":"Snowman","creator":"extwee","creatorVersion":"2.2.0","zoom":1,"passages":[{"name":"Start","tags":["tag1"],"metadata":{"s":"e"}}]}';
|
|
281
|
+
const r = parseJSON(s);
|
|
282
|
+
expect(r.name).toBe('Test');
|
|
283
|
+
expect(Object.keys(r.tagColors).length).toBe(1);
|
|
284
|
+
expect(r.IFID).toBe('DD');
|
|
285
|
+
expect(r.start).toBe('Start');
|
|
286
|
+
expect(r.formatVersion).toBe('1.0');
|
|
287
|
+
expect(Object.keys(r.metadata).length).toBe(1);
|
|
288
|
+
expect(r.format).toBe('Snowman');
|
|
289
|
+
expect(r.creator).toBe(creatorName);
|
|
290
|
+
expect(r.creatorVersion).toBe('2.2.0');
|
|
291
|
+
expect(r.zoom).toBe(1);
|
|
292
|
+
expect(r.size()).toBe(1);
|
|
293
|
+
expect(r.getPassageByName('Start').metadata.s).toBe('e');
|
|
294
|
+
expect(r.getPassageByName('Start').text).toBe('');
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
it('Parse everything but passage metadata', function () {
|
|
298
|
+
const s = '{"name":"Test","tagColors":{"r":"red"},"ifid":"dd","start":"Start","formatVersion":"1.0","metadata":{"some":"thing"},"format":"Snowman","creator":"extwee","creatorVersion":"2.2.0","zoom":1,"passages":[{"name":"Start","tags":["tag1"],"text":"Word"}]}';
|
|
299
|
+
const r = parseJSON(s);
|
|
300
|
+
expect(r.name).toBe('Test');
|
|
301
|
+
expect(Object.keys(r.tagColors).length).toBe(1);
|
|
302
|
+
expect(r.IFID).toBe('DD');
|
|
303
|
+
expect(r.start).toBe('Start');
|
|
304
|
+
expect(r.formatVersion).toBe('1.0');
|
|
305
|
+
expect(Object.keys(r.metadata).length).toBe(1);
|
|
306
|
+
expect(r.format).toBe('Snowman');
|
|
307
|
+
expect(r.creator).toBe(creatorName);
|
|
308
|
+
expect(r.creatorVersion).toBe('2.2.0');
|
|
309
|
+
expect(r.zoom).toBe(1);
|
|
310
|
+
expect(r.size()).toBe(1);
|
|
311
|
+
expect(Object.prototype.hasOwnProperty.call(r.getPassageByName('Start').metadata, 's')).toBe(false);
|
|
312
|
+
expect(r.getPassageByName('Start').text).toBe('Word');
|
|
313
|
+
});
|
|
314
|
+
});
|
|
315
|
+
});
|
|
316
|
+
});
|
package/test/Passage.test.js
CHANGED
|
@@ -1,104 +1,244 @@
|
|
|
1
|
-
import Passage from '../src/Passage.js';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
expect(p.
|
|
9
|
-
expect(p.
|
|
10
|
-
expect(
|
|
11
|
-
expect(p.
|
|
12
|
-
});
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
describe('name', () => {
|
|
16
|
-
it('Set name', () => {
|
|
17
|
-
const p = new Passage();
|
|
18
|
-
p.name = 'New';
|
|
19
|
-
expect(p.name).toBe('New');
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
it('Throw error if name is not String', () => {
|
|
23
|
-
const p = new Passage();
|
|
24
|
-
expect(() => {
|
|
25
|
-
p.name = 1;
|
|
26
|
-
}).toThrow();
|
|
27
|
-
});
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
describe('tags', () => {
|
|
31
|
-
it('Set tags', () => {
|
|
32
|
-
const p = new Passage();
|
|
33
|
-
p.tags = ['tag'];
|
|
34
|
-
expect(p.tags).toHaveLength(1);
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it('Throw error if tags is not Array', () => {
|
|
38
|
-
const p = new Passage();
|
|
39
|
-
expect(() => {
|
|
40
|
-
p.tags = 1;
|
|
41
|
-
}).toThrow();
|
|
42
|
-
});
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
describe('metadata', () => {
|
|
46
|
-
it('Set metadata', () => {
|
|
47
|
-
const p = new Passage();
|
|
48
|
-
p.metadata = { position: '100,100' };
|
|
49
|
-
expect(p.metadata).toEqual({ position: '100,100' });
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
it('Throw error if metadata is not an Object', () => {
|
|
53
|
-
const p = new Passage();
|
|
54
|
-
expect(() => {
|
|
55
|
-
p.metadata = 1;
|
|
56
|
-
}).toThrow();
|
|
57
|
-
});
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
describe('text', () => {
|
|
61
|
-
it('Set text', () => {
|
|
62
|
-
const p = new Passage();
|
|
63
|
-
p.text = 'New';
|
|
64
|
-
expect(p.text).toBe('New');
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
it('Throw error if text is not a String', () => {
|
|
68
|
-
const p = new Passage();
|
|
69
|
-
expect(() => {
|
|
70
|
-
p.text = 1;
|
|
71
|
-
}).toThrow();
|
|
72
|
-
});
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
describe('
|
|
76
|
-
it('
|
|
77
|
-
const p = new Passage();
|
|
78
|
-
p.
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
});
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
describe('
|
|
91
|
-
it('
|
|
92
|
-
const p = new Passage(
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
expect(
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
1
|
+
import Passage from '../src/Passage.js';
|
|
2
|
+
import { parse as HTMLParser } from 'node-html-parser';
|
|
3
|
+
|
|
4
|
+
describe('Passage', () => {
|
|
5
|
+
describe('constructor()', () => {
|
|
6
|
+
it('Set default values', () => {
|
|
7
|
+
const p = new Passage();
|
|
8
|
+
expect(p.name).toBe('');
|
|
9
|
+
expect(p.tags).toHaveLength(0);
|
|
10
|
+
expect(p.text).toBe('');
|
|
11
|
+
expect(typeof p.metadata).toBe('object');
|
|
12
|
+
});
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
describe('name', () => {
|
|
16
|
+
it('Set name', () => {
|
|
17
|
+
const p = new Passage();
|
|
18
|
+
p.name = 'New';
|
|
19
|
+
expect(p.name).toBe('New');
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it('Throw error if name is not String', () => {
|
|
23
|
+
const p = new Passage();
|
|
24
|
+
expect(() => {
|
|
25
|
+
p.name = 1;
|
|
26
|
+
}).toThrow();
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
describe('tags', () => {
|
|
31
|
+
it('Set tags', () => {
|
|
32
|
+
const p = new Passage();
|
|
33
|
+
p.tags = ['tag'];
|
|
34
|
+
expect(p.tags).toHaveLength(1);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('Throw error if tags is not Array', () => {
|
|
38
|
+
const p = new Passage();
|
|
39
|
+
expect(() => {
|
|
40
|
+
p.tags = 1;
|
|
41
|
+
}).toThrow();
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
describe('metadata', () => {
|
|
46
|
+
it('Set metadata', () => {
|
|
47
|
+
const p = new Passage();
|
|
48
|
+
p.metadata = { position: '100,100' };
|
|
49
|
+
expect(p.metadata).toEqual({ position: '100,100' });
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('Throw error if metadata is not an Object', () => {
|
|
53
|
+
const p = new Passage();
|
|
54
|
+
expect(() => {
|
|
55
|
+
p.metadata = 1;
|
|
56
|
+
}).toThrow();
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
describe('text', () => {
|
|
61
|
+
it('Set text', () => {
|
|
62
|
+
const p = new Passage();
|
|
63
|
+
p.text = 'New';
|
|
64
|
+
expect(p.text).toBe('New');
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it('Throw error if text is not a String', () => {
|
|
68
|
+
const p = new Passage();
|
|
69
|
+
expect(() => {
|
|
70
|
+
p.text = 1;
|
|
71
|
+
}).toThrow();
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
describe('toTwee()', () => {
|
|
76
|
+
it('Create name string', () => {
|
|
77
|
+
const p = new Passage('Name', 'Test');
|
|
78
|
+
expect(p.toTwee()).toBe(':: Name\nTest\n\n');
|
|
79
|
+
});
|
|
80
|
+
it('Create tags string', () => {
|
|
81
|
+
const p = new Passage('Name', 'Test', ['tags', 'another']);
|
|
82
|
+
expect(p.toTwee()).toBe(':: Name [tags another]\nTest\n\n');
|
|
83
|
+
});
|
|
84
|
+
it('Create metadata string', () => {
|
|
85
|
+
const p = new Passage('Name', 'Test', ['tags', 'another'], { position: '100,100' });
|
|
86
|
+
expect(p.toTwee()).toBe(':: Name [tags another] {"position":"100,100"}\nTest\n\n');
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
describe('toJSON()', function () {
|
|
91
|
+
it('Should hold default values', function () {
|
|
92
|
+
const p = new Passage();
|
|
93
|
+
const r = JSON.parse(p.toJSON());
|
|
94
|
+
expect(r.name).toBe('');
|
|
95
|
+
expect(r.text).toBe('');
|
|
96
|
+
expect(r.tags.length).toBe(0);
|
|
97
|
+
expect(Object.keys(r.metadata).length).toBe(0);
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
describe('toTwine2HTML()', function () {
|
|
102
|
+
let p = null;
|
|
103
|
+
let result = null;
|
|
104
|
+
|
|
105
|
+
beforeEach(() => {
|
|
106
|
+
p = new Passage('Test', 'Word', ['tag1'], { some: 'thing' });
|
|
107
|
+
result = p.toTwine2HTML();
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it('Should contain default PID', function () {
|
|
111
|
+
expect(result.includes('pid="1"')).toBe(true);
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it('Should include name', function () {
|
|
115
|
+
expect(result.includes('name="Test"')).toBe(true);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it('Should include single tag', function () {
|
|
119
|
+
expect(result.includes('tags="tag1"')).toBe(true);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it('Should include multiple tags', function () {
|
|
123
|
+
p.tags = ['tag1', 'tag2'];
|
|
124
|
+
result = p.toTwine2HTML();
|
|
125
|
+
expect(result.includes('tags="tag1 tag2"')).toBe(true);
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
it('Should include position, if it exists', function () {
|
|
129
|
+
p.metadata = { position: '102,99' };
|
|
130
|
+
result = p.toTwine2HTML();
|
|
131
|
+
expect(result.includes('position="102,99"')).toBe(true);
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
it('Should include size, if it exists', function () {
|
|
135
|
+
p.metadata = { size: '100,100' };
|
|
136
|
+
result = p.toTwine2HTML();
|
|
137
|
+
expect(result.includes('size="100,100"')).toBe(true);
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
describe('toTwine1HTML()', function () {
|
|
142
|
+
let p = null;
|
|
143
|
+
let result = null;
|
|
144
|
+
|
|
145
|
+
beforeEach(() => {
|
|
146
|
+
p = new Passage('Test', 'Word', ['tag1'], { position: '12, 12' });
|
|
147
|
+
result = p.toTwine1HTML();
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
it('Should include tiddler', function () {
|
|
151
|
+
expect(result.includes('tiddler="Test"')).toBe(true);
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
it('Should include single tag', function () {
|
|
155
|
+
expect(result.includes('tags="tag1"')).toBe(true);
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
it('Should include multiple tags', function () {
|
|
159
|
+
p.tags = ['tag1', 'tag2'];
|
|
160
|
+
result = p.toTwine1HTML();
|
|
161
|
+
expect(result.includes('tags="tag1 tag2"')).toBe(true);
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
it('Should include position, if it exists', function () {
|
|
165
|
+
p.metadata = { position: '102,99' };
|
|
166
|
+
result = p.toTwine1HTML();
|
|
167
|
+
expect(result.includes('position="102,99"')).toBe(true);
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
it('Should use default position', function () {
|
|
171
|
+
p.metadata = {};
|
|
172
|
+
result = p.toTwine1HTML();
|
|
173
|
+
expect(result.includes('position="10,10"')).toBe(true);
|
|
174
|
+
});
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
describe('Escaping', function () {
|
|
178
|
+
it('Should escape double quotes', function () {
|
|
179
|
+
const p = new Passage('Test', 'Word "word"');
|
|
180
|
+
expect(p.toTwine2HTML().includes('Word "word"')).toBe(true);
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
it('Should escape ampersands', function () {
|
|
184
|
+
const p = new Passage('Test', 'Word & word');
|
|
185
|
+
expect(p.toTwine2HTML().includes('Word & word')).toBe(true);
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
it('Should escape less than', function () {
|
|
189
|
+
const p = new Passage('Test', 'Word < word');
|
|
190
|
+
expect(p.toTwine2HTML().includes('Word < word')).toBe(true);
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
it('Should escape greater than', function () {
|
|
194
|
+
const p = new Passage('Test', 'Word > word');
|
|
195
|
+
expect(p.toTwine2HTML().includes('Word > word')).toBe(true);
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
it('Should escape all', function () {
|
|
199
|
+
const p = new Passage('Test', 'Word &<>"\' word');
|
|
200
|
+
expect(p.toTwine2HTML().includes('>Word &<>"' word<')).toBe(true);
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
it('Should escape meta-characters safely in name', function () {
|
|
204
|
+
const p = new Passage('"Test"');
|
|
205
|
+
expect(p.toTwine2HTML().includes('name=""Test""')).toBe(true);
|
|
206
|
+
expect(p.toTwine1HTML().includes('tiddler=""Test""')).toBe(true);
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
it('Should escape meta-characters safely in text', function () {
|
|
210
|
+
const p = new Passage('Test', '"Word"');
|
|
211
|
+
expect(p.toTwine2HTML().includes('"Word"')).toBe(true);
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
it('Should escape meta-characters safely in tags', function () {
|
|
215
|
+
const p = new Passage('Test', 'Word', ['&tag', '"bad"']);
|
|
216
|
+
expect(p.toTwine2HTML().includes('tags="&tag "bad""')).toBe(true);
|
|
217
|
+
expect(p.toTwine1HTML().includes('tags="&tag "bad""')).toBe(true);
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
it('Should escape meta-characters safely in Twee header', function () {
|
|
221
|
+
const p = new Passage('Where do tags begin? [well', '', ['hmm']);
|
|
222
|
+
expect(p.toTwee().includes('Where do tags begin? \[well [hmm]')).toBe(true);
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
it('Should produce valid HTML attributes', function () {
|
|
226
|
+
// Generate passage.
|
|
227
|
+
const p = new Passage('"Test"', '"Word"', ['&tag', '"bad"'], { position: '100,100' });
|
|
228
|
+
// Parse HTML.
|
|
229
|
+
const d = new HTMLParser(p.toTwine2HTML());
|
|
230
|
+
// Test attributes.
|
|
231
|
+
expect(d.querySelector('tw-passagedata').getAttribute('name')).toBe('"Test"');
|
|
232
|
+
expect(d.querySelector('tw-passagedata').getAttribute('tags')).toBe('&tag "bad"');
|
|
233
|
+
expect(d.querySelector('tw-passagedata').getAttribute('position')).toBe('100,100');
|
|
234
|
+
// Use Twine 2 result.
|
|
235
|
+
const s = `<tw-passagedata pid="1" name=""Test"" tags="&tag "bad"" position="100,100" size="100,100"></tw-passagedata>`;
|
|
236
|
+
// Parse HTML.
|
|
237
|
+
const t = new HTMLParser(s);
|
|
238
|
+
// Test Twine 2 attributes.
|
|
239
|
+
expect(t.querySelector('tw-passagedata').getAttribute('name')).toBe('"Test"');
|
|
240
|
+
expect(t.querySelector('tw-passagedata').getAttribute('tags')).toBe('&tag "bad"');
|
|
241
|
+
expect(t.querySelector('tw-passagedata').getAttribute('position')).toBe('100,100');
|
|
242
|
+
});
|
|
243
|
+
});
|
|
244
|
+
});
|