extwee 2.0.3 → 2.0.6
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/bin/extwee.js +10 -12
- package/package.json +17 -18
- package/src/HTMLParser.js +2 -0
- package/src/HTMLWriter.js +2 -2
- package/src/Story.js +43 -10
- package/src/TweeWriter.js +23 -0
- package/test/CLI/test2.html +1 -3
- package/test/CLI.test.js +6 -6
- package/test/FileReader.test.js +4 -4
- package/test/HTMLParser/twineExample.html +11 -3
- package/test/HTMLParser.test.js +31 -31
- package/test/HTMLWriter/creator.html +1 -2
- package/test/HTMLWriter/test11.html +1 -3
- package/test/HTMLWriter/test2.html +0 -3
- package/test/HTMLWriter/test3.html +0 -1
- package/test/HTMLWriter/test4.html +1 -2
- package/test/HTMLWriter/test6.html +1 -2
- package/test/HTMLWriter.test.js +1 -3
- package/test/Passage.test.js +14 -14
- package/test/Roundtrip/example4.twee +27 -0
- package/test/Roundtrip/round.html +1 -4
- package/test/Roundtrip.test.js +2 -2
- package/test/Story.test.js +74 -20
- package/test/StoryFormat.test.js +30 -30
- package/test/StoryFormatParser.test.js +16 -16
- package/test/TweeWriter/test1.twee +1 -1
- package/test/TweeWriter/test3.twee +3 -3
- package/test/TweeWriter/test5.twee +1 -1
- package/test/TweeWriter/test6.twee +15 -0
- package/test/TweeWriter/test7.twee +15 -0
- package/test/TweeWriter.test.js +25 -3
|
@@ -1,87 +1,87 @@
|
|
|
1
1
|
import StoryFormatParser from '../src/StoryFormatParser.js';
|
|
2
2
|
import FileReader from '../src/FileReader';
|
|
3
3
|
|
|
4
|
-
describe('StoryFormatParser',
|
|
5
|
-
describe('#parse()',
|
|
6
|
-
|
|
4
|
+
describe('StoryFormatParser', () => {
|
|
5
|
+
describe('#parse()', () => {
|
|
6
|
+
it('Should throw error if JSON missing', () => {
|
|
7
7
|
const fr = FileReader.read('test/StoryFormatParser/example.js');
|
|
8
8
|
expect(() => { StoryFormatParser.parse(fr); }).toThrow();
|
|
9
9
|
});
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
it('Should throw error if JSON malformed', () => {
|
|
12
12
|
const fr = FileReader.read('test/StoryFormatParser/example2.js');
|
|
13
13
|
expect(() => { StoryFormatParser.parse(fr); }).toThrow();
|
|
14
14
|
});
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
it('Should correctly parse a StoryFormat name', () => {
|
|
17
17
|
const fr = FileReader.read('test/StoryFormatParser/format.js');
|
|
18
18
|
const sfp = StoryFormatParser.parse(fr);
|
|
19
19
|
expect(sfp.name).toBe('Snowman');
|
|
20
20
|
});
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
it('Should correctly parse Harlowe story format', () => {
|
|
23
23
|
const fr = FileReader.read('test/StoryFormatParser/harlowe.js');
|
|
24
24
|
const sfp = StoryFormatParser.parse(fr);
|
|
25
25
|
expect(sfp.name).toBe('Harlowe');
|
|
26
26
|
});
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
it('Should detect missing name and set default', () => {
|
|
29
29
|
const fr = FileReader.read('test/StoryFormatParser/missingName.js');
|
|
30
30
|
const sfp = StoryFormatParser.parse(fr);
|
|
31
31
|
expect(sfp.name).toBe('Untitled Story Format');
|
|
32
32
|
});
|
|
33
33
|
|
|
34
|
-
|
|
34
|
+
it('Should detect missing author and set default', () => {
|
|
35
35
|
const fr = FileReader.read('test/StoryFormatParser/missingAuthor.js');
|
|
36
36
|
const sfp = StoryFormatParser.parse(fr);
|
|
37
37
|
expect(sfp.author).toBe('');
|
|
38
38
|
});
|
|
39
39
|
|
|
40
|
-
|
|
40
|
+
it('Should detect missing description and set default', () => {
|
|
41
41
|
const fr = FileReader.read('test/StoryFormatParser/missingDescription.js');
|
|
42
42
|
const sfp = StoryFormatParser.parse(fr);
|
|
43
43
|
expect(sfp.description).toBe('');
|
|
44
44
|
});
|
|
45
45
|
|
|
46
|
-
|
|
46
|
+
it('Should detect missing image and set default', () => {
|
|
47
47
|
const fr = FileReader.read('test/StoryFormatParser/missingImage.js');
|
|
48
48
|
const sfp = StoryFormatParser.parse(fr);
|
|
49
49
|
expect(sfp.image).toBe('');
|
|
50
50
|
});
|
|
51
51
|
|
|
52
|
-
|
|
52
|
+
it('Should detect missing url and set default', () => {
|
|
53
53
|
const fr = FileReader.read('test/StoryFormatParser/missingURL.js');
|
|
54
54
|
const sfp = StoryFormatParser.parse(fr);
|
|
55
55
|
expect(sfp.url).toBe('');
|
|
56
56
|
});
|
|
57
57
|
|
|
58
|
-
|
|
58
|
+
it('Should detect missing license and set default', () => {
|
|
59
59
|
const fr = FileReader.read('test/StoryFormatParser/missingLicense.js');
|
|
60
60
|
const sfp = StoryFormatParser.parse(fr);
|
|
61
61
|
expect(sfp.license).toBe('');
|
|
62
62
|
});
|
|
63
63
|
|
|
64
|
-
|
|
64
|
+
it('Should detect proofing license and set default', () => {
|
|
65
65
|
const fr = FileReader.read('test/StoryFormatParser/missingProofing.js');
|
|
66
66
|
const sfp = StoryFormatParser.parse(fr);
|
|
67
67
|
expect(sfp.proofing).toBe(false);
|
|
68
68
|
});
|
|
69
69
|
|
|
70
|
-
|
|
70
|
+
it('Should throw error if version does not exist', () => {
|
|
71
71
|
const fr = FileReader.read('test/StoryFormatParser/missingVersion.js');
|
|
72
72
|
expect(() => {
|
|
73
73
|
StoryFormatParser.parse(fr);
|
|
74
74
|
}).toThrow();
|
|
75
75
|
});
|
|
76
76
|
|
|
77
|
-
|
|
77
|
+
it('Should throw error if version is not semantic style', () => {
|
|
78
78
|
const fr = FileReader.read('test/StoryFormatParser/versionWrong.js');
|
|
79
79
|
expect(() => {
|
|
80
80
|
StoryFormatParser.parse(fr);
|
|
81
81
|
}).toThrow();
|
|
82
82
|
});
|
|
83
83
|
|
|
84
|
-
|
|
84
|
+
it('Should throw error if source is not found', () => {
|
|
85
85
|
const fr = FileReader.read('test/StoryFormatParser/missingSource.js');
|
|
86
86
|
expect(() => {
|
|
87
87
|
StoryFormatParser.parse(fr);
|
package/test/TweeWriter.test.js
CHANGED
|
@@ -5,7 +5,7 @@ import TweeWriter from '../src/TweeWriter.js';
|
|
|
5
5
|
import TweeParser from '../src/TweeParser.js';
|
|
6
6
|
|
|
7
7
|
describe('TweeWriter', () => {
|
|
8
|
-
describe('#write()', () => {
|
|
8
|
+
describe('#write()', () => {
|
|
9
9
|
let s = null;
|
|
10
10
|
|
|
11
11
|
beforeEach(() => {
|
|
@@ -35,7 +35,7 @@ describe('TweeWriter', () => {
|
|
|
35
35
|
s.addPassage(new Passage('Start', '', ['tag', 'tags']));
|
|
36
36
|
s.addPassage(new Passage('StoryTitle', 'Title'));
|
|
37
37
|
// Verify only one passage.
|
|
38
|
-
expect(s.size()).toBe(
|
|
38
|
+
expect(s.size()).toBe(1);
|
|
39
39
|
|
|
40
40
|
// Set an ifid property
|
|
41
41
|
s.IFID = 'DE7DF8AD-E4CD-499E-A4E7-C5B98B73449A';
|
|
@@ -47,7 +47,7 @@ describe('TweeWriter', () => {
|
|
|
47
47
|
// Parse file.
|
|
48
48
|
const tp = TweeParser.parse(fr);
|
|
49
49
|
// Verify only two passages
|
|
50
|
-
expect(tp.size()).toBe(
|
|
50
|
+
expect(tp.size()).toBe(1);
|
|
51
51
|
});
|
|
52
52
|
|
|
53
53
|
it('Should write format, formatVersion, zoom, and start', () => {
|
|
@@ -81,5 +81,27 @@ describe('TweeWriter', () => {
|
|
|
81
81
|
const story2 = TweeParser.parse(fr);
|
|
82
82
|
expect(story2.tagColors.bar).toBe('green');
|
|
83
83
|
});
|
|
84
|
+
|
|
85
|
+
it('Should write Twee file with "script" tags', () => {
|
|
86
|
+
s.addPassage(new Passage('Test', 'Test', ['script']));
|
|
87
|
+
s.addPassage(new Passage('StoryTitle', 'Title'));
|
|
88
|
+
s.addPassage(new Passage('Start', 'Content'));
|
|
89
|
+
TweeWriter.write(s, 'test/TweeWriter/test6.twee');
|
|
90
|
+
const fr = FileReader.read('test/TweeWriter/test6.twee');
|
|
91
|
+
const story = TweeParser.parse(fr);
|
|
92
|
+
const p = story.getPassagesByTag('script');
|
|
93
|
+
expect(p[0].text).toBe('Test');
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it('Should write Twee file with "stylesheet" tags', () => {
|
|
97
|
+
s.addPassage(new Passage('Test', 'Test', ['stylesheet']));
|
|
98
|
+
s.addPassage(new Passage('StoryTitle', 'Title'));
|
|
99
|
+
s.addPassage(new Passage('Start', 'Content'));
|
|
100
|
+
TweeWriter.write(s, 'test/TweeWriter/test7.twee');
|
|
101
|
+
const fr = FileReader.read('test/TweeWriter/test7.twee');
|
|
102
|
+
const story = TweeParser.parse(fr);
|
|
103
|
+
const p = story.getPassagesByTag('stylesheet');
|
|
104
|
+
expect(p[0].text).toBe('Test');
|
|
105
|
+
});
|
|
84
106
|
});
|
|
85
107
|
});
|