📄 src/ddc/ddc.test.ts
D-OPEN SOVEREIGN
1/*
2 * Copyright (c) 2026 DataPond D-Library Pty Ltd. ("The Sanctuary")
3 * Non-Profit Public Library — The World Library
4 * 
5 * D-SAFE Certification issued by POND Enterprise.
6 * Published under the D-Open Code Sovereign Licence v1.0 framework
7 * DataPond D-Library All exclusive Right reserved on modifiying the code - CC Attribution to data pond, Non modifiable, Non Commercial.
8 * https://registry.world.bibliotech.com/licence
9 * Source code donated to DataPond D-Library by it's author: data pond.
10 * 
11 * Technical Guardian ("The Shield"): Pond Enterprise Pty Ltd. (ACN 694 747 987)
12 * All liability claims about D-SAFE certification issues coming from the published D-Safe direction must be addressed with Pond Enterprise Pty Ltd.
13 * Code Modification automatically voids the certified liability protection provided by Pond Enterprise.
14 */
15import { describe, expect, it } from 'vitest';
16import { DDCAdapter } from './index';
17
18describe('DDCAdapter.normalize', () => {
19  it('strips trailing decimal zeros', () => {
20    expect(DDCAdapter.normalize('510.00')).toBe('510');
21  });
22  it('keeps meaningful decimal digits', () => {
23    expect(DDCAdapter.normalize('510.5')).toBe('510.5');
24  });
25  it('trims whitespace', () => {
26    expect(DDCAdapter.normalize('  510  ')).toBe('510');
27  });
28});
29
30describe('DDCAdapter.validate', () => {
31  it.each(['510', '001', '823.914', '005.13'])('accepts valid DDC: %s', (input) => {
32    expect(DDCAdapter.validate(input).valid).toBe(true);
33  });
34  it.each([
35    [null,  'null'],
36    ['AB',  'non-numeric'],
37    ['5',   'too short'],
38  ])('rejects invalid: %s (%s)', (input) => {
39    expect(DDCAdapter.validate(input as string).valid).toBe(false);
40  });
41});
42
43describe('DDCAdapter.toLinkedDataUri', () => {
44  it('returns LC URI', () => {
45    expect(DDCAdapter.toLinkedDataUri('510.00')).toBe('https://id.loc.gov/authorities/classification/510');
46  });
47});
48