import { test } from 'node:test'; import assert from 'node:assert/strict'; import { cleanCaption, parseBounds, parseOutlineText } from './lcc-parse.ts'; test('number ranges in every form the outline uses', () => { assert.deepEqual(parseBounds('191.2-200.66'), { lo: 191.2, hi: 200.66 }); assert.deepEqual(parseBounds('1201.5'), { lo: 1201.5, hi: 1201.5 }); assert.deepEqual(parseBounds('1115-(1193)'), { lo: 1115, hi: 1193 }); assert.deepEqual(parseBounds('(1)-1281'), { lo: 1, hi: 1281 }); assert.deepEqual(parseBounds('1569.C2'), { lo: 1569, hi: 1569, cutterLo: 'C2', cutterHi: 'C2' }); assert.deepEqual(parseBounds('469.M21-.M38'), { lo: 469, hi: 469, cutterLo: 'M21', cutterHi: 'M38' }); assert.deepEqual(parseBounds('990.U45-U46', 'DA'), { lo: 990, hi: 990, cutterLo: 'U45', cutterHi: 'U46' }); assert.deepEqual(parseBounds('1.A5-3.3'), { lo: 1, hi: 3.3, cutterLo: 'A5' }); assert.deepEqual(parseBounds('12.5-.9'), { lo: 12.5, hi: 12.9 }); assert.deepEqual(parseBounds('1003-Z1005.5', 'Z'), { lo: 1003, hi: 1005.5 }); assert.equal(parseBounds('4440-4406'), null); assert.equal(parseBounds('274.5-6'), null); }); test('captions: wraps joined, notes dropped, headers and breaks ignored, nesting kept in order', () => { const text = [ ' LIBRARY OF CONGRESS CLASSIFICATION OUTLINE', 'Subclass GV Recreation. Leisure', 'Subclass GV', '', 'GV1-1860 Recreation. Leisure', 'GV191.2-200.66 Outdoor life. Outdoor recreation', 'GV199-199.62 Hiking. Pedestrian tours', 'GV346-351.5 School and college athletics. Intramural', ' and interscholastic athletics', 'GV401-433 Physical education facilities.', ' Including gymnasiums, athletic fields,', ' playgrounds, etc.', '\fGV1470-1511 Parties. Party games and stunts', 'GV1201.5 Hobbies (General)', 'Subclass GX', 'GX5 Heading', ' Individual states', ].join('\n'); const { ranges, problems } = parseOutlineText(text); assert.deepEqual(problems, []); assert.deepEqual(ranges.get('GV'), [ [1, 1860, 'Recreation. Leisure'], [191.2, 200.66, 'Outdoor life. Outdoor recreation'], [199, 199.62, 'Hiking. Pedestrian tours'], [346, 351.5, 'School and college athletics. Intramural and interscholastic athletics'], [401, 433, 'Physical education facilities'], [1470, 1511, 'Parties. Party games and stunts'], [1201.5, 1201.5, 'Hobbies (General)'], ]); assert.deepEqual(ranges.get('GX'), [[5, 5, 'Heading']]); }); test('unreadable ranges are reported, not guessed', () => { const { ranges, problems } = parseOutlineText('Subclass KZ\nKZD4440-4406 Liability for accidents\nKZ5 Fine\n'); assert.equal(problems.length, 1); assert.deepEqual(ranges.get('KZ'), [[5, 5, 'Fine']]); }); test('caption clean-up trims debris only', () => { assert.equal(cleanCaption(' Law and\n order , '), 'Law and order'); assert.equal(cleanCaption('Museology. Museum methods, technique, etc.'), 'Museology. Museum methods, technique, etc.'); assert.equal(cleanCaption('Purānas .'), 'Purānas'); assert.equal(cleanCaption('1789­'), '1789-'); assert.equal(cleanCaption('1871- . Later 19th century'), '1871- . Later 19th century'); assert.equal(cleanCaption('Persian wars, 499-479 B.C.'), 'Persian wars, 499-479 B.C.'); });