citation-style-language / test-suite

11 stars 12 forks source link

================== The CSL Test Suite

Developer's Manual

.. class:: fixed

citationstyles.org__

__ http://citationstyles.org/

.. class:: info-version

version 1.00##a2##

.. class:: info-date

=D=25 May 2010=D=

.. class:: contributors

Author of this manual

.. |link| image:: link.png

========

.. contents:: Table of Contents

========

############ Introduction ############

CSL ships with a large bundle of test data for use in the development and maintenance of CSL processors. The tests begin as individual human-friendly fixtures written in a special format, shown in the sample file immediately below. Tests are prepared for use by grinding them into a machine-friendly form (JSON). The JSON form of tests can be run against processors in a test-bed environment with processor-specific tools prepared for that purpose.

################### Preparing the tests ###################

Tests can be validated and prepared (or "compiled") using the ./processor.py script in the root directory of the archive. The script accepts the following options:

--help: List the script options with a brief description of each and exit --cranky validate style code for testing against the CSL schema using the jing XML tool. --grind Force grinding of human-readable test code into machine- readable form. --verbose
Display test names during processing.

############## Fixture layout ##############

The human-readable version of each test fixture is composed in the format below. The five sections MODE, RESULT, CSL and INPUT are required, and may be arranged in any order within the fixture file. As the sample below illustrates, text outside of the section delimiters is ignored. The sample file below shows the layout of a typical fixture. See the explanations of the individual sections further below for information on the usage of each.

.. class:: clothesline

..

  .. admonition:: Hint

     Four additional sections are available for special
     purposes.  The optional sections 
     ``BIBENTRIES``, ``BIBSECTION``, ``CITATIONS`` and ``CITATION-ITEMS``
     are also explained below.

.. sourcecode:: text

===== MODE =====>> citation <<===== MODE =====<<

Everything between the section blocks is

ignored. Comment markup can be used for

clarity, but it is not required.

===== RESULT =====>> John Doe <<===== RESULT =====<<

===== CSL =====>> <style xmlns="http://purl.org/net/xbiblio/csl" class="in-text" version="1.0">

<updated>2009-08-10T04:49:00+09:00</updated> </info> <citation> <layout> <names variable="author"> <name /> </names> </layout> </citation> <p></style> <<===== CSL =====<<</p> <p>===== INPUT =====>> [ { "id":"ID-1", "type": "book", "author": [ { "name":"Doe, John" } ], "issued": { "date-parts": [ [ "1965", "6", "1" ] ] } } ] <<===== INPUT =====<<</p> </blockquote> </blockquote> <p>^^^^^^^^^^^^^^^^^ Required sections ^^^^^^^^^^^^^^^^^</p> <p>The following four sections (<code>MODE</code>, <code>CSL</code>, <code>INPUT</code>, <code>RESULT</code>) are required in all test fixtures.</p> <p>!!!! MODE !!!!</p> <p>A single string tells whether to test <code>citation</code> or <code>bibliography</code> output. In the former case, the test will be performed using the <code>makeCitationCluster()</code> command if a <code>CITATION-ITEMS</code> area is included in the test fixture, or if neither that nor a <code>CITATIONS</code> area is included. If a <code>CITATIONS</code> area is included, <code>citation</code> mode uses the <code>processCitationCluster</code> command.</p> <p>In the case of <code>bibliography</code> mode, the bibliography generation command should be used, with output possibly filtered by the conditions specified in a <code>BIBSECTION</code> area:</p> <p>.. sourcecode:: text</p> <blockquote> <blockquote> <p>===== MODE =====>> citation <<===== MODE =====<<</p> </blockquote> </blockquote> <p>!!! CSL !!!</p> <p>The code to be used in the test must be valid as a complete, if minimal, CSL style:</p> <p>.. sourcecode:: text</p> <blockquote> <blockquote> <p>===== CSL =====>> <style xmlns="<a rel="noreferrer nofollow" target="_blank" href="http://purl.org/net/xbiblio/csl">http://purl.org/net/xbiblio/csl</a>" class="in-text" version="1.0"></p> <info> <id /> <title /> <updated>2009-08-10T04:49:00+09:00</updated> </info> <p><citation et-al-min="3" et-al-use-first="1"></p> <layout delimiter="; "> <group delimiter=" "> <names> <name form="short"/> </names> <date variable="issued" date-parts="year" form="text" prefix="(" suffix=")"/> </group> </layout> <p></citation></p> <bibliography> <layout> <group delimiter=" "> <names variable="author"> <name delimiter=" " initialize-with="."/> </names> <date variable="issued" date-parts="year" form="text" prefix="(" suffix=")"/> </group> </layout> </bibliography> <p></style> <<===== CSL =====<<</p> </blockquote> </blockquote> <p>!!!!! INPUT !!!!!</p> <p>The <code>INPUT</code> section provides the item data to be registered in the processor. In a simple test fixture that contains none of the optional areas <code>BIBENTRIES</code>, <code>BIBSECTION</code> <code>CITATIONS</code> or <code>CITATION-ITEMS</code>, a citation or bibliography is requested for <em>all</em> of the items in the <code>INPUT</code> section (where one of those two optional sections is included, the testing behavior is slightly different; see the discussion of the relevant sections below for details):</p> <p>.. sourcecode:: text</p> <blockquote> <blockquote> <p>===== INPUT =====>> [ { "id":"ID-1", "author": [ { "name":"Noakes, John" }, { "name":"Doe, John" }, { "name":"Roe, Jane" } ], "issued": { "date-parts": [ [ 2005 ] ] } }, { "id":"ID-2", "author": [ { "name":"Stoakes, Richard" } ], "issued": { "date-parts": [ [ 1898 ] ] } } ] <<===== INPUT =====<<</p> </blockquote> </blockquote> <p>!!!!!! RESULT !!!!!!</p> <p>A string to compare with the citation or bibliography output received from the processor.</p> <p>.. sourcecode:: text</p> <blockquote> <blockquote> <p>===== RESULT =====>> (Noakes, et al. 2005; Stoakes 1898) <<===== RESULT =====<<</p> </blockquote> </blockquote> <p>Note that in <code>bibliography</code> mode, the HTML string output used for testing will be affixed with a standard set of wrapper tags, which must be written into the result string used for comparison:</p> <p>.. sourcecode:: text</p> <blockquote> <blockquote> <p>===== RESULT =====>></p> <div class="csl-bib-body"> <div class="csl-entry">J. Noakes, J. Doe, J. Roe (2005)</div> <div class="csl-entry">R. Stoakes (1898)</div> </div> <p><<===== RESULT =====<<</p> </blockquote> </blockquote> <p>^^^^^^^^^^^^^^^^^ Optional sections ^^^^^^^^^^^^^^^^^</p> <p>Four optional sections are available for use in a fixture to exercise special aspects of processor behavior.</p> <p>!!!!!!!!!! BIBENTRIES !!!!!!!!!!</p> <p>The <code>citeproc-js</code> processor maintains a persistent internal registry of citation data, and permits the addition, deletion and rearrangement of registered items. The behavior of the processor across a series of update transactions can be tested by including <code>BIBENTRIES</code> section. When included, the section should consist of a two-tier list, consisting of discrete lists of IDs, which must correspond to items registered in the <code>INPUT</code> section:</p> <p>.. class:: clothesline</p> <p>..</p> <pre><code> .. admonition:: Hint The test of output will be run after first updating the processor's internal registry to reflect each of the requested citation sets, and should correctly reflect the last in the series.</code></pre> <p>.. sourcecode:: text</p> <blockquote> <blockquote> <p>===== BIBENTRIES =====>> [ [ "ITEM-1", "ITEM-2", "ITEM-3", "ITEM-4", "ITEM-5" ], [ "ITEM-1", "ITEM-4", "ITEM-5" ] ] <<===== BIBENTRIES =====<<</p> </blockquote> </blockquote> <p>!!!!!!!!!! BIBSECTION !!!!!!!!!!</p> <p>When <code>bibliography</code> mode is used, a <code>BIBSECTION</code> area can be used to limit the output of the bibliography. The filtering logic is described below, but first an example of the way it looks in a test fixture:</p> <p>.. sourcecode:: text</p> <blockquote> <blockquote> <p>===== BIBSECTION =====>> { "include" : [ { "field" : "categories", "value" : "classical" } ], "quash" : [ { "field" : "type", "value" : "manuscript" }, { "field" : "issued", "value" : "" } ] } <<===== BIBSECTION =====<<</p> </blockquote> </blockquote> <p>Filtering parameters for bibliography output are specified in a JSON object that may contain <em>one of</em> the objects <code>select</code>, <code>include</code> or <code>exclude</code>, and optionally an additional <code>quash</code> object. Each of these four objects is an array containing one or more objects with <code>field</code> and <code>value</code> attributes, each with a simple string value (see the examples below). The matching behavior for each of the four object types, with accompanying input examples, is as follows:</p> <p><code>select</code> For each item in the bibliography, try every match object in the array against the item, and include the item if, and only if, <em>all</em> of the objects match.</p> <p>.. admonition:: Hint</p> <p>The target field in the data items registered in the processor may either be a string or an array. In the latter case, an array containing a value identical to the relevant value is treated as a match.</p> <p>.. sourcecode:: js</p> <p>var myarg = { "select" : [ { "field" : "type", "value" : "book" }, { "field" : "categories", "value" : "1990s" } ] }</p> <p>var mybib = cp.makeBibliography(myarg);</p> <p><code>include</code> Try every match object in the array against the item, and include the item if <em>any</em> of the objects match.</p> <p>.. sourcecode:: js</p> <p>var myarg = { "include" : [ { "field" : "type", "value" : "book" } ] }</p> <p>var mybib = cp.makeBibliography(myarg);</p> <p><code>exclude</code> Include the item if <em>none</em> of the objects match.</p> <p>.. sourcecode:: js</p> <p>var myarg = { "exclude" : [ { "field" : "type", "value" : "legal_case" }, { "field" : "type", "value" : "legislation" } ] }</p> <p>var mybib = cp.makeBibliography(myarg);</p> <p><code>quash</code> Regardless of the result from <code>select</code>, <code>include</code> or <code>exclude</code>, skip the item if <em>all</em> of the objects match.</p> <p>.. admonition:: Hint</p> <p>An empty string given as the field value will match items for which that field is missing or has a nil value.</p> <p>.. sourcecode:: js</p> <p>var myarg = { "include" : [ { "field" : "categories", "value" : "classical" } ], "quash" : [ { "field" : "type", "value" : "manuscript" }, { "field" : "issued", "value" : "" } ] }</p> <p>var mybib = cp.makeBibliography(myarg);</p> <p>!!!!!!!!!!!!!! CITATION-ITEMS !!!!!!!!!!!!!!</p> <p>When testing in <code>citation</code> mode, the data items to be processed are ordinarily rendered as a single citation. To test operations that depend upon or may be affected by the internal state of the processor across a session, either a <code>CITATION-ITEMS</code> or a <code>CITATIONS</code> section may be included in the test fixture (only one may be used in a single test fixture).</p> <p><code>CITATION-ITEMS</code> is the simpler of the two, used in most of the standard processor formatting test fixtures. The data input in this area should consist of a list array of cite data, where each cite consists of a Javascript object containing, at least, item ID. A single citation is composed of a list of cites, and the full entry consists of a list of such citations:</p> <p>.. sourcecode:: text</p> <blockquote> <blockquote> <p>===== CITATION-ITEMS =====>> [ [ {"id": "ITEM-1"} ], [ {"id": "ITEM-2", "label": "page", "locator": "23"}, {"id":"ITEM-3"} ] ] <<===== CITATION-ITEMS =====<<</p> </blockquote> </blockquote> <p>!!!!!!!!! CITATIONS !!!!!!!!!</p> <p>A <code>CITATIONS</code> area can be used (instead of <code>CITATION-ITEMS</code>) to mimic a series of interactions with a word processor plugin. In this case, the area should contain a list array of citation data objects with explicit <code>citationID</code> values and ID list values for subsequent invocations of the <code>processCitationCluster()</code> command, like the following:</p> <p>.. sourcecode:: text</p> <blockquote> <blockquote> <p>===== CITATIONS =====>> [ [ { "citationID": "CITATION-1", "citationItems": [ { "id": "ITEM-1" } ], "properties": { "noteIndex": 1 } }, [], [] ], [ { "citationID": "CITATION-2", "citationItems": [ { "id": "ITEM-2", "locator": 15 }, { "id": "ITEM-3" } ], "properties": { "noteIndex": 2 } }, [ [ "CITATION-1", 1 ] ], [] ] ] <<===== CITATIONS =====<<</p> </blockquote> </blockquote></div> </div> <div class="footer"> <ul class="body"> <li>© <script> document.write(new Date().getFullYear()) </script> Githubissues.</li> <li>Githubissues is a development platform for aggregating issues.</li> </ul> </div> <script src="https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.min.js"></script> <script src="/githubissues/assets/js.js"></script> <script src="/githubissues/assets/markdown.js"></script> <script src="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.4.0/build/highlight.min.js"></script> <script src="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.4.0/build/languages/go.min.js"></script> <script> hljs.highlightAll(); </script> </body> </html>