Skip to content

Commit

Permalink
Add tests for Citation.fromId, 'type'/'type_name' fields, historical …
Browse files Browse the repository at this point in the history
…anomalous Pub.L. numbers
  • Loading branch information
JoshData committed Apr 4, 2020
1 parent c9c8b2c commit f020af9
Show file tree
Hide file tree
Showing 12 changed files with 88 additions and 34 deletions.
2 changes: 2 additions & 0 deletions test/cfr.js
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,8 @@ singles.forEach(function(single) {
if (found.length == 1) {
var citation = found[0];
test.equal(citation.match, expected.match);
test.equal(citation.type, 'cfr');
test.equal(citation.type_name, 'U.S. Code of Federal Regulations');
test.deepEqual(citation.cfr, expected.cfr);
} else
console.log(found);
Expand Down
2 changes: 2 additions & 0 deletions test/dc_code.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ exports["Relative patterns"] = function(test) {

if (found.length == 1) {
var citation = found[0];
test.equal(citation.type, 'dc_code');
test.equal(citation.type_name, 'Code of the District of Columbia');
test.equal(citation.match, details[2], details[0]);
test.equal(citation.dc_code.title, details[3]);
test.equal(citation.dc_code.section, details[4]);
Expand Down
2 changes: 2 additions & 0 deletions test/dc_law.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ exports["All patterns"] = function(test) {

if (found.length == 1) {
var citation = found[0];
test.equal(citation.type, 'dc_law');
test.equal(citation.type_name, 'District of Columbia Law');
test.equal(citation.match, details[0]);
test.equal(citation.dc_law.id, details[1]);
test.equal(citation.dc_law.period, details[2]);
Expand Down
2 changes: 2 additions & 0 deletions test/dc_register.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ exports["All patterns"] = function(test) {

if (found.length == 1) {
var citation = found[0];
test.equal(citation.type, 'dc_register');
test.equal(citation.type_name, 'District of Columbia Register');
test.equal(citation.match, details[2], details[0]);
test.equal(citation.dc_register.volume, details[3]);
test.equal(citation.dc_register.page, details[4]);
Expand Down
2 changes: 2 additions & 0 deletions test/dc_stat.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ exports["All patterns"] = function(test) {

if (found.length == 1) {
var citation = found[0];
test.equal(citation.type, 'dc_stat');
test.equal(citation.type_name, 'D.C. Statutes at Large');
test.equal(citation.match, details[2]);
test.equal(citation.dc_stat.id, details[5]);
test.equal(citation.dc_stat.volume, details[3]);
Expand Down
2 changes: 2 additions & 0 deletions test/fedreg.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ exports["All patterns"] = function(test) {

if (found.length == 1) {
var citation = found[0];
test.equal(citation.type, 'fedreg');
test.equal(citation.type_name, 'Federal Register');
test.equal(citation.match, details[2]);
test.equal(citation.fedreg.volume, details[3]);
test.equal(citation.fedreg.page, details[4]);
Expand Down
70 changes: 48 additions & 22 deletions test/law.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,24 +51,43 @@ exports["Basic patterns"] = function(test) {
"Nuclear Energy Authorization Act of 1980 (Priv L No 96-164; ", "Pvt. L. 96-164"],
["Private Law 96–164", "us-law/private/96/164", "private", "96", "164",
"Nuclear Energy Authorization Act of 1980 (Private Law 96–164; ", "Pvt. L. 96-164"],

// historical anomalies (https://github.com/unitedstates/legisworks-historical-statutes)
["Pub. L. 61-167½", "us-law/public/61/167½", "public", "61", "167½" ],
["Pub. L. 65-246½", "us-law/public/65/246½", "public", "65", "246½" ],
["Pub. L. 67-45-46", "us-law/public/67/45-46", "public", "67", "45-46" ],
["Pub. L. 69-439½", "us-law/public/69/439½", "public", "69", "439½" ],
["Pub. L. 74-297½", "us-law/public/74/297½", "public", "74", "297½" ],
["Pub. L. 74-770½", "us-law/public/74/770½", "public", "74", "770½" ],
["Pub. L. 79-160-A", "us-law/public/79/160-A", "public", "79", "160-A" ]
];

for (var i=0; i<cases.length; i++) {
var details = cases[i];

var text = details[5];
// Search the text string for a citation. The details[5] holds the string
// to search, or if not given, then details[0].
var text = details[5] || details[0];
var found = Citation.find(text, {types: "law"}).citations;
test.equal(found.length, 1, "No match found in: " + text);

if (found.length == 1) {
var citation = found[0];
test.equal(citation.match, details[0]);
test.equal(citation.citation, details[6]);
test.equal(citation.law.id, details[1]);
test.equal(citation.law.type, details[2]);
test.equal(citation.law.congress, details[3]);
test.equal(citation.law.number, details[4]);
}
if (found.length != 1) continue;

// Check the fields of the found citation.
var citation = found[0];
test.equal(citation.type, 'law');
test.equal(citation.type_name, 'U.S. Law');
test.equal(citation.match, details[0]);
test.equal(citation.citation, details[6] || details[0]); // compare to canonical form in details[6] if given
test.equal(citation.law.id, details[1]);
test.equal(citation.law.type, details[2]);
test.equal(citation.law.congress, details[3]);
test.equal(citation.law.number, details[4]);

// Check that fromId round-trips properly. It will be missing the 'match' and 'index'
// properties so delete those.
delete citation.match;
delete citation.index;
test.deepEqual(Citation.fromId(citation.law.id), citation);
}

test.done();
Expand All @@ -92,20 +111,27 @@ exports["Subsections"] = function(test) {
for (var i=0; i<cases.length; i++) {
var details = cases[i];

// Search the text string for a citation.
var text = details[6];
var found = Citation.find(text, {types: "law"}).citations;
test.equal(found.length, 1, "No match found in: " + text);

if (found.length == 1) {
var citation = found[0];
test.equal(citation.match, details[0]);
test.equal(citation.citation, details[7]);
test.equal(citation.law.id, details[1]);
test.equal(citation.law.type, details[2]);
test.equal(citation.law.congress, details[3]);
test.equal(citation.law.number, details[4]);
test.deepEqual(citation.law.sections, details[5]);
}
if (found.length != 1) continue;

// Check the fields of the found citation.
var citation = found[0];
test.equal(citation.match, details[0]);
test.equal(citation.citation, details[7]);
test.equal(citation.law.id, details[1]);
test.equal(citation.law.type, details[2]);
test.equal(citation.law.congress, details[3]);
test.equal(citation.law.number, details[4]);
test.deepEqual(citation.law.sections, details[5]);

// Check that fromId round-trips properly. It will be missing the 'match' and 'index'
// properties so delete those.
delete citation.match;
delete citation.index;
test.deepEqual(Citation.fromId(citation.law.id), citation);
}

test.done();
Expand Down
2 changes: 2 additions & 0 deletions test/reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ exports["Absolute patterns"] = function(test) {

if (found.length == 1) {
var citation = found[0];
test.equal(citation.type, 'reporter');
test.equal(citation.type_name, 'Case Law');
test.equal(citation.match, details[2], details[0]);
test.equal(citation.reporter.volume, details[3]);
test.equal(citation.reporter.reporter, details[4]);
Expand Down
32 changes: 20 additions & 12 deletions test/stat.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,30 @@ exports["All patterns"] = function(test) {
for (var i=0; i<cases.length; i++) {
var details = cases[i];

// Search the text string for a citation.
var text = details[0];
var found = Citation.find(text, {types: "stat", links: true}).citations;
test.equal(found.length, 1);
if (found.length != 1) continue;

if (found.length == 1) {
var citation = found[0];
test.equal(citation.match, details[2]);
test.equal(citation.citation, details[6]);
test.equal(citation.stat.id, details[5]);
test.equal(citation.stat.volume, details[3]);
test.equal(citation.stat.page, details[4]);
if (details[7]) // is a link available?
test.equal(citation.stat.links.usgpo.source.link, "https://govinfo.gov");
}
else
console.log("No match found in: " + text);;
// Check the fields of the found citation.
var citation = found[0];
test.equal(citation.type, 'stat');
test.equal(citation.type_name, 'U.S. Statutes at Large');
test.equal(citation.match, details[2]);
test.equal(citation.citation, details[6]);
test.equal(citation.stat.id, details[5]);
test.equal(citation.stat.volume, details[3]);
test.equal(citation.stat.page, details[4]);
if (details[7]) // is a link available?
test.equal(citation.stat.links.usgpo.source.link, "https://govinfo.gov");


// Check that fromId round-trips properly. It will be missing the 'match' and 'index'
// properties so delete those.
delete citation.match;
delete citation.index;
test.deepEqual(Citation.fromId(citation.stat.id, { links: true }), citation);
};

test.done();
Expand Down
2 changes: 2 additions & 0 deletions test/usc.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ exports["Basic pattern"] = function(test) {
test.equal(found.length, 1);

var citation = found[0];
test.equal(citation.type, 'usc');
test.equal(citation.type_name, 'United States Code');
test.equal(citation.match, "5 U.S.C. 552");
test.equal(citation.index, 37);
test.equal(citation.citation, "5 U.S.C. 552");
Expand Down
2 changes: 2 additions & 0 deletions test/usconst.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ exports["All patterns"] = function(test) {

if (found.length == 1) {
var citation = found[0];
test.equal(citation.type, 'usconst');
test.equal(citation.type_name, 'United States Constitution');
test.equal(citation.usconst.id, details[1]);
}
else
Expand Down
2 changes: 2 additions & 0 deletions test/va_code.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ exports["All patterns"] = function(test) {

if (found.length == 1) {
var citation = found[0];
test.equal(citation.type, 'va_code');
test.equal(citation.type_name, 'Code of Virginia');
test.equal(citation.match, details[1], details[0]);
test.equal(citation.va_code.title, details[2]);
test.equal(citation.va_code.section, details[3]);
Expand Down

0 comments on commit f020af9

Please sign in to comment.