Add resolver, server, PDF rendering and web app
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
1 parent
6a7fcdc4b8
commit
bdfdf581f3
59 files changed
+4088
No files matched your search
@@ -0,0 +1,70 @@
|
||||
import { test } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { chooseCallNumber } from './choose.ts';
|
||||
import type { Tiers } from './choose.ts';
|
||||
|
||||
const none: Tiers = { locExact: [], olEdition: [], locTitle: [], olWork: [] };
|
||||
const raws = (...r: string[]) => r.map((raw) => ({ raw }));
|
||||
const m = { authors: ['Klabnik, Steve'], title: 'The Rust Programming Language' };
|
||||
|
||||
test('LoC exact complete', () => {
|
||||
const r = chooseCallNumber({ ...none, locExact: [{ raw: 'QA76.73.R87 K53 2018', complete: true }] }, m);
|
||||
assert.equal(r?.callNumber, 'QA76.73.R87 K53 2018');
|
||||
assert.equal(r?.confidence, 'exact');
|
||||
assert.equal(r?.source, 'loc-isbn');
|
||||
});
|
||||
|
||||
test('exact source is passed through', () => {
|
||||
const r = chooseCallNumber({ ...none, locExact: [{ raw: 'QA76.73.R87 K53 2018', complete: true }] }, m, 'loc-lccn');
|
||||
assert.equal(r?.source, 'loc-lccn');
|
||||
});
|
||||
|
||||
test('OL edition most frequent after normalizing', () => {
|
||||
const r = chooseCallNumber({ ...none, olEdition: raws('QA76.73.C15 K47 1988', 'QA76.73.C15 .K4718 1991', 'QA76.73.C15K47 1988') }, m);
|
||||
assert.equal(r?.callNumber, 'QA76.73.C15 K47 1988');
|
||||
assert.equal(r?.confidence, 'exact');
|
||||
assert.equal(r?.source, 'ol-edition');
|
||||
});
|
||||
|
||||
test('legacy PZ3 dropped when literature class present', () => {
|
||||
const r = chooseCallNumber({ ...none, olEdition: raws('PZ3.H4186 Du', 'PS3558.E63 D8 2005') }, m);
|
||||
assert.equal(r?.callNumber, 'PS3558.E63 D8 2005');
|
||||
});
|
||||
|
||||
test('PZ kept when it is the only class', () => {
|
||||
const r = chooseCallNumber({ ...none, olEdition: raws('PZ3.H4186 Du 1990') }, m);
|
||||
assert.match(r!.callNumber, /^PZ3/);
|
||||
});
|
||||
|
||||
test('LoC title: approximate, year replaced', () => {
|
||||
const r = chooseCallNumber({ ...none, locTitle: [{ raw: 'QA76.73.R87 K53 2018', complete: true }] }, { ...m, year: 2023 });
|
||||
assert.equal(r?.callNumber, 'QA76.73.R87 K53 2023');
|
||||
assert.equal(r?.confidence, 'approximate');
|
||||
assert.equal(r?.source, 'loc-title');
|
||||
});
|
||||
|
||||
test('OL work: padded class gets cutter and year', () => {
|
||||
const r = chooseCallNumber({ ...none, olWork: raws('QA-0076.76000000.A65') }, { ...m, year: 2018 });
|
||||
assert.equal(r?.callNumber, 'QA76.76.A65 K53 2018');
|
||||
assert.equal(r?.confidence, 'approximate');
|
||||
assert.equal(r?.source, 'ol-work');
|
||||
});
|
||||
|
||||
test('incomplete exact candidate with unknown year gets cutter only', () => {
|
||||
const r = chooseCallNumber({ ...none, olEdition: raws('QA76.73.R87') }, m);
|
||||
assert.equal(r?.callNumber, 'QA76.73.R87 K53');
|
||||
});
|
||||
|
||||
test('tie goes to the longest first line', () => {
|
||||
const r = chooseCallNumber({ ...none, olEdition: raws('QA76.A1 2000', 'QA76.73.R87 K53 2018') }, m);
|
||||
assert.equal(r?.callNumber, 'QA76.73.R87 K53 2018');
|
||||
});
|
||||
|
||||
test('earlier tier wins over later tiers', () => {
|
||||
const r = chooseCallNumber({ ...none, olEdition: raws('QA76.73.R87 K53 2018'), olWork: raws('PS3558.E63 D8 2005') }, m);
|
||||
assert.equal(r?.source, 'ol-edition');
|
||||
});
|
||||
|
||||
test('unparseable only -> null', () => {
|
||||
assert.equal(chooseCallNumber({ ...none, olEdition: raws('[E]', 'Fic') }, m), null);
|
||||
});
|
||||
Reference in new issue
Block a user