extwee 2.3.11 → 2.3.12
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/CHANGELOG.md +219 -0
- package/CONTRIBUTING.md +305 -0
- package/README.md +16 -0
- package/build/extwee.core.min.js +1 -1
- package/build/extwee.twine1html.min.js +1 -1
- package/build/extwee.twine2archive.min.js +1 -1
- package/build/extwee.tws.min.js +1 -1
- package/package.json +8 -5
- package/src/Story.js +2 -2
- package/types/src/Story.d.ts +1 -1
- package/.github/FUNDING.yml +0 -3
- package/.github/codeql-analysis.yml +0 -51
- package/.github/dependabot.yml +0 -11
- package/.github/workflows/dependabot-automerge.yml +0 -23
- package/.github/workflows/nodejs.yml +0 -28
- package/.travis.yml +0 -13
- package/babel.config.json +0 -18
- package/docs/.nojekyll +0 -0
- package/docs/README.md +0 -224
- package/docs/_sidebar.md +0 -19
- package/docs/build/extwee.core.min.js +0 -1
- package/docs/build/extwee.twine1html.min.js +0 -1
- package/docs/build/extwee.twine2archive.min.js +0 -1
- package/docs/build/extwee.tws.min.js +0 -1
- package/docs/demos/compiler/extwee.core.min.js +0 -1
- package/docs/demos/compiler/index.css +0 -105
- package/docs/demos/compiler/index.html +0 -359
- package/docs/demos/decompile/extwee.core.min.js +0 -1
- package/docs/demos/decompile/index.css +0 -584
- package/docs/demos/decompile/index.html +0 -468
- package/docs/examples/dynamicPassages.md +0 -28
- package/docs/examples/jsonToTwee.md +0 -23
- package/docs/examples/twsToTwee.md +0 -25
- package/docs/formats/json.md +0 -17
- package/docs/formats/twee.md +0 -13
- package/docs/formats/twine1HTML.md +0 -13
- package/docs/formats/twine2ArchiveHTML.md +0 -13
- package/docs/formats/twine2HTML.md +0 -13
- package/docs/formats/tws.md +0 -9
- package/docs/index.html +0 -26
- package/docs/install/npm.md +0 -16
- package/docs/install/npx.md +0 -79
- package/docs/objects/passage.md +0 -47
- package/docs/objects/story.md +0 -69
- package/docs/objects/storyformat.md +0 -27
- package/eslint.config.js +0 -28
- package/extwee.config.json +0 -6
- package/extwee.config.md +0 -67
- package/jest.config.json +0 -5
- package/test/CLI/CLI.test.js +0 -49
- package/test/CLI/files/example.json +0 -1
- package/test/CLI/files/example6.twee +0 -22
- package/test/CLI/files/harlowe.js +0 -3
- package/test/CLI/files/input.html +0 -47
- package/test/CLI/files/output/test.twee +0 -0
- package/test/CLI/files/test.twee +0 -18
- package/test/CLI/files/tweeExample.twee +0 -17
- package/test/CLI/files/twine1/LICENSE.txt +0 -32
- package/test/CLI/files/twine1/code.js +0 -5
- package/test/CLI/files/twine1/engine.js +0 -43
- package/test/CLI/files/twine1/header.html +0 -325
- package/test/CLI/files/twine1Test.html +0 -371
- package/test/CLI/files/twineExample.html +0 -16
- package/test/Config/Config.test.js +0 -76
- package/test/Config/files/empty.json +0 -3
- package/test/Config/files/full.json +0 -8
- package/test/Config/files/invalid.json +0 -1
- package/test/Config/files/valid.json +0 -6
- package/test/Config/isDirectory.test.js +0 -50
- package/test/Config/isFile.test.js +0 -53
- package/test/Config/loadStoryFormat.test.js +0 -117
- package/test/Config/readDirectories.test.js +0 -78
- package/test/IFID/IFID.Generate.test.js +0 -10
- package/test/JSON/JSON.Parse.test.js +0 -316
- package/test/Objects/Passage.test.js +0 -274
- package/test/Objects/SnowmanCompatibility.test.js +0 -111
- package/test/Objects/Story.test.js +0 -1075
- package/test/Objects/StoryFormat.test.js +0 -219
- package/test/Roundtrip/Files/Example1.html +0 -64
- package/test/Roundtrip/Files/LICENSE +0 -19
- package/test/Roundtrip/Files/example1.twee +0 -10
- package/test/Roundtrip/Files/example2.twee +0 -27
- package/test/Roundtrip/Files/example4.twee +0 -27
- package/test/Roundtrip/Files/harlowe.js +0 -3
- package/test/Roundtrip/Files/round.html +0 -49
- package/test/Roundtrip/Roundtrip.test.js +0 -54
- package/test/StoryFormat/StoryFormat.Parse.test.js +0 -479
- package/test/TWS/Parse.test.js +0 -56
- package/test/TWS/TWSParser/Example5.tws +0 -414
- package/test/TWS/TWSParser/noscale.tws +0 -0
- package/test/TWS/TWSParser/nostory.tws +0 -0
- package/test/Twee/Twee.Escaping.test.js +0 -200
- package/test/Twee/Twee.Parse.test.js +0 -108
- package/test/Twee/TweeParser/cursed.twee +0 -16
- package/test/Twee/TweeParser/cycling.twee +0 -75
- package/test/Twee/TweeParser/emptytags.twee +0 -2
- package/test/Twee/TweeParser/example.twee +0 -32
- package/test/Twee/TweeParser/malformed.twee +0 -2
- package/test/Twee/TweeParser/missing.twee +0 -19
- package/test/Twee/TweeParser/multipleScriptPassages.twee +0 -19
- package/test/Twee/TweeParser/multipleStyleTag.twee +0 -19
- package/test/Twee/TweeParser/multipletags.twee +0 -10
- package/test/Twee/TweeParser/noTitle.twee +0 -2
- package/test/Twee/TweeParser/notes.twee +0 -16
- package/test/Twee/TweeParser/pasagemetadataerror.twee +0 -2
- package/test/Twee/TweeParser/scriptPassage.twee +0 -16
- package/test/Twee/TweeParser/singletag.twee +0 -13
- package/test/Twee/TweeParser/start.twee +0 -2
- package/test/Twee/TweeParser/startMetadata.twee +0 -14
- package/test/Twee/TweeParser/storydataerror.twee +0 -25
- package/test/Twee/TweeParser/style.twee +0 -16
- package/test/Twee/TweeParser/stylePassage.twee +0 -16
- package/test/Twee/TweeParser/test.twee +0 -25
- package/test/Twine1HTML/Twine1HTML.Compile.test.js +0 -180
- package/test/Twine1HTML/Twine1HTML.Parse.Web.test.js +0 -484
- package/test/Twine1HTML/Twine1HTML.Parse.test.js +0 -183
- package/test/Twine1HTML/Twine1HTMLCompiler/Twine1/LICENSE +0 -674
- package/test/Twine1HTML/Twine1HTMLCompiler/Twine1/engine.js +0 -43
- package/test/Twine1HTML/Twine1HTMLCompiler/Twine1/jquery.js +0 -4
- package/test/Twine1HTML/Twine1HTMLCompiler/Twine1/modernizr.js +0 -4
- package/test/Twine1HTML/Twine1HTMLCompiler/engineTest.html +0 -1
- package/test/Twine1HTML/Twine1HTMLCompiler/jonah-1.4.2/LICENSE +0 -32
- package/test/Twine1HTML/Twine1HTMLCompiler/jonah-1.4.2/code.js +0 -4
- package/test/Twine1HTML/Twine1HTMLCompiler/jonah-1.4.2/header.html +0 -327
- package/test/Twine1HTML/Twine1HTMLCompiler/test.html +0 -0
- package/test/Twine1HTML/Twine1HTMLCompiler/test1.html +0 -6
- package/test/Twine1HTML/Twine1HTMLCompiler/test2.html +0 -6
- package/test/Twine1HTML/Twine1HTMLCompiler/test3.html +0 -43
- package/test/Twine1HTML/Twine1HTMLCompiler/test4.html +0 -372
- package/test/Twine1HTML/Twine1HTMLCompiler/test5.html +0 -372
- package/test/Twine2ArchiveHTML/Twine2ArchiveHTML.Compile.test.js +0 -35
- package/test/Twine2ArchiveHTML/Twine2ArchiveHTML.Parse.Web.test.js +0 -293
- package/test/Twine2ArchiveHTML/Twine2ArchiveHTML.Parse.test.js +0 -42
- package/test/Twine2ArchiveHTML/Twine2ArchiveHTMLCompiler/test1.html +0 -6
- package/test/Twine2ArchiveHTML/Twine2ArchiveHTMLParser/test1.html +0 -3
- package/test/Twine2HTML/Twine2HTML.Compile.test.js +0 -139
- package/test/Twine2HTML/Twine2HTML.Parse.Web.test.js +0 -329
- package/test/Twine2HTML/Twine2HTML.Parse.test.js +0 -192
- package/test/Twine2HTML/Twine2HTMLCompiler/TestTags.html +0 -42
- package/test/Twine2HTML/Twine2HTMLCompiler/creator.html +0 -50
- package/test/Twine2HTML/Twine2HTMLCompiler/example6.twee +0 -16
- package/test/Twine2HTML/Twine2HTMLCompiler/format.js +0 -9
- package/test/Twine2HTML/Twine2HTMLCompiler/missingStoryTitle.twee +0 -29
- package/test/Twine2HTML/Twine2HTMLCompiler/test11.html +0 -121
- package/test/Twine2HTML/Twine2HTMLCompiler/test2.html +0 -58
- package/test/Twine2HTML/Twine2HTMLCompiler/test3.html +0 -49
- package/test/Twine2HTML/Twine2HTMLCompiler/test4.html +0 -50
- package/test/Twine2HTML/Twine2HTMLCompiler/test6.html +0 -49
- package/test/Twine2HTML/Twine2HTMLParser/Example1.html +0 -53
- package/test/Twine2HTML/Twine2HTMLParser/Tags.html +0 -15
- package/test/Twine2HTML/Twine2HTMLParser/lyingStartnode.html +0 -15
- package/test/Twine2HTML/Twine2HTMLParser/lyingTagColors.html +0 -48
- package/test/Twine2HTML/Twine2HTMLParser/missingCreator.html +0 -11
- package/test/Twine2HTML/Twine2HTMLParser/missingCreatorVersion.html +0 -11
- package/test/Twine2HTML/Twine2HTMLParser/missingFormat.html +0 -11
- package/test/Twine2HTML/Twine2HTMLParser/missingFormatVersion.html +0 -11
- package/test/Twine2HTML/Twine2HTMLParser/missingIFID.html +0 -11
- package/test/Twine2HTML/Twine2HTMLParser/missingPassageTags.html +0 -15
- package/test/Twine2HTML/Twine2HTMLParser/missingPosition.html +0 -15
- package/test/Twine2HTML/Twine2HTMLParser/missingScript.html +0 -14
- package/test/Twine2HTML/Twine2HTMLParser/missingSize.html +0 -35
- package/test/Twine2HTML/Twine2HTMLParser/missingStartnode.html +0 -11
- package/test/Twine2HTML/Twine2HTMLParser/missingStyle.html +0 -14
- package/test/Twine2HTML/Twine2HTMLParser/missingZoom.html +0 -11
- package/test/Twine2HTML/Twine2HTMLParser/tagColors.html +0 -31
- package/test/Twine2HTML/Twine2HTMLParser/twineExample.html +0 -23
- package/test/Twine2HTML/Twine2HTMLParser/twineExample2.html +0 -15
- package/test/Twine2HTML/Twine2HTMLParser/twineExample3.html +0 -15
- package/test/Twine2HTML/Twine2HTMLParser/unescaping.html +0 -33
- package/test/Web/web-core-coverage.test.js +0 -175
- package/test/Web/web-core-global.test.js +0 -93
- package/test/Web/web-core.test.js +0 -156
- package/test/Web/web-exports.test.js +0 -136
- package/test/Web/web-twine1html.test.js +0 -105
- package/test/Web/web-twine2archive.test.js +0 -96
- package/test/Web/web-tws.test.js +0 -77
- package/test/Web/window.Extwee.test.js +0 -97
- package/tsconfig.json +0 -21
- package/webpack.config.js +0 -47
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { readFileSync } from 'node:fs';
|
|
2
|
-
import { parse as parseTwee } from '../../src/Twee/parse.js';
|
|
3
|
-
import { parse as parseTwine2HTML } from '../../src/Twine2HTML/parse.js';
|
|
4
|
-
import { compile as compileTwine2HTML } from '../../src/Twine2HTML/compile.js';
|
|
5
|
-
import { parse as parseStoryFormat } from '../../src/StoryFormat/parse.js';
|
|
6
|
-
|
|
7
|
-
describe('Round-trip testing', () => {
|
|
8
|
-
it('Should round-trip Twine 2 HTML to Twee', () => {
|
|
9
|
-
// Read HTML.
|
|
10
|
-
const fr = readFileSync('test/Roundtrip/Files/Example1.html', 'utf-8');
|
|
11
|
-
|
|
12
|
-
// Parse HTML.
|
|
13
|
-
const s = parseTwine2HTML(fr);
|
|
14
|
-
|
|
15
|
-
// Parse the new Twee.
|
|
16
|
-
const s2 = parseTwee(s.toTwee());
|
|
17
|
-
|
|
18
|
-
// Twee adds StoryData.
|
|
19
|
-
// There will be one extra passage in Twee than HTML.
|
|
20
|
-
expect(s2.size()).toBe(s.size());
|
|
21
|
-
|
|
22
|
-
// IFID should be the same
|
|
23
|
-
expect(s.ifid).toBe(s2.ifid);
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
it('Should round-trip Twee to Twine 2 HTML', () => {
|
|
27
|
-
// Read StoryFormat.
|
|
28
|
-
const storyFormat = readFileSync('test/Roundtrip/Files/harlowe.js', 'utf-8');
|
|
29
|
-
|
|
30
|
-
// Parse StoryFormat.
|
|
31
|
-
const sfp = parseStoryFormat(storyFormat);
|
|
32
|
-
|
|
33
|
-
// Read Twee.
|
|
34
|
-
const fr = readFileSync('test/Roundtrip/Files/example2.twee', 'utf-8');
|
|
35
|
-
|
|
36
|
-
// Parse Twee.
|
|
37
|
-
const story = parseTwee(fr);
|
|
38
|
-
|
|
39
|
-
// Write HTML.
|
|
40
|
-
const fr2 = compileTwine2HTML(story, sfp);
|
|
41
|
-
|
|
42
|
-
// Parse HTML
|
|
43
|
-
const story2 = parseTwine2HTML(fr2);
|
|
44
|
-
|
|
45
|
-
// Number of passages should be the same, too
|
|
46
|
-
expect(story2.size()).toBe(story.size());
|
|
47
|
-
|
|
48
|
-
// IFID should be the same
|
|
49
|
-
expect(story.ifid).toBe(story2.ifid);
|
|
50
|
-
|
|
51
|
-
// Should have same 'start' name
|
|
52
|
-
expect(story.start).toBe(story2.start);
|
|
53
|
-
});
|
|
54
|
-
});
|
|
@@ -1,479 +0,0 @@
|
|
|
1
|
-
import {jest} from '@jest/globals';
|
|
2
|
-
import { parse as parseStoryFormat } from '../../src/StoryFormat/parse.js';
|
|
3
|
-
|
|
4
|
-
describe('StoryFormat', () => {
|
|
5
|
-
describe('parse()', () => {
|
|
6
|
-
describe('Removing setup', () => {
|
|
7
|
-
it('Should remove setup', () => {
|
|
8
|
-
const fr = 'window.storyFormat({"author":"A","description":"B","image":"C","name":"harlowe","proofing":false,"license":"MIT","source":"<html></html>","url":"example.com","version":"1.0.0","setup": function(){}});';
|
|
9
|
-
const sfp = parseStoryFormat(fr);
|
|
10
|
-
expect(sfp.name).toBe('harlowe');
|
|
11
|
-
expect(sfp.version).toBe('1.0.0');
|
|
12
|
-
expect(sfp.author).toBe('A');
|
|
13
|
-
expect(sfp.description).toBe('B');
|
|
14
|
-
expect(sfp.image).toBe('C');
|
|
15
|
-
expect(sfp.url).toBe('example.com');
|
|
16
|
-
expect(sfp.license).toBe('MIT');
|
|
17
|
-
expect(sfp.proofing).toBe(false);
|
|
18
|
-
});
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
describe('name', function () {
|
|
22
|
-
const fr = `{
|
|
23
|
-
"name": "My Story Format",
|
|
24
|
-
"version": "1.0.0",
|
|
25
|
-
"author": "Twine",
|
|
26
|
-
"description": "A story format.",
|
|
27
|
-
"image": "icon.svg",
|
|
28
|
-
"url": "https://example.com",
|
|
29
|
-
"license": "MIT",
|
|
30
|
-
"proofing": false,
|
|
31
|
-
"source": "<html></html>"
|
|
32
|
-
}`;
|
|
33
|
-
|
|
34
|
-
it('Should parse a name', () => {
|
|
35
|
-
const sfp = parseStoryFormat(fr);
|
|
36
|
-
expect(sfp.name).toBe('My Story Format');
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
it('Should detect missing name and set default', () => {
|
|
40
|
-
const copy = JSON.parse(fr);
|
|
41
|
-
delete copy.name;
|
|
42
|
-
const sfp = parseStoryFormat(JSON.stringify(copy));
|
|
43
|
-
expect(sfp.name).toBe('Untitled Story Format');
|
|
44
|
-
});
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
describe('author', function () {
|
|
48
|
-
const fr = `{
|
|
49
|
-
"name": "My Story Format",
|
|
50
|
-
"version": "1.0.0",
|
|
51
|
-
"author": "Twine",
|
|
52
|
-
"description": "A story format.",
|
|
53
|
-
"image": "icon.svg",
|
|
54
|
-
"url": "https://example.com",
|
|
55
|
-
"license": "MIT",
|
|
56
|
-
"proofing": false,
|
|
57
|
-
"source": "<html></html>"
|
|
58
|
-
}`;
|
|
59
|
-
|
|
60
|
-
it('Should parse an author', () => {
|
|
61
|
-
const sfp = parseStoryFormat(fr);
|
|
62
|
-
expect(sfp.author).toBe('Twine');
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
it('Should detect missing author and set default', () => {
|
|
66
|
-
const copy = JSON.parse(fr);
|
|
67
|
-
delete copy.author;
|
|
68
|
-
const sfp = parseStoryFormat(JSON.stringify(copy));
|
|
69
|
-
expect(sfp.author).toBe('');
|
|
70
|
-
});
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
describe('description', function () {
|
|
74
|
-
const fr = `{
|
|
75
|
-
"name": "My Story Format",
|
|
76
|
-
"version": "1.0.0",
|
|
77
|
-
"author": "Twine",
|
|
78
|
-
"description": "A story format.",
|
|
79
|
-
"image": "icon.svg",
|
|
80
|
-
"url": "https://example.com",
|
|
81
|
-
"license": "MIT",
|
|
82
|
-
"proofing": false,
|
|
83
|
-
"source": "<html></html>"
|
|
84
|
-
}`;
|
|
85
|
-
|
|
86
|
-
it('Should parse a description', () => {
|
|
87
|
-
const sfp = parseStoryFormat(fr);
|
|
88
|
-
expect(sfp.description).toBe('A story format.');
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
it('Should detect missing description and set default', () => {
|
|
92
|
-
const copy = JSON.parse(fr);
|
|
93
|
-
delete copy.description;
|
|
94
|
-
const sfp = parseStoryFormat(JSON.stringify(copy));
|
|
95
|
-
expect(sfp.description).toBe('');
|
|
96
|
-
});
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
describe('image', function () {
|
|
100
|
-
const fr = `{
|
|
101
|
-
"name": "My Story Format",
|
|
102
|
-
"version": "1.0.0",
|
|
103
|
-
"author": "Twine",
|
|
104
|
-
"description": "A story format.",
|
|
105
|
-
"image": "icon.svg",
|
|
106
|
-
"url": "https://example.com",
|
|
107
|
-
"license": "MIT",
|
|
108
|
-
"proofing": false,
|
|
109
|
-
"source": "<html></html>"
|
|
110
|
-
}`;
|
|
111
|
-
|
|
112
|
-
it('Should parse an image', () => {
|
|
113
|
-
const sfp = parseStoryFormat(fr);
|
|
114
|
-
expect(sfp.image).toBe('icon.svg');
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
it('Should detect missing image and set default', () => {
|
|
118
|
-
const copy = JSON.parse(fr);
|
|
119
|
-
delete copy.image;
|
|
120
|
-
const sfp = parseStoryFormat(JSON.stringify(copy));
|
|
121
|
-
expect(sfp.image).toBe('');
|
|
122
|
-
});
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
describe('url', function () {
|
|
126
|
-
const fr = `{
|
|
127
|
-
"name": "My Story Format",
|
|
128
|
-
"version": "1.0.0",
|
|
129
|
-
"author": "Twine",
|
|
130
|
-
"description": "A story format.",
|
|
131
|
-
"image": "icon.svg",
|
|
132
|
-
"url": "https://example.com",
|
|
133
|
-
"license": "MIT",
|
|
134
|
-
"proofing": false,
|
|
135
|
-
"source": "<html></html>"
|
|
136
|
-
}`;
|
|
137
|
-
|
|
138
|
-
it('Should parse a url', () => {
|
|
139
|
-
const sfp = parseStoryFormat(fr);
|
|
140
|
-
expect(sfp.url).toBe('https://example.com');
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
it('Should detect missing url and set default', () => {
|
|
144
|
-
const copy = JSON.parse(fr);
|
|
145
|
-
delete copy.url;
|
|
146
|
-
const sfp = parseStoryFormat(JSON.stringify(copy));
|
|
147
|
-
expect(sfp.url).toBe('');
|
|
148
|
-
});
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
describe('version', function () {
|
|
152
|
-
const fr = `{
|
|
153
|
-
"name": "My Story Format",
|
|
154
|
-
"version": "1.0.0",
|
|
155
|
-
"author": "Twine",
|
|
156
|
-
"description": "A story format.",
|
|
157
|
-
"image": "icon.svg",
|
|
158
|
-
"url": "https://example.com",
|
|
159
|
-
"license": "MIT",
|
|
160
|
-
"proofing": false,
|
|
161
|
-
"source": "<html></html>"
|
|
162
|
-
}`;
|
|
163
|
-
|
|
164
|
-
it('Should parse a version', () => {
|
|
165
|
-
const sfp = parseStoryFormat(fr);
|
|
166
|
-
expect(sfp.version).toBe('1.0.0');
|
|
167
|
-
});
|
|
168
|
-
});
|
|
169
|
-
|
|
170
|
-
describe('license', function () {
|
|
171
|
-
const fr = `{
|
|
172
|
-
"name": "My Story Format",
|
|
173
|
-
"version": "1.0.0",
|
|
174
|
-
"author": "Twine",
|
|
175
|
-
"description": "A story format.",
|
|
176
|
-
"image": "icon.svg",
|
|
177
|
-
"url": "https://example.com",
|
|
178
|
-
"license": "MIT",
|
|
179
|
-
"proofing": false,
|
|
180
|
-
"source": "<html></html>"
|
|
181
|
-
}`;
|
|
182
|
-
|
|
183
|
-
it('Should parse a license', () => {
|
|
184
|
-
const sfp = parseStoryFormat(fr);
|
|
185
|
-
expect(sfp.license).toBe('MIT');
|
|
186
|
-
});
|
|
187
|
-
|
|
188
|
-
it('Should detect missing license and set default', () => {
|
|
189
|
-
const copy = JSON.parse(fr);
|
|
190
|
-
delete copy.license;
|
|
191
|
-
const sfp = parseStoryFormat(JSON.stringify(copy));
|
|
192
|
-
expect(sfp.license).toBe('');
|
|
193
|
-
});
|
|
194
|
-
});
|
|
195
|
-
|
|
196
|
-
describe('proofing', function () {
|
|
197
|
-
const fr = `{
|
|
198
|
-
"name": "My Story Format",
|
|
199
|
-
"version": "1.0.0",
|
|
200
|
-
"author": "Twine",
|
|
201
|
-
"description": "A story format.",
|
|
202
|
-
"image": "icon.svg",
|
|
203
|
-
"url": "https://example.com",
|
|
204
|
-
"license": "MIT",
|
|
205
|
-
"proofing": true,
|
|
206
|
-
"source": "<html></html>"
|
|
207
|
-
}`;
|
|
208
|
-
|
|
209
|
-
it('Should parse proofing', () => {
|
|
210
|
-
const sfp = parseStoryFormat(fr);
|
|
211
|
-
expect(sfp.proofing).toBe(true);
|
|
212
|
-
});
|
|
213
|
-
|
|
214
|
-
it('Should detect missing proofing and set default', () => {
|
|
215
|
-
const copy = JSON.parse(fr);
|
|
216
|
-
delete copy.proofing;
|
|
217
|
-
const sfp = parseStoryFormat(JSON.stringify(copy));
|
|
218
|
-
expect(sfp.proofing).toBe(false);
|
|
219
|
-
});
|
|
220
|
-
});
|
|
221
|
-
|
|
222
|
-
describe('source', function () {
|
|
223
|
-
const fr = `{
|
|
224
|
-
"name": "My Story Format",
|
|
225
|
-
"version": "1.0.0",
|
|
226
|
-
"author": "Twine",
|
|
227
|
-
"description": "A story format.",
|
|
228
|
-
"image": "icon.svg",
|
|
229
|
-
"url": "https://example.com",
|
|
230
|
-
"license": "MIT",
|
|
231
|
-
"proofing": true,
|
|
232
|
-
"source": "<html></html>"
|
|
233
|
-
}`;
|
|
234
|
-
|
|
235
|
-
it('Should parse a source', () => {
|
|
236
|
-
const sfp = parseStoryFormat(fr);
|
|
237
|
-
expect(sfp.source).toBe('<html></html>');
|
|
238
|
-
});
|
|
239
|
-
});
|
|
240
|
-
});
|
|
241
|
-
|
|
242
|
-
describe('Errors', function () {
|
|
243
|
-
it('Should throw error if JSON missing', () => {
|
|
244
|
-
const fr = '[]';
|
|
245
|
-
expect(() => { parseStoryFormat(fr); }).toThrow();
|
|
246
|
-
});
|
|
247
|
-
|
|
248
|
-
it('Should throw error if JSON is malformed', () => {
|
|
249
|
-
const fr = '{"state"}';
|
|
250
|
-
expect(() => { parseStoryFormat(fr); }).toThrow();
|
|
251
|
-
});
|
|
252
|
-
});
|
|
253
|
-
|
|
254
|
-
describe('Warnings', () => {
|
|
255
|
-
beforeEach(() => {
|
|
256
|
-
// Mock console.warn.
|
|
257
|
-
jest.spyOn(console, 'warn').mockImplementation();
|
|
258
|
-
});
|
|
259
|
-
|
|
260
|
-
afterEach(() => {
|
|
261
|
-
// Restore all mocks.
|
|
262
|
-
jest.restoreAllMocks();
|
|
263
|
-
});
|
|
264
|
-
|
|
265
|
-
it('Should produce warning if name is not a string', () => {
|
|
266
|
-
const fr = `{
|
|
267
|
-
"name": null,
|
|
268
|
-
"version": "1.0.0",
|
|
269
|
-
"author": "Twine",
|
|
270
|
-
"description": "A story format.",
|
|
271
|
-
"image": "icon.svg",
|
|
272
|
-
"url": "https://example.com",
|
|
273
|
-
"license": "MIT",
|
|
274
|
-
"proofing": true,
|
|
275
|
-
"source": "<html></html>"
|
|
276
|
-
}`;
|
|
277
|
-
// Parse the story format.
|
|
278
|
-
parseStoryFormat(fr);
|
|
279
|
-
// Expect warning.
|
|
280
|
-
expect(console.warn).toHaveBeenCalledWith('Warning: Processed story format\'s name is not a string. It will be ignored.');
|
|
281
|
-
});
|
|
282
|
-
|
|
283
|
-
it('Should produce warning if author is not a string', () => {
|
|
284
|
-
const fr = `{
|
|
285
|
-
"name": "My Story Format",
|
|
286
|
-
"version": "1.0.0",
|
|
287
|
-
"author": null,
|
|
288
|
-
"description": "A story format.",
|
|
289
|
-
"image": "icon.svg",
|
|
290
|
-
"url": "https://example.com",
|
|
291
|
-
"license": "MIT",
|
|
292
|
-
"proofing": true,
|
|
293
|
-
"source": "<html></html>"
|
|
294
|
-
}`;
|
|
295
|
-
// Parse the story format.
|
|
296
|
-
parseStoryFormat(fr);
|
|
297
|
-
// Expect warning.
|
|
298
|
-
expect(console.warn).toHaveBeenCalledWith('Warning: Processed story format\'s author is not a string. It will be ignored.');
|
|
299
|
-
});
|
|
300
|
-
|
|
301
|
-
it('Should produce warning if description is not a string', () => {
|
|
302
|
-
const fr = `{
|
|
303
|
-
"name": "My Story Format",
|
|
304
|
-
"version": "1.0.0",
|
|
305
|
-
"author": "Twine",
|
|
306
|
-
"description": null,
|
|
307
|
-
"image": "icon.svg",
|
|
308
|
-
"url": "https://example.com",
|
|
309
|
-
"license": "MIT",
|
|
310
|
-
"proofing": true,
|
|
311
|
-
"source": "<html></html>"
|
|
312
|
-
}`;
|
|
313
|
-
// Parse the story format.
|
|
314
|
-
parseStoryFormat(fr);
|
|
315
|
-
// Expect warning.
|
|
316
|
-
expect(console.warn).toHaveBeenCalledWith('Warning: Processed story format\'s description is not a string. It will be ignored.');
|
|
317
|
-
});
|
|
318
|
-
|
|
319
|
-
it('Should produce warning if image is not a string', () => {
|
|
320
|
-
const fr = `{
|
|
321
|
-
"name": "My Story Format",
|
|
322
|
-
"version": "1.0.0",
|
|
323
|
-
"author": "Twine",
|
|
324
|
-
"description": "A story format.",
|
|
325
|
-
"image": null,
|
|
326
|
-
"url": "https://example.com",
|
|
327
|
-
"license": "MIT",
|
|
328
|
-
"proofing": true,
|
|
329
|
-
"source": "<html></html>"
|
|
330
|
-
}`;
|
|
331
|
-
// Parse the story format.
|
|
332
|
-
parseStoryFormat(fr);
|
|
333
|
-
// Expect warning.
|
|
334
|
-
expect(console.warn).toHaveBeenCalledWith('Warning: Processed story format\'s image is not a string. It will be ignored.');
|
|
335
|
-
});
|
|
336
|
-
|
|
337
|
-
it('Should produce warning if url is not a string', () => {
|
|
338
|
-
const fr = `{
|
|
339
|
-
"name": "My Story Format",
|
|
340
|
-
"version": "1.0.0",
|
|
341
|
-
"author": "Twine",
|
|
342
|
-
"description": "A story format.",
|
|
343
|
-
"image": "icon.svg",
|
|
344
|
-
"url": null,
|
|
345
|
-
"license": "MIT",
|
|
346
|
-
"proofing": true,
|
|
347
|
-
"source": "<html></html>"
|
|
348
|
-
}`;
|
|
349
|
-
// Parse the story format.
|
|
350
|
-
parseStoryFormat(fr);
|
|
351
|
-
// Expect warning.
|
|
352
|
-
expect(console.warn).toHaveBeenCalledWith('Warning: Processed story format\'s url is not a string. It will be ignored.');
|
|
353
|
-
});
|
|
354
|
-
|
|
355
|
-
it('Should produce warning if license is not a string', () => {
|
|
356
|
-
const fr = `{
|
|
357
|
-
"name": "My Story Format",
|
|
358
|
-
"version": "1.0.0",
|
|
359
|
-
"author": "Twine",
|
|
360
|
-
"description": "A story format.",
|
|
361
|
-
"image": "icon.svg",
|
|
362
|
-
"url": "https://example.com",
|
|
363
|
-
"license": null,
|
|
364
|
-
"proofing": true,
|
|
365
|
-
"source": "<html></html>"
|
|
366
|
-
}`;
|
|
367
|
-
// Parse the story format.
|
|
368
|
-
parseStoryFormat(fr);
|
|
369
|
-
// Expect warning.
|
|
370
|
-
expect(console.warn).toHaveBeenCalledWith('Warning: Processed story format\'s license is not a string. It will be ignored.');
|
|
371
|
-
});
|
|
372
|
-
|
|
373
|
-
it('Should produce warning if proofing is not a boolean', () => {
|
|
374
|
-
const fr = `{
|
|
375
|
-
"name": "My Story Format",
|
|
376
|
-
"version": "1.0.0",
|
|
377
|
-
"author": "Twine",
|
|
378
|
-
"description": "A story format.",
|
|
379
|
-
"image": "icon.svg",
|
|
380
|
-
"url": "https://example.com",
|
|
381
|
-
"license": "MIT",
|
|
382
|
-
"proofing": null,
|
|
383
|
-
"source": "<html></html>"
|
|
384
|
-
}`;
|
|
385
|
-
// Parse the story format.
|
|
386
|
-
parseStoryFormat(fr);
|
|
387
|
-
// Expect warning.
|
|
388
|
-
expect(console.warn).toHaveBeenCalledWith('Warning: Processed story format\'s proofing is not a boolean. It will be ignored.');
|
|
389
|
-
});
|
|
390
|
-
|
|
391
|
-
it('Should produce warning if source is not a string', () => {
|
|
392
|
-
const fr = `{
|
|
393
|
-
"name": "My Story Format",
|
|
394
|
-
"version": "1.0.0",
|
|
395
|
-
"author": "Twine",
|
|
396
|
-
"description": "A story format.",
|
|
397
|
-
"image": "icon.svg",
|
|
398
|
-
"url": "https://example.com",
|
|
399
|
-
"license": "MIT",
|
|
400
|
-
"proofing": true,
|
|
401
|
-
"source": null
|
|
402
|
-
}`;
|
|
403
|
-
// Parse the story format.
|
|
404
|
-
parseStoryFormat(fr);
|
|
405
|
-
// Expect warning.
|
|
406
|
-
expect(console.warn).toHaveBeenCalledWith('Warning: Processed story format\'s source is not a string! It will be ignored.');
|
|
407
|
-
});
|
|
408
|
-
|
|
409
|
-
it('Should produce warning if source is missing', () => {
|
|
410
|
-
const fr = `{
|
|
411
|
-
"name": "My Story Format",
|
|
412
|
-
"version": "1.0.0",
|
|
413
|
-
"author": "Twine",
|
|
414
|
-
"description": "A story format.",
|
|
415
|
-
"image": "icon.svg",
|
|
416
|
-
"url": "https://example.com",
|
|
417
|
-
"license": "MIT",
|
|
418
|
-
"proofing": true
|
|
419
|
-
}`;
|
|
420
|
-
// Parse the story format.
|
|
421
|
-
parseStoryFormat(fr);
|
|
422
|
-
// Expect warning.
|
|
423
|
-
expect(console.warn).toHaveBeenCalledWith('Warning: Processed story format does not have source property!');
|
|
424
|
-
});
|
|
425
|
-
|
|
426
|
-
it('Should produce warning if version is not a string', () => {
|
|
427
|
-
const fr = `{
|
|
428
|
-
"name": "My Story Format",
|
|
429
|
-
"version": null,
|
|
430
|
-
"author": "Twine",
|
|
431
|
-
"description": "A story format.",
|
|
432
|
-
"image": "icon.svg",
|
|
433
|
-
"url": "https://example.com",
|
|
434
|
-
"license": "MIT",
|
|
435
|
-
"proofing": true,
|
|
436
|
-
"source": "<html></html>"
|
|
437
|
-
}`;
|
|
438
|
-
// Parse the story format.
|
|
439
|
-
parseStoryFormat(fr);
|
|
440
|
-
// Expect warning.
|
|
441
|
-
expect(console.warn).toHaveBeenCalledWith('Warning: Processed story format\'s version is not a string! It will be ignored.');
|
|
442
|
-
});
|
|
443
|
-
|
|
444
|
-
it('Should produce warning if version is not semantic', () => {
|
|
445
|
-
const fr = `{
|
|
446
|
-
"name": "My Story Format",
|
|
447
|
-
"version": "fake version",
|
|
448
|
-
"author": "Twine",
|
|
449
|
-
"description": "A story format.",
|
|
450
|
-
"image": "icon.svg",
|
|
451
|
-
"url": "https://example.com",
|
|
452
|
-
"license": "MIT",
|
|
453
|
-
"proofing": true,
|
|
454
|
-
"source": "<html></html>"
|
|
455
|
-
}`;
|
|
456
|
-
// Parse the story format.
|
|
457
|
-
parseStoryFormat(fr);
|
|
458
|
-
// Expect warning.
|
|
459
|
-
expect(console.warn).toHaveBeenCalledWith('Warning: Processed story format\'s version is not semantic! It will be ignored.');
|
|
460
|
-
});
|
|
461
|
-
|
|
462
|
-
it('Should produce warning if version is missing', () => {
|
|
463
|
-
const fr = `{
|
|
464
|
-
"name": "My Story Format",
|
|
465
|
-
"author": "Twine",
|
|
466
|
-
"description": "A story format.",
|
|
467
|
-
"image": "icon.svg",
|
|
468
|
-
"url": "https://example.com",
|
|
469
|
-
"license": "MIT",
|
|
470
|
-
"proofing": true,
|
|
471
|
-
"source": "<html></html>"
|
|
472
|
-
}`;
|
|
473
|
-
// Parse the story format.
|
|
474
|
-
parseStoryFormat(fr);
|
|
475
|
-
// Expect warning.
|
|
476
|
-
expect(console.warn).toHaveBeenCalledWith('Warning: Processed story format does not have version property!');
|
|
477
|
-
});
|
|
478
|
-
});
|
|
479
|
-
});
|
package/test/TWS/Parse.test.js
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import fs from 'node:fs';
|
|
2
|
-
import { parse as parseTWS } from '../../src/TWS/parse.js';
|
|
3
|
-
|
|
4
|
-
describe('TWSParser', () => {
|
|
5
|
-
describe('#parse()', () => {
|
|
6
|
-
it('Should throw error if input is not Buffer', function () {
|
|
7
|
-
expect(() => { parseTWS(0); }).toThrow();
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
describe('Passage parsing', function () {
|
|
11
|
-
let r = null;
|
|
12
|
-
|
|
13
|
-
beforeAll(() => {
|
|
14
|
-
const contents = fs.readFileSync('test/TWS/TWSParser/Example5.tws', 'binary');
|
|
15
|
-
const b = Buffer.from(contents, 'binary');
|
|
16
|
-
r = parseTWS(b);
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
it('Should parse passage - tags', function () {
|
|
20
|
-
const p = r.getPassageByName('Untitled Passage 1');
|
|
21
|
-
expect(p.tags.length).toBe(3);
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
it('Should parse passage - text', function () {
|
|
25
|
-
const p = r.getPassageByName('Untitled Passage 2');
|
|
26
|
-
expect(p.text).toBe('dd');
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
it('Should set Story start (to start passage)', function () {
|
|
30
|
-
expect(r.start).toBe('Start');
|
|
31
|
-
});
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
describe('Exceptions and parsing issues', function () {
|
|
35
|
-
it('Should throw error if parsing a Buffer but not pickle data', function () {
|
|
36
|
-
const contents = 'Test';
|
|
37
|
-
const b = Buffer.from(contents);
|
|
38
|
-
expect(() => { parseTWS(b); }).toThrow();
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
it('Should create default Story object if pickle data but not TWS data', function () {
|
|
42
|
-
const contents = fs.readFileSync('test/TWS/TWSParser/nostory.tws', 'binary');
|
|
43
|
-
const b = Buffer.from(contents, 'binary');
|
|
44
|
-
const r = parseTWS(b);
|
|
45
|
-
expect(r.size()).toBe(0);
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it('Should parse storyPanel but no scale', function () {
|
|
49
|
-
const contents = fs.readFileSync('test/TWS/TWSParser/noscale.tws', 'binary');
|
|
50
|
-
const b = Buffer.from(contents, 'binary');
|
|
51
|
-
const r = parseTWS(b);
|
|
52
|
-
expect(r.zoom).toBe(1);
|
|
53
|
-
});
|
|
54
|
-
});
|
|
55
|
-
});
|
|
56
|
-
});
|