Skip to content

Commit

Permalink
Initial unit tests added
Browse files Browse the repository at this point in the history
Added Mocha to the project along with initial set of unit tests for parsers (Twee and HTML) as well as for FileReader.

Noticed bugs in process and changed TweeParser and HTMLParser code.
  • Loading branch information
Dan Cox authored and Dan Cox committed Apr 11, 2019
1 parent 07a2ca5 commit f59a7b0
Show file tree
Hide file tree
Showing 10 changed files with 250 additions and 1,352 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
node_modules
testing
storyformats
builds
.DS_Store
4 changes: 1 addition & 3 deletions HTMLParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@ class HTMLParser {
* @constructor
*/
constructor (content) {
this.inputContents = content;
this.outputContents = "";

this.dom = null;
this.story = null;

this.parse(this.inputContents);
this.parse(content);
}

parse(content) {
Expand Down
16 changes: 3 additions & 13 deletions TweeParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class TweeParser {
*/
parse(fileContents) {

// Check if there are extra notes in the files
// Check if there are extra content in the files
// If so, cut it all out for the parser
if(fileContents[0] != ':' && fileContents[1] != ':') {

Expand Down Expand Up @@ -215,24 +215,14 @@ class TweeParser {

} catch(event) {

// Silently fail
this.story.metadata = {};
// Silently fail with default values

}

// Remove the StoryMetadata passage
this.passages = this.passages.filter(p => p.name !== "StoryMetadata");

} else {

if(!this.story.metadata.hasOwnProperty('ifid') ) {

throw new Error("This story does not have an IFID.");

}

}

}

// Set the passages to the internal story
this.story.passages = this.passages;
Expand Down
Loading

0 comments on commit f59a7b0

Please sign in to comment.