extwee 2.0.5 → 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 +1 -1
- package/package.json +4 -4
- package/src/HTMLParser.js +2 -0
- package/src/HTMLWriter.js +2 -2
- package/src/Story.js +40 -6
- 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
package/test/Passage.test.js
CHANGED
|
@@ -2,7 +2,7 @@ import Passage from '../src/Passage.js';
|
|
|
2
2
|
|
|
3
3
|
describe('Passage', () => {
|
|
4
4
|
describe('#constructor()', () => {
|
|
5
|
-
|
|
5
|
+
it('Set default values', () => {
|
|
6
6
|
const p = new Passage();
|
|
7
7
|
expect(p.name).toBe('');
|
|
8
8
|
expect(p.tags).toHaveLength(0);
|
|
@@ -13,13 +13,13 @@ describe('Passage', () => {
|
|
|
13
13
|
});
|
|
14
14
|
|
|
15
15
|
describe('name', () => {
|
|
16
|
-
|
|
16
|
+
it('Set name', () => {
|
|
17
17
|
const p = new Passage();
|
|
18
18
|
p.name = 'New';
|
|
19
19
|
expect(p.name).toBe('New');
|
|
20
20
|
});
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
it('Throw error if name is not String', () => {
|
|
23
23
|
const p = new Passage();
|
|
24
24
|
expect(() => {
|
|
25
25
|
p.name = 1;
|
|
@@ -28,13 +28,13 @@ describe('Passage', () => {
|
|
|
28
28
|
});
|
|
29
29
|
|
|
30
30
|
describe('tags', () => {
|
|
31
|
-
|
|
31
|
+
it('Set tags', () => {
|
|
32
32
|
const p = new Passage();
|
|
33
33
|
p.tags = ['tag'];
|
|
34
34
|
expect(p.tags).toHaveLength(1);
|
|
35
35
|
});
|
|
36
36
|
|
|
37
|
-
|
|
37
|
+
it('Throw error if tags is not Array', () => {
|
|
38
38
|
const p = new Passage();
|
|
39
39
|
expect(() => {
|
|
40
40
|
p.tags = 1;
|
|
@@ -43,13 +43,13 @@ describe('Passage', () => {
|
|
|
43
43
|
});
|
|
44
44
|
|
|
45
45
|
describe('metadata', () => {
|
|
46
|
-
|
|
46
|
+
it('Set metadata', () => {
|
|
47
47
|
const p = new Passage();
|
|
48
48
|
p.metadata = { position: '100,100' };
|
|
49
49
|
expect(p.metadata).toEqual({ position: '100,100' });
|
|
50
50
|
});
|
|
51
51
|
|
|
52
|
-
|
|
52
|
+
it('Throw error if metadata is not an Object', () => {
|
|
53
53
|
const p = new Passage();
|
|
54
54
|
expect(() => {
|
|
55
55
|
p.metadata = 1;
|
|
@@ -58,13 +58,13 @@ describe('Passage', () => {
|
|
|
58
58
|
});
|
|
59
59
|
|
|
60
60
|
describe('text', () => {
|
|
61
|
-
|
|
61
|
+
it('Set text', () => {
|
|
62
62
|
const p = new Passage();
|
|
63
63
|
p.text = 'New';
|
|
64
64
|
expect(p.text).toBe('New');
|
|
65
65
|
});
|
|
66
66
|
|
|
67
|
-
|
|
67
|
+
it('Throw error if text is not a String', () => {
|
|
68
68
|
const p = new Passage();
|
|
69
69
|
expect(() => {
|
|
70
70
|
p.text = 1;
|
|
@@ -73,13 +73,13 @@ describe('Passage', () => {
|
|
|
73
73
|
});
|
|
74
74
|
|
|
75
75
|
describe('pid', () => {
|
|
76
|
-
|
|
76
|
+
it('Set PID', () => {
|
|
77
77
|
const p = new Passage();
|
|
78
78
|
p.pid = 12;
|
|
79
79
|
expect(p.pid).toBe(12);
|
|
80
80
|
});
|
|
81
81
|
|
|
82
|
-
|
|
82
|
+
it('Throw error if pid is not a Number', () => {
|
|
83
83
|
const p = new Passage();
|
|
84
84
|
expect(() => {
|
|
85
85
|
p.pid = [];
|
|
@@ -88,15 +88,15 @@ describe('Passage', () => {
|
|
|
88
88
|
});
|
|
89
89
|
|
|
90
90
|
describe('toString()', () => {
|
|
91
|
-
|
|
91
|
+
it('Create name string', () => {
|
|
92
92
|
const p = new Passage('Name', 'Test');
|
|
93
93
|
expect(p.toString()).toBe(':: Name\nTest\n\n');
|
|
94
94
|
});
|
|
95
|
-
|
|
95
|
+
it('Create tags string', () => {
|
|
96
96
|
const p = new Passage('Name', 'Test', ['tags', 'another']);
|
|
97
97
|
expect(p.toString()).toBe(':: Name [tags another]\nTest\n\n');
|
|
98
98
|
});
|
|
99
|
-
|
|
99
|
+
it('Create metadata string', () => {
|
|
100
100
|
const p = new Passage('Name', 'Test', ['tags', 'another'], { position: '100,100' });
|
|
101
101
|
expect(p.toString()).toBe(':: Name [tags another] {"position":"100,100"}\nTest\n\n');
|
|
102
102
|
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
:: StoryTitle
|
|
2
|
+
Example4
|
|
3
|
+
|
|
4
|
+
:: user[script]
|
|
5
|
+
console.log("Hi!");
|
|
6
|
+
|
|
7
|
+
:: user2[script]
|
|
8
|
+
console.log("Hi!");
|
|
9
|
+
|
|
10
|
+
:: style1[stylesheet]
|
|
11
|
+
body {
|
|
12
|
+
color: #ccc;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
:: style2[stylesheet]
|
|
16
|
+
html {
|
|
17
|
+
color: #ccc;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
:: Start
|
|
21
|
+
[[Another passage]]
|
|
22
|
+
|
|
23
|
+
:: Another passage
|
|
24
|
+
[[A third]]
|
|
25
|
+
|
|
26
|
+
:: A third
|
|
27
|
+
Double-click this passage to edit it.
|
|
@@ -11,12 +11,9 @@
|
|
|
11
11
|
|
|
12
12
|
<tw-story></tw-story>
|
|
13
13
|
|
|
14
|
-
<tw-storydata name="Example1" startnode="4" creator="extwee" creator-version="2.0.
|
|
14
|
+
<tw-storydata name="Example1" startnode="4" creator="extwee" creator-version="2.0.6" ifid="BB4B4C20-2E2D-4283-B125-5550042AD3EB" zoom="0" format="Harlowe" format-version="3.0.2" options hidden>
|
|
15
15
|
<style role="stylesheet" id="twine-user-stylesheet" type="text/twine-css"></style>
|
|
16
16
|
<script role="script" id="twine-user-script" type="text/twine-javascript"></script>
|
|
17
|
-
<tw-passagedata pid="1" name="StoryTitle">Example1</tw-passagedata>
|
|
18
|
-
<tw-passagedata pid="2" name="UserScript" tags="script" ></tw-passagedata>
|
|
19
|
-
<tw-passagedata pid="3" name="UserStylesheet" tags="stylesheet" ></tw-passagedata>
|
|
20
17
|
<tw-passagedata pid="4" name="Start">[[Another passage]]</tw-passagedata>
|
|
21
18
|
<tw-passagedata pid="5" name="Another passage">[[A third]]</tw-passagedata>
|
|
22
19
|
<tw-passagedata pid="6" name="A third">Double-click this passage to edit it.</tw-passagedata>
|
package/test/Roundtrip.test.js
CHANGED
|
@@ -6,7 +6,7 @@ import StoryFormatParser from '../src/StoryFormatParser.js';
|
|
|
6
6
|
import HTMLWriter from '../src/HTMLWriter.js';
|
|
7
7
|
|
|
8
8
|
describe('Round-trip testing', () => {
|
|
9
|
-
|
|
9
|
+
it('Should round-trip HTML-to-Twee', () => {
|
|
10
10
|
// Read HTML
|
|
11
11
|
const fr = FileReader.read('test/Roundtrip/Example1.html');
|
|
12
12
|
// Parse HTML
|
|
@@ -23,7 +23,7 @@ describe('Round-trip testing', () => {
|
|
|
23
23
|
expect(s.ifid).toBe(s2.ifid);
|
|
24
24
|
});
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
it('Should round-trip Twee-to-HTML', () => {
|
|
27
27
|
// Read StoryFormat
|
|
28
28
|
const storyFormat = FileReader.read('test/Roundtrip/harlowe.js');
|
|
29
29
|
// Parse StoryFormat
|
package/test/Story.test.js
CHANGED
|
@@ -7,7 +7,7 @@ import FileReader from '../src/FileReader.js';
|
|
|
7
7
|
const { name, version } = JSON.parse(FileReader.read('package.json'));
|
|
8
8
|
|
|
9
9
|
describe('Story', () => {
|
|
10
|
-
describe('#constructor()', () => {
|
|
10
|
+
describe('#constructor()', () => {
|
|
11
11
|
let s = null;
|
|
12
12
|
|
|
13
13
|
beforeEach(() => {
|
|
@@ -23,7 +23,7 @@ describe('Story', () => {
|
|
|
23
23
|
});
|
|
24
24
|
});
|
|
25
25
|
|
|
26
|
-
describe('creator', () => {
|
|
26
|
+
describe('creator', () => {
|
|
27
27
|
let s = null;
|
|
28
28
|
|
|
29
29
|
beforeEach(() => {
|
|
@@ -42,7 +42,7 @@ describe('Story', () => {
|
|
|
42
42
|
});
|
|
43
43
|
});
|
|
44
44
|
|
|
45
|
-
describe('creatorVersion', () => {
|
|
45
|
+
describe('creatorVersion', () => {
|
|
46
46
|
let s = null;
|
|
47
47
|
|
|
48
48
|
beforeEach(() => {
|
|
@@ -61,7 +61,7 @@ describe('Story', () => {
|
|
|
61
61
|
});
|
|
62
62
|
});
|
|
63
63
|
|
|
64
|
-
describe('IFID', () => {
|
|
64
|
+
describe('IFID', () => {
|
|
65
65
|
let s = null;
|
|
66
66
|
|
|
67
67
|
beforeEach(() => {
|
|
@@ -80,7 +80,7 @@ describe('Story', () => {
|
|
|
80
80
|
});
|
|
81
81
|
});
|
|
82
82
|
|
|
83
|
-
describe('format', () => {
|
|
83
|
+
describe('format', () => {
|
|
84
84
|
let s = null;
|
|
85
85
|
|
|
86
86
|
beforeEach(() => {
|
|
@@ -99,7 +99,7 @@ describe('Story', () => {
|
|
|
99
99
|
});
|
|
100
100
|
});
|
|
101
101
|
|
|
102
|
-
describe('formatVersion', () => {
|
|
102
|
+
describe('formatVersion', () => {
|
|
103
103
|
let s = null;
|
|
104
104
|
|
|
105
105
|
beforeEach(() => {
|
|
@@ -118,7 +118,7 @@ describe('Story', () => {
|
|
|
118
118
|
});
|
|
119
119
|
});
|
|
120
120
|
|
|
121
|
-
describe('name', () => {
|
|
121
|
+
describe('name', () => {
|
|
122
122
|
let s = null;
|
|
123
123
|
|
|
124
124
|
beforeEach(() => {
|
|
@@ -137,7 +137,7 @@ describe('Story', () => {
|
|
|
137
137
|
});
|
|
138
138
|
});
|
|
139
139
|
|
|
140
|
-
describe('zoom', () => {
|
|
140
|
+
describe('zoom', () => {
|
|
141
141
|
let s = null;
|
|
142
142
|
|
|
143
143
|
beforeEach(() => {
|
|
@@ -156,7 +156,7 @@ describe('Story', () => {
|
|
|
156
156
|
});
|
|
157
157
|
});
|
|
158
158
|
|
|
159
|
-
describe('metadata', () => {
|
|
159
|
+
describe('metadata', () => {
|
|
160
160
|
let s = null;
|
|
161
161
|
|
|
162
162
|
beforeEach(() => {
|
|
@@ -175,7 +175,7 @@ describe('Story', () => {
|
|
|
175
175
|
});
|
|
176
176
|
});
|
|
177
177
|
|
|
178
|
-
describe('start', () => {
|
|
178
|
+
describe('start', () => {
|
|
179
179
|
let s = null;
|
|
180
180
|
|
|
181
181
|
beforeEach(() => {
|
|
@@ -194,7 +194,7 @@ describe('Story', () => {
|
|
|
194
194
|
});
|
|
195
195
|
});
|
|
196
196
|
|
|
197
|
-
describe('tagColors', () => {
|
|
197
|
+
describe('tagColors', () => {
|
|
198
198
|
let s = null;
|
|
199
199
|
|
|
200
200
|
beforeEach(() => {
|
|
@@ -216,7 +216,7 @@ describe('Story', () => {
|
|
|
216
216
|
});
|
|
217
217
|
});
|
|
218
218
|
|
|
219
|
-
describe('addPassage()', () => {
|
|
219
|
+
describe('addPassage()', () => {
|
|
220
220
|
let s = null;
|
|
221
221
|
|
|
222
222
|
beforeEach(() => {
|
|
@@ -244,22 +244,22 @@ describe('Story', () => {
|
|
|
244
244
|
});
|
|
245
245
|
});
|
|
246
246
|
|
|
247
|
-
describe('
|
|
247
|
+
describe('removePassageByName()', () => {
|
|
248
248
|
let s = null;
|
|
249
249
|
|
|
250
250
|
beforeEach(() => {
|
|
251
251
|
s = new Story();
|
|
252
252
|
});
|
|
253
253
|
|
|
254
|
-
it('
|
|
254
|
+
it('removePassageByName() - should decrease size', () => {
|
|
255
255
|
s.addPassage(new Passage('Find'));
|
|
256
256
|
s.addPassage(new Passage('Find2'));
|
|
257
|
-
s.
|
|
257
|
+
s.removePassageByName('Find');
|
|
258
258
|
expect(s.size()).toBe(1);
|
|
259
259
|
});
|
|
260
260
|
});
|
|
261
261
|
|
|
262
|
-
describe('getPassagesByTag()', () => {
|
|
262
|
+
describe('getPassagesByTag()', () => {
|
|
263
263
|
let s = null;
|
|
264
264
|
|
|
265
265
|
beforeEach(() => {
|
|
@@ -290,7 +290,7 @@ describe('Story', () => {
|
|
|
290
290
|
});
|
|
291
291
|
});
|
|
292
292
|
|
|
293
|
-
describe('getPassageByName()', () => {
|
|
293
|
+
describe('getPassageByName()', () => {
|
|
294
294
|
let s = null;
|
|
295
295
|
|
|
296
296
|
beforeEach(() => {
|
|
@@ -305,7 +305,7 @@ describe('Story', () => {
|
|
|
305
305
|
});
|
|
306
306
|
});
|
|
307
307
|
|
|
308
|
-
describe('getPassageByPID()', () => {
|
|
308
|
+
describe('getPassageByPID()', () => {
|
|
309
309
|
let s = null;
|
|
310
310
|
|
|
311
311
|
beforeEach(() => {
|
|
@@ -324,7 +324,7 @@ describe('Story', () => {
|
|
|
324
324
|
});
|
|
325
325
|
});
|
|
326
326
|
|
|
327
|
-
describe('forEach()', () => {
|
|
327
|
+
describe('forEach()', () => {
|
|
328
328
|
let s = null;
|
|
329
329
|
|
|
330
330
|
beforeEach(() => {
|
|
@@ -346,9 +346,30 @@ describe('Story', () => {
|
|
|
346
346
|
s.forEach(null);
|
|
347
347
|
}).toThrow();
|
|
348
348
|
});
|
|
349
|
+
|
|
350
|
+
it('forEach() - should ignore StoryTitle', () => {
|
|
351
|
+
let count = 0;
|
|
352
|
+
s.addPassage(new Passage('StoryTitle', 'Test'));
|
|
353
|
+
s.forEach(() => {count++});
|
|
354
|
+
expect(count).toBe(0);
|
|
355
|
+
});
|
|
356
|
+
|
|
357
|
+
it('forEach() - should ignore "script" tags', () => {
|
|
358
|
+
let count = 0;
|
|
359
|
+
s.addPassage(new Passage('Test', 'Test', ['script']));
|
|
360
|
+
s.forEach(() => {count++});
|
|
361
|
+
expect(count).toBe(0);
|
|
362
|
+
});
|
|
363
|
+
|
|
364
|
+
it('forEach() - should ignore "stylesheet" tags', () => {
|
|
365
|
+
let count = 0;
|
|
366
|
+
s.addPassage(new Passage('Test', 'Test', ['stylesheet']));
|
|
367
|
+
s.forEach(() => {count++});
|
|
368
|
+
expect(count).toBe(0);
|
|
369
|
+
});
|
|
349
370
|
});
|
|
350
371
|
|
|
351
|
-
describe('size()', () => {
|
|
372
|
+
describe('size()', () => {
|
|
352
373
|
let s = null;
|
|
353
374
|
|
|
354
375
|
beforeEach(() => {
|
|
@@ -365,5 +386,38 @@ describe('Story', () => {
|
|
|
365
386
|
// Test size after adding one
|
|
366
387
|
expect(s.size()).toBe(1);
|
|
367
388
|
});
|
|
389
|
+
|
|
390
|
+
it('size() - should not count StoryTitle', () => {
|
|
391
|
+
// Create a Passage
|
|
392
|
+
const p = new Passage('StoryTitle', 'Test');
|
|
393
|
+
// Test initial size
|
|
394
|
+
expect(s.size()).toBe(0);
|
|
395
|
+
// Add a passage
|
|
396
|
+
s.addPassage(p);
|
|
397
|
+
// Test size after adding one
|
|
398
|
+
expect(s.size()).toBe(0);
|
|
399
|
+
});
|
|
400
|
+
|
|
401
|
+
it('size() - should not count script tags', () => {
|
|
402
|
+
// Create a Passage
|
|
403
|
+
const p = new Passage('Test', 'Test', ['script']);
|
|
404
|
+
// Test initial size
|
|
405
|
+
expect(s.size()).toBe(0);
|
|
406
|
+
// Add a passage
|
|
407
|
+
s.addPassage(p);
|
|
408
|
+
// Test size after adding one
|
|
409
|
+
expect(s.size()).toBe(0);
|
|
410
|
+
});
|
|
411
|
+
|
|
412
|
+
it('size() - should not count script tags', () => {
|
|
413
|
+
// Create a Passage
|
|
414
|
+
const p = new Passage('Test', 'Test', ['stylesheet']);
|
|
415
|
+
// Test initial size
|
|
416
|
+
expect(s.size()).toBe(0);
|
|
417
|
+
// Add a passage
|
|
418
|
+
s.addPassage(p);
|
|
419
|
+
// Test size after adding one
|
|
420
|
+
expect(s.size()).toBe(0);
|
|
421
|
+
});
|
|
368
422
|
});
|
|
369
423
|
});
|
package/test/StoryFormat.test.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import StoryFormat from '../src/StoryFormat.js';
|
|
2
2
|
|
|
3
|
-
describe('StoryFormat',
|
|
4
|
-
describe('#constructor()',
|
|
5
|
-
|
|
3
|
+
describe('StoryFormat', () => {
|
|
4
|
+
describe('#constructor()', () => {
|
|
5
|
+
it('Should create default values', () => {
|
|
6
6
|
const sf = new StoryFormat();
|
|
7
7
|
expect(sf.name).toBe('');
|
|
8
8
|
expect(sf.version).toBe('');
|
|
@@ -15,14 +15,14 @@ describe('StoryFormat', function () {
|
|
|
15
15
|
});
|
|
16
16
|
});
|
|
17
17
|
|
|
18
|
-
describe('name',
|
|
19
|
-
|
|
18
|
+
describe('name', () => {
|
|
19
|
+
it('Set new String', () => {
|
|
20
20
|
const sf = new StoryFormat();
|
|
21
21
|
sf.name = 'New';
|
|
22
22
|
expect(sf.name).toBe('New');
|
|
23
23
|
});
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
it('Throw error if non-String', () => {
|
|
26
26
|
const sf = new StoryFormat();
|
|
27
27
|
expect(() => {
|
|
28
28
|
sf.name = 1;
|
|
@@ -30,14 +30,14 @@ describe('StoryFormat', function () {
|
|
|
30
30
|
});
|
|
31
31
|
});
|
|
32
32
|
|
|
33
|
-
describe('version',
|
|
34
|
-
|
|
33
|
+
describe('version', () => {
|
|
34
|
+
it('Set new String', () => {
|
|
35
35
|
const sf = new StoryFormat();
|
|
36
36
|
sf.version = 'New';
|
|
37
37
|
expect(sf.version).toBe('New');
|
|
38
38
|
});
|
|
39
39
|
|
|
40
|
-
|
|
40
|
+
it('Throw error if non-String', () => {
|
|
41
41
|
const sf = new StoryFormat();
|
|
42
42
|
expect(() => {
|
|
43
43
|
sf.version = 1;
|
|
@@ -45,14 +45,14 @@ describe('StoryFormat', function () {
|
|
|
45
45
|
});
|
|
46
46
|
});
|
|
47
47
|
|
|
48
|
-
describe('author',
|
|
49
|
-
|
|
48
|
+
describe('author', () => {
|
|
49
|
+
it('Set new String', () => {
|
|
50
50
|
const sf = new StoryFormat();
|
|
51
51
|
sf.author = 'New';
|
|
52
52
|
expect(sf.author).toBe('New');
|
|
53
53
|
});
|
|
54
54
|
|
|
55
|
-
|
|
55
|
+
it('Throw error if non-String', () => {
|
|
56
56
|
const sf = new StoryFormat();
|
|
57
57
|
expect(() => {
|
|
58
58
|
sf.author = 1;
|
|
@@ -60,14 +60,14 @@ describe('StoryFormat', function () {
|
|
|
60
60
|
});
|
|
61
61
|
});
|
|
62
62
|
|
|
63
|
-
describe('image',
|
|
64
|
-
|
|
63
|
+
describe('image', () => {
|
|
64
|
+
it('Set new String', () => {
|
|
65
65
|
const sf = new StoryFormat();
|
|
66
66
|
sf.image = 'New';
|
|
67
67
|
expect(sf.image).toBe('New');
|
|
68
68
|
});
|
|
69
69
|
|
|
70
|
-
|
|
70
|
+
it('Throw error if non-String', () => {
|
|
71
71
|
const sf = new StoryFormat();
|
|
72
72
|
expect(() => {
|
|
73
73
|
sf.image = 1;
|
|
@@ -75,14 +75,14 @@ describe('StoryFormat', function () {
|
|
|
75
75
|
});
|
|
76
76
|
});
|
|
77
77
|
|
|
78
|
-
describe('url',
|
|
79
|
-
|
|
78
|
+
describe('url', () => {
|
|
79
|
+
it('Set new String', () => {
|
|
80
80
|
const sf = new StoryFormat();
|
|
81
81
|
sf.url = 'New';
|
|
82
82
|
expect(sf.url).toBe('New');
|
|
83
83
|
});
|
|
84
84
|
|
|
85
|
-
|
|
85
|
+
it('Throw error if non-String', () => {
|
|
86
86
|
const sf = new StoryFormat();
|
|
87
87
|
expect(() => {
|
|
88
88
|
sf.url = 1;
|
|
@@ -90,14 +90,14 @@ describe('StoryFormat', function () {
|
|
|
90
90
|
});
|
|
91
91
|
});
|
|
92
92
|
|
|
93
|
-
describe('license',
|
|
94
|
-
|
|
93
|
+
describe('license', () => {
|
|
94
|
+
it('Set new String', () => {
|
|
95
95
|
const sf = new StoryFormat();
|
|
96
96
|
sf.license = 'New';
|
|
97
97
|
expect(sf.license).toBe('New');
|
|
98
98
|
});
|
|
99
99
|
|
|
100
|
-
|
|
100
|
+
it('Throw error if non-String', () => {
|
|
101
101
|
const sf = new StoryFormat();
|
|
102
102
|
expect(() => {
|
|
103
103
|
sf.license = 1;
|
|
@@ -105,14 +105,14 @@ describe('StoryFormat', function () {
|
|
|
105
105
|
});
|
|
106
106
|
});
|
|
107
107
|
|
|
108
|
-
describe('proofing',
|
|
109
|
-
|
|
108
|
+
describe('proofing', () => {
|
|
109
|
+
it('Set new String', () => {
|
|
110
110
|
const sf = new StoryFormat();
|
|
111
111
|
sf.proofing = true;
|
|
112
112
|
expect(sf.proofing).toBe(true);
|
|
113
113
|
});
|
|
114
114
|
|
|
115
|
-
|
|
115
|
+
it('Throw error if non-String', () => {
|
|
116
116
|
const sf = new StoryFormat();
|
|
117
117
|
expect(() => {
|
|
118
118
|
sf.proofing = 1;
|
|
@@ -120,14 +120,14 @@ describe('StoryFormat', function () {
|
|
|
120
120
|
});
|
|
121
121
|
});
|
|
122
122
|
|
|
123
|
-
describe('source',
|
|
124
|
-
|
|
123
|
+
describe('source', () => {
|
|
124
|
+
it('Set new String', () => {
|
|
125
125
|
const sf = new StoryFormat();
|
|
126
126
|
sf.source = 'New';
|
|
127
127
|
expect(sf.source).toBe('New');
|
|
128
128
|
});
|
|
129
129
|
|
|
130
|
-
|
|
130
|
+
it('Throw error if non-String', () => {
|
|
131
131
|
const sf = new StoryFormat();
|
|
132
132
|
expect(() => {
|
|
133
133
|
sf.source = 1;
|
|
@@ -135,14 +135,14 @@ describe('StoryFormat', function () {
|
|
|
135
135
|
});
|
|
136
136
|
});
|
|
137
137
|
|
|
138
|
-
describe('description',
|
|
139
|
-
|
|
138
|
+
describe('description', () => {
|
|
139
|
+
it('Set new String', () => {
|
|
140
140
|
const sf = new StoryFormat();
|
|
141
141
|
sf.description = 'New';
|
|
142
142
|
expect(sf.description).toBe('New');
|
|
143
143
|
});
|
|
144
144
|
|
|
145
|
-
|
|
145
|
+
it('Throw error if non-String', () => {
|
|
146
146
|
const sf = new StoryFormat();
|
|
147
147
|
expect(() => {
|
|
148
148
|
sf.description = 1;
|
|
@@ -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);
|