Warning, /firebird/packages/root2dex/src/errors.spec.ts is written in an unsupported language. File is not indexed.
0001 /**
0002 * What the converter says when the input is not what it wants. These messages
0003 * reach the user directly in the "Open event" panel, so they are part of the
0004 * contract.
0005 */
0006
0007 import { describe, expect, it } from 'vitest';
0008 import { existsSync } from 'node:fs';
0009 import { resolve } from 'node:path';
0010 import { Root2DexConverter, parseEntryNumbers } from './convert';
0011 import { PodioEventFile } from './podio-file';
0012
0013 const REPO = resolve(__dirname, '../../..');
0014 const GEOMETRY_FILE = resolve(REPO, 'firebird-ng/src/assets/data/epic_craterlake.root');
0015 const EIC_FILE = resolve(
0016 REPO,
0017 'pyrobird/tests/unit_tests/data/reco_2024-09_craterlake_2evt.edm4eic.root',
0018 );
0019
0020 describe('parseEntryNumbers', () => {
0021 it('parses single numbers, ranges and lists', () => {
0022 expect(parseEntryNumbers('3')).toEqual([3]);
0023 expect(parseEntryNumbers('1-5')).toEqual([1, 2, 3, 4, 5]);
0024 expect(parseEntryNumbers('1,2-5,8')).toEqual([1, 2, 3, 4, 5, 8]);
0025 expect(parseEntryNumbers(7)).toEqual([7]);
0026 expect(parseEntryNumbers([2, 4])).toEqual([2, 4]);
0027 });
0028
0029 it('rejects nonsense and backwards ranges', () => {
0030 expect(() => parseEntryNumbers('5-1')).toThrow(/start must be <= end/);
0031 expect(() => parseEntryNumbers('abc')).toThrow(/Invalid entry format/);
0032 expect(() => parseEntryNumbers('')).toThrow(/Invalid entry format/);
0033 });
0034 });
0035
0036 describe('rejecting the wrong file', () => {
0037 it.runIf(existsSync(GEOMETRY_FILE))('says a geometry file has no events tree', async () => {
0038 await expect(Root2DexConverter.open(GEOMETRY_FILE)).rejects.toThrow(/No 'events' TTree/);
0039 });
0040
0041 it.runIf(existsSync(EIC_FILE))('names both models when detection fails', async () => {
0042 const file = await PodioEventFile.open(EIC_FILE);
0043 // Force the failing path by looking for a model this file cannot have
0044 const empty = Object.create(Object.getPrototypeOf(file)) as PodioEventFile;
0045 Object.assign(empty, file, { collectionTypes: new Map() });
0046 expect(() => empty.detectModel()).toThrow(/Cannot detect file type/);
0047 });
0048 });