Add unit tests to verify data integrity
This commit is contained in:
@@ -17,6 +17,7 @@ module.exports = class CommandParserVersionBase
|
|||||||
|
|
||||||
@_model = options.model
|
@_model = options.model
|
||||||
@_showAllErrors = options.showAllErrors
|
@_showAllErrors = options.showAllErrors
|
||||||
|
@errors = []
|
||||||
|
|
||||||
# Class Methods ################################################################################
|
# Class Methods ################################################################################
|
||||||
|
|
||||||
@@ -38,6 +39,7 @@ module.exports = class CommandParserVersionBase
|
|||||||
parse: (text)->
|
parse: (text)->
|
||||||
@_rawData = {}
|
@_rawData = {}
|
||||||
@_lineNumber = 1
|
@_lineNumber = 1
|
||||||
|
@errors = []
|
||||||
|
|
||||||
@_lines = text.split '\n'
|
@_lines = text.split '\n'
|
||||||
@_lineNumber = 0
|
@_lineNumber = 0
|
||||||
@@ -105,6 +107,7 @@ module.exports = class CommandParserVersionBase
|
|||||||
catch e
|
catch e
|
||||||
e.message = "line #{@_lineNumber}: #{e.message}"
|
e.message = "line #{@_lineNumber}: #{e.message}"
|
||||||
if not @_showAllErrors then throw e
|
if not @_showAllErrors then throw e
|
||||||
|
@errors.push e
|
||||||
logger.error -> e.message
|
logger.error -> e.message
|
||||||
|
|
||||||
_parseHereDoc: (line)->
|
_parseHereDoc: (line)->
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ module.exports = class VersionedParserBase
|
|||||||
constructor: (options={})->
|
constructor: (options={})->
|
||||||
@_parsers = @_createParsers options
|
@_parsers = @_createParsers options
|
||||||
@_currentSchema = _.chain(@_parsers).keys().last().value()
|
@_currentSchema = _.chain(@_parsers).keys().last().value()
|
||||||
|
@errors = []
|
||||||
|
|
||||||
# Class Members ################################################################################
|
# Class Members ################################################################################
|
||||||
|
|
||||||
@@ -27,6 +28,7 @@ module.exports = class VersionedParserBase
|
|||||||
if not parser? then throw new Error "schema version #{schema} is not supported"
|
if not parser? then throw new Error "schema version #{schema} is not supported"
|
||||||
|
|
||||||
parser.parse text
|
parser.parse text
|
||||||
|
@errors = parser.errors
|
||||||
|
|
||||||
return @_model
|
return @_model
|
||||||
|
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ group: Agriculture
|
|||||||
pattern: ... .0. ...
|
pattern: ... .0. ...
|
||||||
recipe:
|
recipe:
|
||||||
input: Coffee Beans
|
input: Coffee Beans
|
||||||
pattern: ... .0. ...
|
pattern: ... .0. .0.
|
||||||
quantity: 3
|
quantity: 3
|
||||||
tools: Macerator
|
tools: Macerator
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,46 @@
|
|||||||
|
###
|
||||||
|
Crafting Guide - data.test.coffee
|
||||||
|
|
||||||
|
Copyright (c) 2015 by Redwood Labs
|
||||||
|
All rights reserved.
|
||||||
|
###
|
||||||
|
|
||||||
|
Mod = require '../src/coffee/models/mod'
|
||||||
|
ModParser = require '../src/coffee/models/mod_parser'
|
||||||
|
ModVersion = require '../src/coffee/models/mod_version'
|
||||||
|
ModVersionParser = require '../src/coffee/models/mod_version_parser'
|
||||||
|
fs = require 'fs'
|
||||||
|
|
||||||
|
########################################################################################################################
|
||||||
|
|
||||||
|
describe 'data files for', ->
|
||||||
|
|
||||||
|
for modSlug in fs.readdirSync './static/data/'
|
||||||
|
do (modSlug)->
|
||||||
|
describe modSlug, ->
|
||||||
|
|
||||||
|
mod = new Mod slug:modSlug
|
||||||
|
modParser = new ModParser model:mod, showAllErrors:true
|
||||||
|
modParser.parse fs.readFileSync "./static/data/#{modSlug}/mod.cg", 'utf8'
|
||||||
|
|
||||||
|
it 'loads mod.cg without errors', ->
|
||||||
|
modParser.errors.should.eql []
|
||||||
|
mod.name.should.not.equal ''
|
||||||
|
mod.activeModVersion.should.exist
|
||||||
|
|
||||||
|
it 'has an icon file', ->
|
||||||
|
stats = fs.statSync "./static/browse/#{modSlug}/icon.png"
|
||||||
|
stats.isFile().should.be.true
|
||||||
|
|
||||||
|
mod.eachModVersion (modVersion)->
|
||||||
|
do (modVersion)->
|
||||||
|
describe modVersion.version, ->
|
||||||
|
|
||||||
|
modVersionParser = new ModVersionParser model:modVersion, showAllErrors:true
|
||||||
|
fileName = "./static/data/#{modSlug}/#{modVersion.version}/mod-version.cg"
|
||||||
|
modVersionParser.parse fs.readFileSync fileName, 'utf8'
|
||||||
|
|
||||||
|
it 'loads mod-version.cg without errors', ->
|
||||||
|
modVersionParser.errors.should.eql []
|
||||||
|
_.keys(modVersion._items).length.should.be.greaterThan 0
|
||||||
|
_.keys(modVersion._recipes).length.should.be.greaterThan 0
|
||||||
Reference in New Issue
Block a user