extwee 1.6.2 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.json +25 -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 +60 -45
- package/src/FileReader.js +33 -35
- package/src/HTMLParser.js +343 -206
- package/src/HTMLWriter.js +196 -172
- package/src/Passage.js +202 -24
- package/src/Story.js +461 -122
- package/src/StoryFormat.js +300 -28
- package/src/StoryFormatParser.js +142 -59
- package/src/TweeParser.js +166 -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 +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 +279 -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 -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 +82 -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
|
@@ -1,13 +1,19 @@
|
|
|
1
|
-
::
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
::
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
::
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
:: Start
|
|
2
|
+
Content
|
|
3
|
+
|
|
4
|
+
:: StoryTitle
|
|
5
|
+
Title
|
|
6
|
+
|
|
7
|
+
:: UserScript [script]
|
|
8
|
+
1
|
|
9
|
+
|
|
10
|
+
:: UserScript2 [script]
|
|
11
|
+
2
|
|
12
|
+
|
|
13
|
+
:: StoryData
|
|
14
|
+
{
|
|
15
|
+
"ifid": "2B68ECD6-348F-4CF5-96F8-549A512A8128",
|
|
16
|
+
"format": "Harlowe",
|
|
17
|
+
"formatVersion": "2.1.0",
|
|
18
|
+
"zoom": "1"
|
|
19
|
+
}
|
|
@@ -1,13 +1,19 @@
|
|
|
1
|
-
::
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
::
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
::
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
:: Start
|
|
2
|
+
Content
|
|
3
|
+
|
|
4
|
+
:: StoryTitle
|
|
5
|
+
Title
|
|
6
|
+
|
|
7
|
+
:: UserStylesheet1 [stylesheet]
|
|
8
|
+
1
|
|
9
|
+
|
|
10
|
+
:: UserStylesheet2 [stylesheet]
|
|
11
|
+
2
|
|
12
|
+
|
|
13
|
+
:: StoryData
|
|
14
|
+
{
|
|
15
|
+
"ifid": "2B68ECD6-348F-4CF5-96F8-549A512A8128",
|
|
16
|
+
"format": "Harlowe",
|
|
17
|
+
"formatVersion": "2.1.0",
|
|
18
|
+
"zoom": "1"
|
|
19
|
+
}
|
|
@@ -1,32 +1,16 @@
|
|
|
1
|
-
/**
|
|
2
|
-
These are some notes at the top of the file
|
|
3
|
-
*/
|
|
4
|
-
:: StoryTitle
|
|
5
|
-
twineExample
|
|
6
|
-
|
|
7
|
-
:: Start {"position":"102,104","size":"100,100"}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
:: A third passage {"position":"350,288","size":"100,100"}
|
|
18
|
-
[[Start]]
|
|
19
|
-
|
|
20
|
-
:: A fourth passage {"position":"587,197","size":"100,100"}
|
|
21
|
-
[[A fifth passage]]
|
|
22
|
-
|
|
23
|
-
:: A fifth passage {"position":"800,306","size":"100,100"}
|
|
24
|
-
Double-click this passage to edit it.
|
|
25
|
-
|
|
26
|
-
:: StoryData
|
|
27
|
-
{
|
|
28
|
-
"ifid": "2B68ECD6-348F-4CF5-96F8-549A512A8128",
|
|
29
|
-
"format": "Harlowe",
|
|
30
|
-
"formatVersion": "2.1.0",
|
|
31
|
-
"zoom": "1"
|
|
32
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
These are some notes at the top of the file
|
|
3
|
+
*/
|
|
4
|
+
:: StoryTitle
|
|
5
|
+
twineExample
|
|
6
|
+
|
|
7
|
+
:: Start {"position":"102,104","size":"100,100"}
|
|
8
|
+
Start passage
|
|
9
|
+
|
|
10
|
+
:: StoryData
|
|
11
|
+
{
|
|
12
|
+
"ifid": "2B68ECD6-348F-4CF5-96F8-549A512A8128",
|
|
13
|
+
"format": "Harlowe",
|
|
14
|
+
"formatVersion": "2.1.0",
|
|
15
|
+
"zoom": "1"
|
|
16
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
:: Start {"position}
|
|
2
|
-
Some content
|
|
1
|
+
:: Start {"position}
|
|
2
|
+
Some content
|
|
@@ -1,13 +1,16 @@
|
|
|
1
|
-
::
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
::
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
::
|
|
8
|
-
{
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
"
|
|
13
|
-
|
|
1
|
+
:: Start
|
|
2
|
+
Content
|
|
3
|
+
|
|
4
|
+
:: StoryTitle
|
|
5
|
+
Title
|
|
6
|
+
|
|
7
|
+
:: UserScript [script]
|
|
8
|
+
window.example = {}
|
|
9
|
+
|
|
10
|
+
:: StoryData
|
|
11
|
+
{
|
|
12
|
+
"ifid": "2B68ECD6-348F-4CF5-96F8-549A512A8128",
|
|
13
|
+
"format": "Harlowe",
|
|
14
|
+
"formatVersion": "2.1.0",
|
|
15
|
+
"zoom": "1"
|
|
16
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
:: StoryTitle
|
|
2
|
+
Example
|
|
3
|
+
|
|
4
|
+
:: StoryData
|
|
5
|
+
{
|
|
6
|
+
"ifid": "A74F654F-3F85-44DE-8A87-9845AECD04B0",
|
|
7
|
+
"format": "Harlowe",
|
|
8
|
+
"formatVersion": "3.2.1",
|
|
9
|
+
"zoom": "1",
|
|
10
|
+
"start": "Untitled Passage"
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
:: Untitled Passage {"position":"100,99","size":"100,100"}
|
|
14
|
+
Double-click this passage to edit it.
|
|
@@ -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;}
|
|
@@ -1,13 +1,16 @@
|
|
|
1
|
-
::
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
::
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
::
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
"
|
|
13
|
-
|
|
1
|
+
:: Start
|
|
2
|
+
Content
|
|
3
|
+
|
|
4
|
+
:: StoryTitle
|
|
5
|
+
Title
|
|
6
|
+
|
|
7
|
+
:: UserStylesheet [stylesheet]
|
|
8
|
+
1
|
|
9
|
+
|
|
10
|
+
:: StoryData
|
|
11
|
+
{
|
|
12
|
+
"ifid": "2B68ECD6-348F-4CF5-96F8-549A512A8128",
|
|
13
|
+
"format": "Harlowe",
|
|
14
|
+
"formatVersion": "2.1.0",
|
|
15
|
+
"zoom": "1"
|
|
16
|
+
}
|
|
@@ -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,79 @@
|
|
|
1
|
+
import FileReader from '../src/FileReader.js';
|
|
2
|
+
import TweeParser from '../src/TweeParser.js';
|
|
3
|
+
|
|
4
|
+
describe('TweeParser', function () {
|
|
5
|
+
describe('#parse()', function () {
|
|
6
|
+
test('Should throw error if non-string is used', function () {
|
|
7
|
+
expect(() => { TweeParser.parse(1); }).toThrow();
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
test('Should throw error if empty string is used', function () {
|
|
11
|
+
expect(() => { TweeParser.parse(); }).toThrow();
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
test('Should throw error if no passages are present', function () {
|
|
15
|
+
expect(() => { TweeParser.parse('()()'); }).toThrow();
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
test('Should throw error if it detects malformed passage headers', function () {
|
|
19
|
+
expect(() => { TweeParser.parse('::{}[]\nNo name'); }).toThrow();
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
test('Should cut notes before passages', function () {
|
|
23
|
+
const fr = FileReader.read('test/TweeParser/notes.twee');
|
|
24
|
+
const story = TweeParser.parse(fr);
|
|
25
|
+
const p = story.getPassageByName('StoryTitle');
|
|
26
|
+
expect(p.text).toBe('twineExample');
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
test('Should be able to parse Twee file for Story Name', function () {
|
|
30
|
+
const fr = FileReader.read('test/TweeParser/example.twee');
|
|
31
|
+
const story = TweeParser.parse(fr);
|
|
32
|
+
const p = story.getPassageByName('StoryTitle');
|
|
33
|
+
expect(p.text).toBe('twineExample');
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
test('Should parse single tag on Start passage', function () {
|
|
37
|
+
const fr = FileReader.read('test/TweeParser/singletag.twee');
|
|
38
|
+
const story = TweeParser.parse(fr);
|
|
39
|
+
const start = story.getPassageByName('Start');
|
|
40
|
+
expect(start.tags).toHaveLength(1);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
test('Should parse multiple tag', function () {
|
|
44
|
+
const fr = FileReader.read('test/TweeParser/multipletags.twee');
|
|
45
|
+
const story = TweeParser.parse(fr);
|
|
46
|
+
const start = story.getPassageByName('Start');
|
|
47
|
+
expect(start.tags).toHaveLength(2);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
test('Should parse single script passage', function () {
|
|
51
|
+
const fr = FileReader.read('test/TweeParser/scriptPassage.twee');
|
|
52
|
+
const story = TweeParser.parse(fr);
|
|
53
|
+
const p = story.getPassageByName('UserScript');
|
|
54
|
+
expect(p.tags).toHaveLength(1);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
test('Should parse single stylesheet passage', function () {
|
|
58
|
+
const fr = FileReader.read('test/TweeParser/stylePassage.twee');
|
|
59
|
+
const story = TweeParser.parse(fr);
|
|
60
|
+
const p = story.getPassageByName('UserStylesheet');
|
|
61
|
+
expect(p.tags).toHaveLength(1);
|
|
62
|
+
expect(p.name).toBe('UserStylesheet');
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
test('Should parse StoryTitle', function () {
|
|
66
|
+
const fr = FileReader.read('test/TweeParser/test.twee');
|
|
67
|
+
const story = TweeParser.parse(fr);
|
|
68
|
+
const p = story.getPassageByName('StoryTitle');
|
|
69
|
+
expect(p).not.toBe(null);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
test('Should parse StoryAuthor', function () {
|
|
73
|
+
const fr = FileReader.read('test/TweeParser/example.twee');
|
|
74
|
+
const story = TweeParser.parse(fr);
|
|
75
|
+
const p = story.getPassageByName('StoryAuthor');
|
|
76
|
+
expect(p).not.toBe(null);
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
});
|
|
@@ -1,13 +1,18 @@
|
|
|
1
|
-
:: StoryTitle
|
|
2
|
-
Unknown
|
|
3
|
-
|
|
4
1
|
:: StoryData
|
|
5
|
-
|
|
6
|
-
"ifid": "",
|
|
7
|
-
"format": "",
|
|
8
|
-
"
|
|
9
|
-
"zoom":
|
|
10
|
-
"start": ""
|
|
2
|
+
{
|
|
3
|
+
"ifid": "DD03696D-5967-4E01-A955-885CDFEA2FE1",
|
|
4
|
+
"format": "Test",
|
|
5
|
+
"format-version": "1.2.3",
|
|
6
|
+
"zoom": 1,
|
|
7
|
+
"start": "Untitled"
|
|
11
8
|
}
|
|
12
9
|
|
|
10
|
+
:: StoryTitle
|
|
11
|
+
Title
|
|
12
|
+
|
|
13
13
|
:: Start
|
|
14
|
+
Content
|
|
15
|
+
|
|
16
|
+
:: Untitled
|
|
17
|
+
Some stuff
|
|
18
|
+
|
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
:: StoryTitle
|
|
2
|
-
TweeWriter
|
|
3
|
-
|
|
4
1
|
:: StoryData
|
|
5
|
-
|
|
6
|
-
"ifid": "",
|
|
7
|
-
"
|
|
8
|
-
"formatVersion": "",
|
|
9
|
-
"zoom": "",
|
|
10
|
-
"start": ""
|
|
2
|
+
{
|
|
3
|
+
"ifid": "DE7DF8AD-E4CD-499E-A4E7-C5B98B73449A",
|
|
4
|
+
"start": "Start"
|
|
11
5
|
}
|
|
12
6
|
|
|
13
|
-
:: Start [
|
|
7
|
+
:: Start [tag tags]
|
|
14
8
|
|
|
15
9
|
|
|
10
|
+
:: StoryTitle
|
|
11
|
+
Title
|
|
12
|
+
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
:: StoryData
|
|
2
|
+
{
|
|
3
|
+
"ifid": "FFA1527D-3700-4697-BCD1-386E4A6AE902",
|
|
4
|
+
"start": "Start",
|
|
5
|
+
"tag-colors": {
|
|
6
|
+
"bar": "green",
|
|
7
|
+
"foo": "red",
|
|
8
|
+
"qaz": "blue"
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
:: StoryTitle
|
|
13
|
+
Title
|
|
14
|
+
|
|
15
|
+
:: Start
|
|
16
|
+
Content
|
|
17
|
+
|
|
18
|
+
:: Untitled
|
|
19
|
+
Some stuff
|
|
20
|
+
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import FileReader from '../src/FileReader.js';
|
|
2
|
+
import Story from '../src/Story.js';
|
|
3
|
+
import Passage from '../src/Passage.js';
|
|
4
|
+
import TweeWriter from '../src/TweeWriter.js';
|
|
5
|
+
import TweeParser from '../src/TweeParser.js';
|
|
6
|
+
|
|
7
|
+
describe('TweeWriter', function () {
|
|
8
|
+
describe('#write()', function () {
|
|
9
|
+
test('Should throw error if object passed is not instanceof Story', function () {
|
|
10
|
+
expect(() => { TweeWriter.write({}); }).toThrow();
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
test('Should throw error if output file invalid', function () {
|
|
14
|
+
expect(() => { TweeWriter.write(new Story(), ''); }).toThrow();
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
test('Should write Twee file', function () {
|
|
18
|
+
const s = new Story();
|
|
19
|
+
s.addPassage(new Passage('StoryData', '{}'));
|
|
20
|
+
s.addPassage(new Passage('StoryTitle', 'Title'));
|
|
21
|
+
s.addPassage(new Passage('Start', 'Content'));
|
|
22
|
+
TweeWriter.write(s, 'test/TweeWriter/test1.twee');
|
|
23
|
+
const fr = FileReader.read('test/TweeWriter/test1.twee');
|
|
24
|
+
const story = TweeParser.parse(fr);
|
|
25
|
+
const p = story.getPassageByName('StoryTitle');
|
|
26
|
+
expect(p.text).toBe('Title');
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
test('Should correctly write Twee file with passage tags', function () {
|
|
30
|
+
const s = new Story();
|
|
31
|
+
s.addPassage(new Passage('Start', '', ['tag', 'tags']));
|
|
32
|
+
s.addPassage(new Passage('StoryTitle', 'Title'));
|
|
33
|
+
// Verify only one passage.
|
|
34
|
+
expect(s.size()).toBe(2);
|
|
35
|
+
|
|
36
|
+
// Set an ifid property
|
|
37
|
+
s.IFID = 'DE7DF8AD-E4CD-499E-A4E7-C5B98B73449A';
|
|
38
|
+
|
|
39
|
+
// Write contents to file.
|
|
40
|
+
TweeWriter.write(s, 'test/TweeWriter/test3.twee');
|
|
41
|
+
// Read file.
|
|
42
|
+
const fr = FileReader.read('test/TweeWriter/test3.twee');
|
|
43
|
+
// Parse file.
|
|
44
|
+
const tp = TweeParser.parse(fr);
|
|
45
|
+
// Verify only two passages
|
|
46
|
+
expect(tp.size()).toBe(2);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
test('Should write format, formatVersion, zoom, and start', function () {
|
|
50
|
+
const s = new Story();
|
|
51
|
+
s.addPassage(new Passage('StoryTitle', 'Title'));
|
|
52
|
+
s.addPassage(new Passage('Start', 'Content'));
|
|
53
|
+
s.addPassage(new Passage('Untitled', 'Some stuff'));
|
|
54
|
+
|
|
55
|
+
s.format = 'Test';
|
|
56
|
+
s.formatVersion = '1.2.3';
|
|
57
|
+
s.zoom = 1;
|
|
58
|
+
s.start = 'Untitled';
|
|
59
|
+
|
|
60
|
+
TweeWriter.write(s, 'test/TweeWriter/test1.twee');
|
|
61
|
+
const fr = FileReader.read('test/TweeWriter/test1.twee');
|
|
62
|
+
const story2 = TweeParser.parse(fr);
|
|
63
|
+
expect(story2.format).toBe('Test');
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
test('Should write tag colors', function () {
|
|
67
|
+
const s = new Story();
|
|
68
|
+
s.addPassage(new Passage('StoryTitle', 'Title'));
|
|
69
|
+
s.addPassage(new Passage('Start', 'Content'));
|
|
70
|
+
s.addPassage(new Passage('Untitled', 'Some stuff'));
|
|
71
|
+
s.tagColors = {
|
|
72
|
+
bar: 'green',
|
|
73
|
+
foo: 'red',
|
|
74
|
+
qaz: 'blue'
|
|
75
|
+
};
|
|
76
|
+
TweeWriter.write(s, 'test/TweeWriter/test5.twee');
|
|
77
|
+
const fr = FileReader.read('test/TweeWriter/test5.twee');
|
|
78
|
+
const story2 = TweeParser.parse(fr);
|
|
79
|
+
expect(story2.tagColors.bar).toBe('green');
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
});
|