import { describe, expect, it } from 'bun:test'; import { classifyStatementRole, parseLabelLinkbase, parsePresentationLinkbase } from '@/lib/server/taxonomy/linkbase-parser'; const SAMPLE_LABEL_LINKBASE = ` Rev. Revenues `; const SAMPLE_PRESENTATION_LINKBASE = ` `; describe('linkbase parser', () => { it('builds preferred labels from label linkbase', () => { const labels = parseLabelLinkbase(SAMPLE_LABEL_LINKBASE); expect(labels.get('http://fasb.org/us-gaap/2024#Revenues')).toBe('Revenues'); }); it('builds role trees with depth/order/parent metadata', () => { const rows = parsePresentationLinkbase(SAMPLE_PRESENTATION_LINKBASE); expect(rows.length).toBe(3); const root = rows.find((row) => row.qname === 'us-gaap:StatementLineItems'); const revenue = rows.find((row) => row.qname === 'us-gaap:Revenues'); const cogs = rows.find((row) => row.qname === 'us-gaap:CostOfGoodsSold'); expect(root?.depth).toBe(0); expect(root?.parentConceptKey).toBeNull(); expect(revenue?.depth).toBe(1); expect(cogs?.depth).toBe(1); expect(revenue?.parentConceptKey).toBe(root?.conceptKey ?? null); expect(revenue?.order).toBeLessThan(cogs?.order ?? Number.POSITIVE_INFINITY); }); it('classifies statement roles into canonical statement kinds', () => { expect(classifyStatementRole('http://www.xbrl.org/2003/role/StatementOfOperations')).toBe('income'); expect(classifyStatementRole('http://www.xbrl.org/2003/role/StatementOfFinancialPosition')).toBe('balance'); expect(classifyStatementRole('http://www.xbrl.org/2003/role/StatementOfCashFlows')).toBe('cash_flow'); }); });