Improve test for event-title substitution

And add comments

Follow-up to 20d0f103f
This commit is contained in:
Dan Stillman 2022-08-10 01:33:13 -04:00
parent ebacb83563
commit c90f8415b3
2 changed files with 12 additions and 2 deletions

View file

@ -799,10 +799,16 @@ Zotero.Style.prototype.getCiteProc = function(locale, format, automaticJournalAb
}
};
/**
* Temporarily substitute `event-title` for `event`
*
* Until https://github.com/citation-style-language/styles/issues/6151
*/
Zotero.Style.prototype._eventToEventTitle = function (xml) {
var parser = Components.classes["@mozilla.org/xmlextras/domparser;1"]
.createInstance(Components.interfaces.nsIDOMParser);
var doc = parser.parseFromString(xml, "text/xml");
// Ignore styles that already include `event-title`
if (doc.querySelector('[variable*="event-title"]')) {
return xml;
}
@ -813,6 +819,7 @@ Zotero.Style.prototype._eventToEventTitle = function (xml) {
var changed = false;
for (let elem of elems) {
let variable = elem.getAttribute('variable');
// Must be "event" or "event foo", not, say, "event-place"
if (!/event( |$)/.test(variable)) {
continue;
}

View file

@ -98,7 +98,9 @@ describe("Zotero.Styles", function() {
<layout>
<text variable="event"/>
<text value=" - "/>
<text variable="event event-place"/>
<text variable="event foo"/>
<text value=" - "/>
<text variable="event-place"/>
</layout>
</bibliography>
</style>
@ -113,6 +115,7 @@ describe("Zotero.Styles", function() {
}
);
item.setField('conferenceName', 'Conference');
item.setField('place', 'Place');
await item.saveTx();
});
@ -121,7 +124,7 @@ describe("Zotero.Styles", function() {
var cslEngine = style.getCiteProc('en-US', 'text');
var text = Zotero.Cite.makeFormattedBibliographyOrCitationList(cslEngine, [item], "text");
cslEngine.free();
assert.equal(text, 'Conference - Conference\n');
assert.equal(text, 'Conference - Conference - Place\n');
});
});
});