29 lines
1.4 KiB
TypeScript
29 lines
1.4 KiB
TypeScript
import { test } from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { normalizeTitle, recordMatches, titlesMatch } from './match.ts';
|
|
import type { MarcFields } from '../sources/marc.ts';
|
|
|
|
const rec = (title: string, names: string[]): MarcFields => ({ lccn: null, lcc: [], dewey: null, meta: { title, authors: [], subjects: [] }, names });
|
|
|
|
test('normalizeTitle', () => {
|
|
assert.equal(normalizeTitle('The Mythical Man-Month: Essays on Software'), 'mythical man month');
|
|
assert.equal(normalizeTitle('An Introduction!'), 'introduction');
|
|
});
|
|
|
|
test('titlesMatch: equal or prefix, nothing looser', () => {
|
|
assert.ok(titlesMatch('The mythical man-month :', 'Mythical Man-Month'));
|
|
assert.ok(titlesMatch('Dune', 'Dune Messiah'));
|
|
assert.ok(!titlesMatch('Dunes', 'Dune'));
|
|
assert.ok(!titlesMatch('', 'Dune'));
|
|
assert.ok(titlesMatch('Rust', 'The Rust Programming Language'));
|
|
});
|
|
|
|
test('recordMatches needs title and an author surname', () => {
|
|
const r = rec('The mythical man-month', ['Brooks, Frederick P.']);
|
|
assert.ok(recordMatches(r, 'The Mythical Man-Month: Essays', 'Frederick P. Brooks'));
|
|
assert.ok(recordMatches(r, 'Mythical Man-Month', 'Brooks, Frederick P.'));
|
|
assert.ok(!recordMatches(r, 'Mythical Man-Month', 'Tolkien'));
|
|
assert.ok(!recordMatches(r, 'Something Else', 'Brooks'));
|
|
assert.ok(recordMatches(rec('Dune', ['Smith, Bob', 'Herbert, Frank']), 'Dune', 'Frank Herbert'));
|
|
});
|