extwee 1.6.0 → 2.0.2
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 -0
- package/.github/workflows/nodejs.yml +24 -25
- package/.travis.yml +13 -13
- package/CODE_OF_CONDUCT.md +82 -0
- package/LICENSE +21 -21
- package/README.md +36 -205
- package/SECURITY.md +12 -0
- package/babel.config.json +22 -0
- package/bin/extwee.js +49 -0
- package/index.js +31 -26
- package/package.json +59 -37
- package/src/FileReader.js +33 -36
- package/src/HTMLParser.js +343 -206
- package/src/HTMLWriter.js +227 -177
- package/src/Passage.js +202 -20
- package/src/Story.js +461 -148
- package/src/StoryFormat.js +300 -41
- package/src/StoryFormatParser.js +142 -65
- package/src/TweeParser.js +161 -255
- package/src/TweeWriter.js +98 -111
- package/story-formats/chapbook-1.2.0/format.js +1 -0
- package/story-formats/chapbook-1.2.0/logo.svg +1 -0
- package/story-formats/harlowe-1.2.4/format.js +1 -0
- package/story-formats/harlowe-1.2.4/icon.svg +78 -0
- package/story-formats/harlowe-2.1.0/format.js +2 -0
- package/story-formats/harlowe-2.1.0/icon.svg +78 -0
- package/story-formats/harlowe-3.1.0/format.js +3 -0
- package/story-formats/harlowe-3.1.0/icon.svg +78 -0
- package/story-formats/paperthin-1.0.0/format.js +1 -0
- package/story-formats/paperthin-1.0.0/icon.svg +5 -0
- package/story-formats/snowman-1.4.0/format.js +1 -0
- package/story-formats/snowman-1.4.0/icon.svg +436 -0
- package/story-formats/snowman-2.0.2/format.js +1 -0
- package/story-formats/snowman-2.0.2/icon.svg +436 -0
- package/story-formats/sugarcube-1.0.35/LICENSE +23 -0
- package/story-formats/sugarcube-1.0.35/format.js +1 -0
- package/story-formats/sugarcube-1.0.35/icon.svg +56 -0
- package/story-formats/sugarcube-2.31.1/LICENSE +22 -0
- package/story-formats/sugarcube-2.31.1/format.js +1 -0
- package/story-formats/sugarcube-2.31.1/icon.svg +56 -0
- package/test/{HTMLWriter/example7.twee → CLI/example6.twee} +16 -16
- package/test/CLI/harlowe.js +3 -0
- package/test/CLI/input.html +47 -0
- package/test/CLI/test.twee +18 -0
- package/test/CLI/test2.html +47 -0
- package/test/CLI/tweeExample.twee +17 -0
- package/test/CLI/twineExample.html +15 -0
- package/test/CLI.test.js +30 -0
- package/test/FileReader.test.js +14 -0
- package/test/HTMLParser/Example1.html +53 -0
- package/test/HTMLParser/Tags.html +15 -0
- package/test/HTMLParser/lyingStartnode.html +15 -0
- package/test/HTMLParser/lyingTagColors.html +48 -0
- package/test/HTMLParser/missingCreator.html +11 -0
- package/test/HTMLParser/missingCreatorVersion.html +11 -0
- package/test/HTMLParser/missingFormat.html +11 -0
- package/test/HTMLParser/missingFormatVersion.html +11 -0
- package/test/HTMLParser/missingIFID.html +11 -0
- package/test/HTMLParser/missingName.html +33 -0
- package/test/HTMLParser/missingPID.html +15 -0
- package/test/HTMLParser/missingPassageName.html +15 -0
- package/test/HTMLParser/missingPassageTags.html +15 -0
- package/test/HTMLParser/missingPosition.html +15 -0
- package/test/HTMLParser/missingScript.html +14 -0
- package/test/HTMLParser/missingSize.html +35 -0
- package/test/HTMLParser/missingStartnode.html +11 -0
- package/test/HTMLParser/missingStyle.html +14 -0
- package/test/HTMLParser/missingZoom.html +11 -0
- package/test/HTMLParser/tagColors.html +31 -0
- package/test/HTMLParser/twineExample.html +15 -46
- package/test/HTMLParser/twineExample2.html +15 -0
- package/test/HTMLParser/twineExample3.html +15 -0
- package/test/HTMLParser.test.js +177 -0
- package/test/HTMLWriter/TestTags.html +42 -0
- package/test/HTMLWriter/{test10.html → creator.html} +8 -5
- package/test/HTMLWriter/example6.twee +16 -16
- package/test/HTMLWriter/{example.twee → missingStoryTitle.twee} +29 -29
- package/test/HTMLWriter/test11.html +123 -0
- package/test/HTMLWriter/test2.html +15 -12
- package/test/HTMLWriter/test3.html +7 -13
- package/test/HTMLWriter/test4.html +8 -5
- package/test/HTMLWriter/test6.html +7 -5
- package/test/HTMLWriter.test.js +289 -0
- package/test/Passage.test.js +104 -0
- package/test/Roundtrip/Example1.html +64 -0
- package/test/Roundtrip/example1.twee +21 -0
- package/test/Roundtrip/example2.twee +18 -0
- package/test/Roundtrip/harlowe.js +3 -0
- package/test/Roundtrip/round.html +50 -0
- package/test/Roundtrip.test.js +48 -0
- package/test/Story/startmeta.twee +29 -29
- package/test/Story/test.twee +25 -25
- package/test/Story.test.js +282 -0
- package/test/StoryFormat.test.js +152 -0
- package/test/StoryFormatParser/example.js +3 -0
- package/test/StoryFormatParser/{test2.js → example2.js} +3 -3
- package/test/StoryFormatParser/format_doublename.js +1 -0
- package/test/StoryFormatParser/harlowe.js +2 -2
- package/test/StoryFormatParser/missingAuthor.js +1 -0
- package/test/StoryFormatParser/missingDescription.js +1 -0
- package/test/StoryFormatParser/missingImage.js +1 -0
- package/test/StoryFormatParser/missingLicense.js +1 -0
- package/test/StoryFormatParser/missingName.js +1 -0
- package/test/StoryFormatParser/missingProofing.js +1 -0
- package/test/StoryFormatParser/missingSource.js +1 -0
- package/test/StoryFormatParser/missingURL.js +1 -0
- package/test/StoryFormatParser/missingVersion.js +1 -0
- package/test/StoryFormatParser/versionWrong.js +1 -0
- package/test/StoryFormatParser.test.js +91 -0
- package/test/TweeParser/emptytags.twee +2 -2
- package/test/TweeParser/example.twee +32 -29
- package/test/TweeParser/missing.twee +19 -0
- package/test/{HTMLWriter/example5.twee → TweeParser/multipleScriptPassages.twee} +19 -13
- package/test/{HTMLWriter/example4.twee → TweeParser/multipleStyleTag.twee} +19 -13
- package/test/TweeParser/multipletags.twee +10 -2
- package/test/TweeParser/noTitle.twee +2 -0
- package/test/TweeParser/notes.twee +16 -0
- package/test/TweeParser/pasagemetadataerror.twee +2 -2
- package/test/{HTMLWriter/example2.twee → TweeParser/scriptPassage.twee} +16 -13
- package/test/TweeParser/singletag.twee +13 -2
- package/test/TweeParser/startMetadata.twee +14 -0
- package/test/TweeParser/storydataerror.twee +25 -25
- package/test/{HTMLWriter/example3.twee → TweeParser/stylePassage.twee} +16 -13
- package/test/TweeParser/test.twee +25 -25
- package/test/TweeParser.test.js +79 -0
- package/test/TweeWriter/test1.twee +14 -9
- package/test/TweeWriter/test3.twee +7 -10
- package/test/TweeWriter/test4.twee +14 -0
- package/test/TweeWriter/test5.twee +20 -0
- package/test/TweeWriter.test.js +85 -0
- package/main.js +0 -106
- package/src/DirectoryReader.js +0 -107
- package/src/DirectoryWatcher.js +0 -92
- package/test/DirectoryReader/css/test.css +0 -3
- package/test/DirectoryReader1/js/Site.js +0 -1
- package/test/DirectoryReader2/error.js +0 -1
- package/test/DirectoryReader2/example.css +0 -3
- package/test/DirectoryReader2/index.twee +0 -6
- package/test/DirectoryReader3/twee/index.twee +0 -6
- package/test/DirectoryWatcher/example.txt +0 -0
- package/test/DirectoryWatcher/test.txt +0 -0
- package/test/DirectoryWatcher/test1.txt +0 -0
- package/test/HTMLWriter/test5.html +0 -48
- package/test/HTMLWriter/test7.html +0 -48
- package/test/HTMLWriter/test8.html +0 -48
- package/test/HTMLWriter/test9.html +0 -48
- package/test/StoryFormatParser/test.js +0 -2
- package/test/TweeParser/test.twee3 +0 -11
- package/test/TweeWriter/metatest.twee +0 -12
- package/test/TweeWriter/test2.twee +0 -15
- package/test/test.js +0 -722
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import TweeWriter from '../src/TweeWriter.js';
|
|
2
|
+
import FileReader from '../src/FileReader.js';
|
|
3
|
+
import TweeParser from '../src/TweeParser.js';
|
|
4
|
+
import HTMLParser from '../src/HTMLParser.js';
|
|
5
|
+
import StoryFormatParser from '../src/StoryFormatParser.js';
|
|
6
|
+
import HTMLWriter from '../src/HTMLWriter.js';
|
|
7
|
+
|
|
8
|
+
describe('Round-trip testing', () => {
|
|
9
|
+
test('Should round-trip HTML-to-Twee', () => {
|
|
10
|
+
// Read HTML
|
|
11
|
+
const fr = FileReader.read('test/Roundtrip/Example1.html');
|
|
12
|
+
// Parse HTML
|
|
13
|
+
const s = HTMLParser.parse(fr);
|
|
14
|
+
// Write Story into Twee
|
|
15
|
+
TweeWriter.write(s, 'test/Roundtrip/example1.twee');
|
|
16
|
+
// Read new Twee file
|
|
17
|
+
const fr2 = FileReader.read('test/Roundtrip/example1.twee');
|
|
18
|
+
// Parse the new Twee
|
|
19
|
+
const s2 = TweeParser.parse(fr2);
|
|
20
|
+
// Number of passages should be the same, too
|
|
21
|
+
expect(s2.size()).toBe(s.size());
|
|
22
|
+
// IFID should be the same
|
|
23
|
+
expect(s.ifid).toBe(s2.ifid);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
test('Should round-trip Twee-to-HTML', () => {
|
|
27
|
+
// Read StoryFormat
|
|
28
|
+
const storyFormat = FileReader.read('test/Roundtrip/harlowe.js');
|
|
29
|
+
// Parse StoryFormat
|
|
30
|
+
const sfp = StoryFormatParser.parse(storyFormat);
|
|
31
|
+
// Read Twee
|
|
32
|
+
const fr = FileReader.read('test/Roundtrip/example2.twee');
|
|
33
|
+
// Parse Twee
|
|
34
|
+
const story = TweeParser.parse(fr);
|
|
35
|
+
// Write HTML
|
|
36
|
+
HTMLWriter.write('test/Roundtrip/round.html', story, sfp);
|
|
37
|
+
// Read HTML
|
|
38
|
+
const fr2 = FileReader.read('test/Roundtrip/round.html');
|
|
39
|
+
// Parse HTML
|
|
40
|
+
const story2 = HTMLParser.parse(fr2);
|
|
41
|
+
// Number of passages should be the same, too
|
|
42
|
+
expect(story2.size()).toBe(story.size());
|
|
43
|
+
// IFID should be the same
|
|
44
|
+
expect(story.ifid).toBe(story2.ifid);
|
|
45
|
+
// Should have same 'start' name
|
|
46
|
+
expect(story.start).toBe(story2.start);
|
|
47
|
+
});
|
|
48
|
+
});
|
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
:: StoryTitle
|
|
2
|
-
twineExample
|
|
3
|
-
|
|
4
|
-
:: Another
|
|
5
|
-
This should be the start passage!
|
|
6
|
-
|
|
7
|
-
:: Start
|
|
8
|
-
Some content.
|
|
9
|
-
|
|
10
|
-
:: StoryData
|
|
11
|
-
{
|
|
12
|
-
"ifid": "2B68ECD6-348F-4CF5-96F8-549A512A8128",
|
|
13
|
-
"format": "Harlowe",
|
|
14
|
-
"formatVersion": "2.1.0",
|
|
15
|
-
"zoom": "1",
|
|
16
|
-
"start": "Another"
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
:: Script1 [script]
|
|
20
|
-
// Some code
|
|
21
|
-
|
|
22
|
-
:: Script2 [script]
|
|
23
|
-
//More code here!
|
|
24
|
-
|
|
25
|
-
:: Style1 [stylesheet]
|
|
26
|
-
body {font-size: 1.2em}
|
|
27
|
-
|
|
28
|
-
:: Style2 [stylesheet]
|
|
29
|
-
p {font-style: italic;}
|
|
1
|
+
:: StoryTitle
|
|
2
|
+
twineExample
|
|
3
|
+
|
|
4
|
+
:: Another
|
|
5
|
+
This should be the start passage!
|
|
6
|
+
|
|
7
|
+
:: Start
|
|
8
|
+
Some content.
|
|
9
|
+
|
|
10
|
+
:: StoryData
|
|
11
|
+
{
|
|
12
|
+
"ifid": "2B68ECD6-348F-4CF5-96F8-549A512A8128",
|
|
13
|
+
"format": "Harlowe",
|
|
14
|
+
"formatVersion": "2.1.0",
|
|
15
|
+
"zoom": "1",
|
|
16
|
+
"start": "Another"
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
:: Script1 [script]
|
|
20
|
+
// Some code
|
|
21
|
+
|
|
22
|
+
:: Script2 [script]
|
|
23
|
+
//More code here!
|
|
24
|
+
|
|
25
|
+
:: Style1 [stylesheet]
|
|
26
|
+
body {font-size: 1.2em}
|
|
27
|
+
|
|
28
|
+
:: Style2 [stylesheet]
|
|
29
|
+
p {font-style: italic;}
|
package/test/Story/test.twee
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
:: StoryTitle
|
|
2
|
-
twineExample
|
|
3
|
-
|
|
4
|
-
:: Start
|
|
5
|
-
Some content.
|
|
6
|
-
|
|
7
|
-
:: StoryData
|
|
8
|
-
{
|
|
9
|
-
"ifid": "2B68ECD6-348F-4CF5-96F8-549A512A8128",
|
|
10
|
-
"format": "Harlowe",
|
|
11
|
-
"formatVersion": "2.1.0",
|
|
12
|
-
"zoom": "1"
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
:: Script1 [script]
|
|
16
|
-
// Some code
|
|
17
|
-
|
|
18
|
-
:: Script2 [script]
|
|
19
|
-
//More code here!
|
|
20
|
-
|
|
21
|
-
:: Style1 [stylesheet]
|
|
22
|
-
body {font-size: 1.2em}
|
|
23
|
-
|
|
24
|
-
:: Style2 [stylesheet]
|
|
25
|
-
p {font-style: italic;}
|
|
1
|
+
:: StoryTitle
|
|
2
|
+
twineExample
|
|
3
|
+
|
|
4
|
+
:: Start
|
|
5
|
+
Some content.
|
|
6
|
+
|
|
7
|
+
:: StoryData
|
|
8
|
+
{
|
|
9
|
+
"ifid": "2B68ECD6-348F-4CF5-96F8-549A512A8128",
|
|
10
|
+
"format": "Harlowe",
|
|
11
|
+
"formatVersion": "2.1.0",
|
|
12
|
+
"zoom": "1"
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
:: Script1 [script]
|
|
16
|
+
// Some code
|
|
17
|
+
|
|
18
|
+
:: Script2 [script]
|
|
19
|
+
//More code here!
|
|
20
|
+
|
|
21
|
+
:: Style1 [stylesheet]
|
|
22
|
+
body {font-size: 1.2em}
|
|
23
|
+
|
|
24
|
+
:: Style2 [stylesheet]
|
|
25
|
+
p {font-style: italic;}
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
import Story from '../src/Story.js';
|
|
2
|
+
import Passage from '../src/Passage';
|
|
3
|
+
import FileReader from '../src/FileReader.js';
|
|
4
|
+
|
|
5
|
+
// Pull the name and version of this project from package.json.
|
|
6
|
+
// These are used as the 'creator' and 'creator-version'.
|
|
7
|
+
const { name, version } = JSON.parse(FileReader.read('package.json'));
|
|
8
|
+
|
|
9
|
+
describe('Story', function () {
|
|
10
|
+
describe('#constructor()', function () {
|
|
11
|
+
test('Should have extwee name', function () {
|
|
12
|
+
const s = new Story();
|
|
13
|
+
expect(s.creator).toBe(name);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
test('Should have extwee version', function () {
|
|
17
|
+
const s = new Story();
|
|
18
|
+
expect(s.creatorVersion).toBe(version);
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
describe('creator', function () {
|
|
23
|
+
test('Set using String', function () {
|
|
24
|
+
const s = new Story();
|
|
25
|
+
s.creator = 'New';
|
|
26
|
+
expect(s.creator).toBe('New');
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
test('Should throw error if not String', function () {
|
|
30
|
+
const s = new Story();
|
|
31
|
+
expect(() => {
|
|
32
|
+
s.creator = 1;
|
|
33
|
+
}).toThrow();
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
describe('creatorVersion', function () {
|
|
38
|
+
test('Set using String', function () {
|
|
39
|
+
const s = new Story();
|
|
40
|
+
s.creatorVersion = 'New';
|
|
41
|
+
expect(s.creatorVersion).toBe('New');
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
test('Should throw error if not String', function () {
|
|
45
|
+
const s = new Story();
|
|
46
|
+
expect(() => {
|
|
47
|
+
s.creatorVersion = 1;
|
|
48
|
+
}).toThrow();
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
describe('IFID', function () {
|
|
53
|
+
test('Set using String', function () {
|
|
54
|
+
const s = new Story();
|
|
55
|
+
s.IFID = 'New';
|
|
56
|
+
expect(s.IFID).toBe('New');
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
test('Should throw error if not String', function () {
|
|
60
|
+
const s = new Story();
|
|
61
|
+
expect(() => {
|
|
62
|
+
s.IFID = 1;
|
|
63
|
+
}).toThrow();
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
describe('format', function () {
|
|
68
|
+
test('Set using String', function () {
|
|
69
|
+
const s = new Story();
|
|
70
|
+
s.format = 'New';
|
|
71
|
+
expect(s.format).toBe('New');
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
test('Should throw error if not String', function () {
|
|
75
|
+
const s = new Story();
|
|
76
|
+
expect(() => {
|
|
77
|
+
s.format = 1;
|
|
78
|
+
}).toThrow();
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
describe('formatVersion', function () {
|
|
83
|
+
test('Set using String', function () {
|
|
84
|
+
const s = new Story();
|
|
85
|
+
s.formatVersion = 'New';
|
|
86
|
+
expect(s.formatVersion).toBe('New');
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
test('Should throw error if not String', function () {
|
|
90
|
+
const s = new Story();
|
|
91
|
+
expect(() => {
|
|
92
|
+
s.formatVersion = 1;
|
|
93
|
+
}).toThrow();
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
describe('zoom', function () {
|
|
98
|
+
test('Set using Number', function () {
|
|
99
|
+
const s = new Story();
|
|
100
|
+
s.zoom = 1.0;
|
|
101
|
+
expect(s.zoom).not.toBe(0);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
test('Should throw error if not String', function () {
|
|
105
|
+
const s = new Story();
|
|
106
|
+
expect(() => {
|
|
107
|
+
s.zoom = null;
|
|
108
|
+
}).toThrow();
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
describe('metadata', function () {
|
|
113
|
+
test('Set metadata', function () {
|
|
114
|
+
const s = new Story();
|
|
115
|
+
s.metadata = {};
|
|
116
|
+
expect(s.metadata).not.toBe(null);
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
test('Should throw error if not object', function () {
|
|
120
|
+
const s = new Story();
|
|
121
|
+
expect(() => {
|
|
122
|
+
s.metadata = 1;
|
|
123
|
+
}).toThrow();
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
describe('start', function () {
|
|
128
|
+
test('Set start', function () {
|
|
129
|
+
const s = new Story();
|
|
130
|
+
s.start = 'Start';
|
|
131
|
+
expect(s.start).not.toBe('');
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
test('Should throw error if not String', function () {
|
|
135
|
+
const s = new Story();
|
|
136
|
+
expect(() => {
|
|
137
|
+
s.start = 1;
|
|
138
|
+
}).toThrow();
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
describe('tagColors', function () {
|
|
143
|
+
test('Set tagColors', function () {
|
|
144
|
+
const s = new Story();
|
|
145
|
+
s.tagColors = {
|
|
146
|
+
bar: 'green'
|
|
147
|
+
};
|
|
148
|
+
const count = Object.keys(s.tagColors).length;
|
|
149
|
+
expect(count).toBe(1);
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
test('Should throw error if not object', function () {
|
|
153
|
+
const s = new Story();
|
|
154
|
+
expect(() => {
|
|
155
|
+
s.tagColors = null;
|
|
156
|
+
}).toThrow();
|
|
157
|
+
});
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
describe('addPassage()', function () {
|
|
161
|
+
test('addPassage() - should increase size', function () {
|
|
162
|
+
const s = new Story();
|
|
163
|
+
const p = new Passage();
|
|
164
|
+
s.addPassage(p);
|
|
165
|
+
expect(s.size()).toBe(1);
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
test('addPassage() - should throw error if non-Passage', function () {
|
|
169
|
+
const s = new Story();
|
|
170
|
+
expect(() => {
|
|
171
|
+
s.addPassage(null);
|
|
172
|
+
}).toThrow();
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
test('addPassage() - should prevent passages with same name being added', function () {
|
|
176
|
+
const s = new Story();
|
|
177
|
+
const p = new Passage('A');
|
|
178
|
+
const p2 = new Passage('A');
|
|
179
|
+
s.addPassage(p);
|
|
180
|
+
s.addPassage(p2);
|
|
181
|
+
expect(s.size()).toBe(1);
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
describe('removePassage()', function () {
|
|
186
|
+
test('removePassage() - should decrease size', function () {
|
|
187
|
+
const s = new Story();
|
|
188
|
+
s.addPassage(new Passage('Find'));
|
|
189
|
+
s.addPassage(new Passage('Find2'));
|
|
190
|
+
s.removePassage('Find');
|
|
191
|
+
expect(s.size()).toBe(1);
|
|
192
|
+
});
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
describe('getPassagesByTag()', function () {
|
|
196
|
+
test('getPassagesByTag() - should find passages', function () {
|
|
197
|
+
const s = new Story();
|
|
198
|
+
const p = new Passage('Find', '', ['one']);
|
|
199
|
+
const p2 = new Passage('Find2', '', ['one']);
|
|
200
|
+
s.addPassage(p);
|
|
201
|
+
s.addPassage(p2);
|
|
202
|
+
const ps = s.getPassagesByTag('one');
|
|
203
|
+
expect(ps).toHaveLength(2);
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
test('getPassagesByTag() - should find none if none in collection', function () {
|
|
207
|
+
const s = new Story();
|
|
208
|
+
const ps = s.getPassagesByTag('one');
|
|
209
|
+
expect(ps).toHaveLength(0);
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
test('getPassagesByTag() - should find none if no tags match search', function () {
|
|
213
|
+
const s = new Story();
|
|
214
|
+
const p = new Passage('Find', '', ['one']);
|
|
215
|
+
const p2 = new Passage('Find2', '', ['one']);
|
|
216
|
+
s.addPassage(p);
|
|
217
|
+
s.addPassage(p2);
|
|
218
|
+
const ps = s.getPassagesByTag('two');
|
|
219
|
+
expect(ps).toHaveLength(0);
|
|
220
|
+
});
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
describe('getPassageByName()', function () {
|
|
224
|
+
test('getPassageByName() - should get passage by name', function () {
|
|
225
|
+
const s = new Story();
|
|
226
|
+
const p = new Passage('Find');
|
|
227
|
+
s.addPassage(p);
|
|
228
|
+
const passage = s.getPassageByName('Find');
|
|
229
|
+
expect(passage.name).toBe('Find');
|
|
230
|
+
});
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
describe('getPassageByPID()', function () {
|
|
234
|
+
test('getPassageByPID() - should get passage by PID', function () {
|
|
235
|
+
const s = new Story();
|
|
236
|
+
const p = new Passage('Find', '', [], {}, 12);
|
|
237
|
+
s.addPassage(p);
|
|
238
|
+
const passage = s.getPassageByPID(12);
|
|
239
|
+
expect(passage.name).toBe('Find');
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
test('getPassageByPID() - should return null if not found', function () {
|
|
243
|
+
const s = new Story();
|
|
244
|
+
expect(s.getPassageByPID(12)).toBe(null);
|
|
245
|
+
});
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
describe('forEach()', function () {
|
|
249
|
+
test('forEach() - should return if non-function', function () {
|
|
250
|
+
const s = new Story();
|
|
251
|
+
s.addPassage(new Passage('A'));
|
|
252
|
+
s.addPassage(new Passage('B'));
|
|
253
|
+
let passageNames = '';
|
|
254
|
+
s.forEach((p) => {
|
|
255
|
+
passageNames += p.name;
|
|
256
|
+
});
|
|
257
|
+
expect(passageNames).toBe('AB');
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
test('forEach() - should throw error if non-function', function () {
|
|
261
|
+
const s = new Story();
|
|
262
|
+
expect(() => {
|
|
263
|
+
s.forEach(null);
|
|
264
|
+
}).toThrow();
|
|
265
|
+
});
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
describe('size()', function () {
|
|
269
|
+
test('size() - should report number of passages', function () {
|
|
270
|
+
// Create a Story
|
|
271
|
+
const s = new Story();
|
|
272
|
+
// Create a Passage
|
|
273
|
+
const p = new Passage('');
|
|
274
|
+
// Test initial size
|
|
275
|
+
expect(s.size()).toBe(0);
|
|
276
|
+
// Add a passage
|
|
277
|
+
s.addPassage(p);
|
|
278
|
+
// Test size after adding one
|
|
279
|
+
expect(s.size()).toBe(1);
|
|
280
|
+
});
|
|
281
|
+
});
|
|
282
|
+
});
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import StoryFormat from '../src/StoryFormat.js';
|
|
2
|
+
|
|
3
|
+
describe('StoryFormat', function () {
|
|
4
|
+
describe('#constructor()', function () {
|
|
5
|
+
test('Should create default values', function () {
|
|
6
|
+
const sf = new StoryFormat();
|
|
7
|
+
expect(sf.name).toBe('');
|
|
8
|
+
expect(sf.version).toBe('');
|
|
9
|
+
expect(sf.author).toBe('');
|
|
10
|
+
expect(sf.image).toBe('');
|
|
11
|
+
expect(sf.url).toBe('');
|
|
12
|
+
expect(sf.license).toBe('');
|
|
13
|
+
expect(sf.proofing).toBe(false);
|
|
14
|
+
expect(sf.source).toBe('');
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
describe('name', function () {
|
|
19
|
+
test('Set new String', function () {
|
|
20
|
+
const sf = new StoryFormat();
|
|
21
|
+
sf.name = 'New';
|
|
22
|
+
expect(sf.name).toBe('New');
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
test('Throw error if non-String', function () {
|
|
26
|
+
const sf = new StoryFormat();
|
|
27
|
+
expect(() => {
|
|
28
|
+
sf.name = 1;
|
|
29
|
+
}).toThrow();
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
describe('version', function () {
|
|
34
|
+
test('Set new String', function () {
|
|
35
|
+
const sf = new StoryFormat();
|
|
36
|
+
sf.version = 'New';
|
|
37
|
+
expect(sf.version).toBe('New');
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
test('Throw error if non-String', function () {
|
|
41
|
+
const sf = new StoryFormat();
|
|
42
|
+
expect(() => {
|
|
43
|
+
sf.version = 1;
|
|
44
|
+
}).toThrow();
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
describe('author', function () {
|
|
49
|
+
test('Set new String', function () {
|
|
50
|
+
const sf = new StoryFormat();
|
|
51
|
+
sf.author = 'New';
|
|
52
|
+
expect(sf.author).toBe('New');
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
test('Throw error if non-String', function () {
|
|
56
|
+
const sf = new StoryFormat();
|
|
57
|
+
expect(() => {
|
|
58
|
+
sf.author = 1;
|
|
59
|
+
}).toThrow();
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
describe('image', function () {
|
|
64
|
+
test('Set new String', function () {
|
|
65
|
+
const sf = new StoryFormat();
|
|
66
|
+
sf.image = 'New';
|
|
67
|
+
expect(sf.image).toBe('New');
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
test('Throw error if non-String', function () {
|
|
71
|
+
const sf = new StoryFormat();
|
|
72
|
+
expect(() => {
|
|
73
|
+
sf.image = 1;
|
|
74
|
+
}).toThrow();
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
describe('url', function () {
|
|
79
|
+
test('Set new String', function () {
|
|
80
|
+
const sf = new StoryFormat();
|
|
81
|
+
sf.url = 'New';
|
|
82
|
+
expect(sf.url).toBe('New');
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
test('Throw error if non-String', function () {
|
|
86
|
+
const sf = new StoryFormat();
|
|
87
|
+
expect(() => {
|
|
88
|
+
sf.url = 1;
|
|
89
|
+
}).toThrow();
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
describe('license', function () {
|
|
94
|
+
test('Set new String', function () {
|
|
95
|
+
const sf = new StoryFormat();
|
|
96
|
+
sf.license = 'New';
|
|
97
|
+
expect(sf.license).toBe('New');
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
test('Throw error if non-String', function () {
|
|
101
|
+
const sf = new StoryFormat();
|
|
102
|
+
expect(() => {
|
|
103
|
+
sf.license = 1;
|
|
104
|
+
}).toThrow();
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
describe('proofing', function () {
|
|
109
|
+
test('Set new String', function () {
|
|
110
|
+
const sf = new StoryFormat();
|
|
111
|
+
sf.proofing = true;
|
|
112
|
+
expect(sf.proofing).toBe(true);
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
test('Throw error if non-String', function () {
|
|
116
|
+
const sf = new StoryFormat();
|
|
117
|
+
expect(() => {
|
|
118
|
+
sf.proofing = 1;
|
|
119
|
+
}).toThrow();
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
describe('source', function () {
|
|
124
|
+
test('Set new String', function () {
|
|
125
|
+
const sf = new StoryFormat();
|
|
126
|
+
sf.source = 'New';
|
|
127
|
+
expect(sf.source).toBe('New');
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
test('Throw error if non-String', function () {
|
|
131
|
+
const sf = new StoryFormat();
|
|
132
|
+
expect(() => {
|
|
133
|
+
sf.source = 1;
|
|
134
|
+
}).toThrow();
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
describe('description', function () {
|
|
139
|
+
test('Set new String', function () {
|
|
140
|
+
const sf = new StoryFormat();
|
|
141
|
+
sf.description = 'New';
|
|
142
|
+
expect(sf.description).toBe('New');
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
test('Throw error if non-String', function () {
|
|
146
|
+
const sf = new StoryFormat();
|
|
147
|
+
expect(() => {
|
|
148
|
+
sf.description = 1;
|
|
149
|
+
}).toThrow();
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
});
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
{
|
|
2
|
-
"malformed:
|
|
3
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"malformed:
|
|
3
|
+
}
|