extwee 1.6.2 → 2.0.3
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 -24
- package/.github/workflows/nodejs.yml +24 -24
- 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 -45
- package/src/FileReader.js +33 -35
- package/src/HTMLParser.js +343 -206
- package/src/HTMLWriter.js +231 -172
- package/src/Passage.js +202 -24
- package/src/Story.js +490 -122
- package/src/StoryFormat.js +300 -28
- package/src/StoryFormatParser.js +142 -59
- package/src/TweeParser.js +161 -207
- package/src/TweeWriter.js +98 -96
- 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 +14 -11
- 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 +369 -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 -32
- 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 -114
- package/src/DirectoryWatcher.js +0 -87
- 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 -736
|
@@ -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,369 @@
|
|
|
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', () => {
|
|
10
|
+
describe('#constructor()', () => {
|
|
11
|
+
let s = null;
|
|
12
|
+
|
|
13
|
+
beforeEach(() => {
|
|
14
|
+
s = new Story();
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it('Should have extwee name', () => {
|
|
18
|
+
expect(s.creator).toBe(name);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it('Should have extwee version', () => {
|
|
22
|
+
expect(s.creatorVersion).toBe(version);
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
describe('creator', () => {
|
|
27
|
+
let s = null;
|
|
28
|
+
|
|
29
|
+
beforeEach(() => {
|
|
30
|
+
s = new Story();
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it('Set using String', () => {
|
|
34
|
+
s.creator = 'New';
|
|
35
|
+
expect(s.creator).toBe('New');
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('Should throw error if not String', () => {
|
|
39
|
+
expect(() => {
|
|
40
|
+
s.creator = 1;
|
|
41
|
+
}).toThrow();
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
describe('creatorVersion', () => {
|
|
46
|
+
let s = null;
|
|
47
|
+
|
|
48
|
+
beforeEach(() => {
|
|
49
|
+
s = new Story();
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('Set using String', () => {
|
|
53
|
+
s.creatorVersion = 'New';
|
|
54
|
+
expect(s.creatorVersion).toBe('New');
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('Should throw error if not String', () => {
|
|
58
|
+
expect(() => {
|
|
59
|
+
s.creatorVersion = 1;
|
|
60
|
+
}).toThrow();
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
describe('IFID', () => {
|
|
65
|
+
let s = null;
|
|
66
|
+
|
|
67
|
+
beforeEach(() => {
|
|
68
|
+
s = new Story();
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it('Set using String', () => {
|
|
72
|
+
s.IFID = 'New';
|
|
73
|
+
expect(s.IFID).toBe('New');
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it('Should throw error if not String', () => {
|
|
77
|
+
expect(() => {
|
|
78
|
+
s.IFID = 1;
|
|
79
|
+
}).toThrow();
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
describe('format', () => {
|
|
84
|
+
let s = null;
|
|
85
|
+
|
|
86
|
+
beforeEach(() => {
|
|
87
|
+
s = new Story();
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it('Set using String', () => {
|
|
91
|
+
s.format = 'New';
|
|
92
|
+
expect(s.format).toBe('New');
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it('Should throw error if not String', () => {
|
|
96
|
+
expect(() => {
|
|
97
|
+
s.format = 1;
|
|
98
|
+
}).toThrow();
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
describe('formatVersion', () => {
|
|
103
|
+
let s = null;
|
|
104
|
+
|
|
105
|
+
beforeEach(() => {
|
|
106
|
+
s = new Story();
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it('Set using String', () => {
|
|
110
|
+
s.formatVersion = 'New';
|
|
111
|
+
expect(s.formatVersion).toBe('New');
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it('Should throw error if not String', () => {
|
|
115
|
+
expect(() => {
|
|
116
|
+
s.formatVersion = 1;
|
|
117
|
+
}).toThrow();
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
describe('name', () => {
|
|
122
|
+
let s = null;
|
|
123
|
+
|
|
124
|
+
beforeEach(() => {
|
|
125
|
+
s = new Story();
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
it('Set using String', () => {
|
|
129
|
+
s.name = 'New';
|
|
130
|
+
expect(s.name).toBe('New');
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
it('Should throw error if not String', () => {
|
|
134
|
+
expect(() => {
|
|
135
|
+
s.name = 1;
|
|
136
|
+
}).toThrow();
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
describe('zoom', () => {
|
|
141
|
+
let s = null;
|
|
142
|
+
|
|
143
|
+
beforeEach(() => {
|
|
144
|
+
s = new Story();
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
it('Set using Number', () => {
|
|
148
|
+
s.zoom = 1.0;
|
|
149
|
+
expect(s.zoom).not.toBe(0);
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
it('Should throw error if not String', () => {
|
|
153
|
+
expect(() => {
|
|
154
|
+
s.zoom = null;
|
|
155
|
+
}).toThrow();
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
describe('metadata', () => {
|
|
160
|
+
let s = null;
|
|
161
|
+
|
|
162
|
+
beforeEach(() => {
|
|
163
|
+
s = new Story();
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
it('Set metadata', () => {
|
|
167
|
+
s.metadata = {};
|
|
168
|
+
expect(s.metadata).not.toBe(null);
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
it('Should throw error if not object', () => {
|
|
172
|
+
expect(() => {
|
|
173
|
+
s.metadata = 1;
|
|
174
|
+
}).toThrow();
|
|
175
|
+
});
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
describe('start', () => {
|
|
179
|
+
let s = null;
|
|
180
|
+
|
|
181
|
+
beforeEach(() => {
|
|
182
|
+
s = new Story();
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
it('Set start', () => {
|
|
186
|
+
s.start = 'Start';
|
|
187
|
+
expect(s.start).not.toBe('');
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
it('Should throw error if not String', () => {
|
|
191
|
+
expect(() => {
|
|
192
|
+
s.start = 1;
|
|
193
|
+
}).toThrow();
|
|
194
|
+
});
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
describe('tagColors', () => {
|
|
198
|
+
let s = null;
|
|
199
|
+
|
|
200
|
+
beforeEach(() => {
|
|
201
|
+
s = new Story();
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
it('Set tagColors', () => {
|
|
205
|
+
s.tagColors = {
|
|
206
|
+
bar: 'green'
|
|
207
|
+
};
|
|
208
|
+
const count = Object.keys(s.tagColors).length;
|
|
209
|
+
expect(count).toBe(1);
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
it('Should throw error if not object', () => {
|
|
213
|
+
expect(() => {
|
|
214
|
+
s.tagColors = null;
|
|
215
|
+
}).toThrow();
|
|
216
|
+
});
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
describe('addPassage()', () => {
|
|
220
|
+
let s = null;
|
|
221
|
+
|
|
222
|
+
beforeEach(() => {
|
|
223
|
+
s = new Story();
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
it('addPassage() - should increase size', () => {
|
|
227
|
+
const p = new Passage();
|
|
228
|
+
s.addPassage(p);
|
|
229
|
+
expect(s.size()).toBe(1);
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
it('addPassage() - should throw error if non-Passage', () => {
|
|
233
|
+
expect(() => {
|
|
234
|
+
s.addPassage(null);
|
|
235
|
+
}).toThrow();
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
it('addPassage() - should prevent passages with same name being added', () => {
|
|
239
|
+
const p = new Passage('A');
|
|
240
|
+
const p2 = new Passage('A');
|
|
241
|
+
s.addPassage(p);
|
|
242
|
+
s.addPassage(p2);
|
|
243
|
+
expect(s.size()).toBe(1);
|
|
244
|
+
});
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
describe('removePassage()', () => {
|
|
248
|
+
let s = null;
|
|
249
|
+
|
|
250
|
+
beforeEach(() => {
|
|
251
|
+
s = new Story();
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
it('removePassage() - should decrease size', () => {
|
|
255
|
+
s.addPassage(new Passage('Find'));
|
|
256
|
+
s.addPassage(new Passage('Find2'));
|
|
257
|
+
s.removePassage('Find');
|
|
258
|
+
expect(s.size()).toBe(1);
|
|
259
|
+
});
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
describe('getPassagesByTag()', () => {
|
|
263
|
+
let s = null;
|
|
264
|
+
|
|
265
|
+
beforeEach(() => {
|
|
266
|
+
s = new Story();
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
it('getPassagesByTag() - should find passages', () => {
|
|
270
|
+
const p = new Passage('Find', '', ['one']);
|
|
271
|
+
const p2 = new Passage('Find2', '', ['one']);
|
|
272
|
+
s.addPassage(p);
|
|
273
|
+
s.addPassage(p2);
|
|
274
|
+
const ps = s.getPassagesByTag('one');
|
|
275
|
+
expect(ps).toHaveLength(2);
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
it('getPassagesByTag() - should find none if none in collection', () => {
|
|
279
|
+
const ps = s.getPassagesByTag('one');
|
|
280
|
+
expect(ps).toHaveLength(0);
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
it('getPassagesByTag() - should find none if no tags match search', () => {
|
|
284
|
+
const p = new Passage('Find', '', ['one']);
|
|
285
|
+
const p2 = new Passage('Find2', '', ['one']);
|
|
286
|
+
s.addPassage(p);
|
|
287
|
+
s.addPassage(p2);
|
|
288
|
+
const ps = s.getPassagesByTag('two');
|
|
289
|
+
expect(ps).toHaveLength(0);
|
|
290
|
+
});
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
describe('getPassageByName()', () => {
|
|
294
|
+
let s = null;
|
|
295
|
+
|
|
296
|
+
beforeEach(() => {
|
|
297
|
+
s = new Story();
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
it('getPassageByName() - should get passage by name', () => {
|
|
301
|
+
const p = new Passage('Find');
|
|
302
|
+
s.addPassage(p);
|
|
303
|
+
const passage = s.getPassageByName('Find');
|
|
304
|
+
expect(passage.name).toBe('Find');
|
|
305
|
+
});
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
describe('getPassageByPID()', () => {
|
|
309
|
+
let s = null;
|
|
310
|
+
|
|
311
|
+
beforeEach(() => {
|
|
312
|
+
s = new Story();
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
it('getPassageByPID() - should get passage by PID', () => {
|
|
316
|
+
const p = new Passage('Find', '', [], {}, 12);
|
|
317
|
+
s.addPassage(p);
|
|
318
|
+
const passage = s.getPassageByPID(12);
|
|
319
|
+
expect(passage.name).toBe('Find');
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
it('getPassageByPID() - should return null if not found', () => {
|
|
323
|
+
expect(s.getPassageByPID(12)).toBe(null);
|
|
324
|
+
});
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
describe('forEach()', () => {
|
|
328
|
+
let s = null;
|
|
329
|
+
|
|
330
|
+
beforeEach(() => {
|
|
331
|
+
s = new Story();
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
it('forEach() - should return if non-function', () => {
|
|
335
|
+
s.addPassage(new Passage('A'));
|
|
336
|
+
s.addPassage(new Passage('B'));
|
|
337
|
+
let passageNames = '';
|
|
338
|
+
s.forEach((p) => {
|
|
339
|
+
passageNames += p.name;
|
|
340
|
+
});
|
|
341
|
+
expect(passageNames).toBe('AB');
|
|
342
|
+
});
|
|
343
|
+
|
|
344
|
+
it('forEach() - should throw error if non-function', () => {
|
|
345
|
+
expect(() => {
|
|
346
|
+
s.forEach(null);
|
|
347
|
+
}).toThrow();
|
|
348
|
+
});
|
|
349
|
+
});
|
|
350
|
+
|
|
351
|
+
describe('size()', () => {
|
|
352
|
+
let s = null;
|
|
353
|
+
|
|
354
|
+
beforeEach(() => {
|
|
355
|
+
s = new Story();
|
|
356
|
+
});
|
|
357
|
+
|
|
358
|
+
it('size() - should report number of passages', () => {
|
|
359
|
+
// Create a Passage
|
|
360
|
+
const p = new Passage('');
|
|
361
|
+
// Test initial size
|
|
362
|
+
expect(s.size()).toBe(0);
|
|
363
|
+
// Add a passage
|
|
364
|
+
s.addPassage(p);
|
|
365
|
+
// Test size after adding one
|
|
366
|
+
expect(s.size()).toBe(1);
|
|
367
|
+
});
|
|
368
|
+
});
|
|
369
|
+
});
|
|
@@ -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
|
+
}
|