From 1fea00245e051b4d88195239adce32c0006666b9 Mon Sep 17 00:00:00 2001 From: Simon Kornblith Date: Mon, 20 Jun 2011 01:22:41 +0000 Subject: [PATCH] - Make translator tester run detect code - Add support for creating tests to translatorTester.js --- .../tools/testTranslators/testTranslators.js | 2 +- .../tools/testTranslators/translatorTester.js | 150 ++++++++++++++---- 2 files changed, 116 insertions(+), 36 deletions(-) diff --git a/chrome/content/zotero/tools/testTranslators/testTranslators.js b/chrome/content/zotero/tools/testTranslators/testTranslators.js index ede5a3cea..9f806d3ca 100644 --- a/chrome/content/zotero/tools/testTranslators/testTranslators.js +++ b/chrome/content/zotero/tools/testTranslators/testTranslators.js @@ -114,7 +114,7 @@ TranslatorTestView.prototype.updateStatus = function(obj) { */ TranslatorTestView.prototype.runTests = function(doneCallback) { var me = this; - var newCallback = function(obj, status, message) { + var newCallback = function(obj, test, status, message) { me.updateStatus(obj); if(obj.pending.length === 0) { doneCallback(); diff --git a/chrome/content/zotero/tools/testTranslators/translatorTester.js b/chrome/content/zotero/tools/testTranslators/translatorTester.js index a720f9a4e..ad49c9a8f 100644 --- a/chrome/content/zotero/tools/testTranslators/translatorTester.js +++ b/chrome/content/zotero/tools/testTranslators/translatorTester.js @@ -42,7 +42,7 @@ const Zotero_TranslatorTester_IGNORE_FIELDS = ["complete", "accessDate", "checkF Zotero_TranslatorTester = function(translator, type, debug) { this._type = type; this._translator = translator; - this._debug = (debug ? debug : function(a, b) { Zotero.debug(a, b) }); + this._debug = debug ? debug : function(obj, a, b) { Zotero.debug(a, b) }; this.tests = []; this.pending = []; @@ -73,7 +73,40 @@ Zotero_TranslatorTester = function(translator, type, debug) { } } } -} +}; + +/** + * Removes document objects, which contain cyclic references, and other fields to be ignored from items + * @param {Object} Item, in the format returned by Zotero.Item.serialize() + */ +Zotero_TranslatorTester._sanitizeItem = function(item) { + // remove cyclic references + if(item.attachments && item.attachments.length) { + for (var i=0; i 1 || + test.items.length === 1 && translators[0].itemType !== test.items[0].itemType) { + testDoneCallback(this, test, "failed", "Detection returned wrong item type"); + return; + } + + translate.setTranslator(this._translator); + translate.translate(false); +}; + /** * Checks whether the results of translation match what is expected by the test * @param {Object} test Test that was executed @@ -146,45 +207,64 @@ Zotero_TranslatorTester.prototype.runTest = function(test, doc, testDoneCallback */ Zotero_TranslatorTester.prototype._checkResult = function(test, translate, returnValue, testDoneCallback) { if(!returnValue) { - testDoneCallback(this, "failed", "Translation failed; examine debug output for errors"); + testDoneCallback(this, test, "failed", "Translation failed; examine debug output for errors"); return; } if(!translate.newItems.length) { - testDoneCallback(this, "failed", "Translation failed; no items returned"); + testDoneCallback(this, test, "failed", "Translation failed: no items returned"); return; } if(translate.newItems.length !== test.items.length) { - testDoneCallback(this, "unknown", "Expected "+test.items.length+" items; got "+translate.newItems.length); + testDoneCallback(this, test, "unknown", "Expected "+test.items.length+" items; got "+translate.newItems.length); return; } for(var i in test.items) { - var testItem = test.items[i]; - var translatedItem = translate.newItems[i]; - - // Clear attachment document objects - if (translatedItem && translatedItem.attachments && translatedItem.attachments.length) { - for (var i=0; i