Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
verify cache objects in debug mode
Browse files Browse the repository at this point in the history
retorquere committed May 29, 2015
1 parent a898a59 commit 5e8ca81
Showing 2 changed files with 34 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
@@ -338,7 +338,7 @@ task :test, [:tag] => [XPI, :plugins] do |t, args|
end

if OS.mac?
sh "script -q -t 1 cucumuber.log cucumber --require features #{rerun} --strict #{tag}"
sh "script -q -t 1 cucumuber.log cucumber --strict #{tag}"
else
sh "script -ec 'cucumber --require features #{rerun} --strict #{tag}' cucumber.log"
end
36 changes: 33 additions & 3 deletions chrome/content/zotero-better-bibtex/cache.coffee
Original file line number Diff line number Diff line change
@@ -39,6 +39,37 @@ Zotero.BetterBibTeX.cache = new class
@cache.flushChanges()
@access.flushChanges()

verify: (entry) ->
return entry unless Zotero.BetterBibTeX.pref.get('debug') || Zotero.BetterBibTeX.pref.get('testMode')

verify = {itemID: 1, exportCharset: 'x', exportNotes: true, getCollections: true, preserveBibTeXVariables: true, translatorID: 'x', useJournalAbbreviation: true }

for own key, value of entry
switch
when key in ['$loki', 'meta'] then # ignore

when verify[key] == undefined
throw new Error("Unexpected field #{key} in #{typeof entry} #{JSON.stringify(entry)}")

when verify[key] == null
delete verify[key]

when typeof verify[key] == 'string' && typeof value == 'string' && value.trim() != ''
delete verify[key]

when typeof verify[key] == 'number' && typeof value == 'number'
delete verify[key]

when typeof verify[key] == 'boolean' && typeof value == 'boolean'
delete verify[key]

else
throw new Error("field #{key} of #{typeof entry} #{JSON.stringify(entry)} is unexpected #{typeof value} #{value}")

verify = Object.keys(verify)
return entry if verify.length == 0
throw new Error("missing fields #{verify} in #{typeof entry} #{JSON.stringify(entry)}")

remove: (what) ->
what.itemID = @integer(what.itemID) unless what.itemID == undefined
@cache.removeWhere(what)
@@ -91,16 +122,15 @@ Zotero.BetterBibTeX.cache = new class
@access.flushChanges()

record: (itemID, context) ->
throw new Error("No translator ID supplied in #{JSON.stringify(Object.keys(context))}") unless context.translatorID
return {
return @verify({
itemID: @integer(itemID)
exportCharset: (context.exportCharset || 'UTF-8').toUpperCase()
exportNotes: !!context.exportNotes
getCollections: !!context.getCollections
preserveBibTeXVariables: !!context.preserveBibTeXVariables
translatorID: context.translatorID
useJournalAbbreviation: !!context.useJournalAbbreviation
}
})

clone: (obj) ->
clone = JSON.parse(JSON.stringify(obj))

0 comments on commit 5e8ca81

Please sign in to comment.