Back to home page

EIC code displayed by LXR

 
 

    


Warning, /firebird/packages/firebird-core/src/loaders.spec.ts is written in an unsupported language. File is not indexed.

0001 import { describe, expect, it } from 'vitest';
0002 import { matchesFileExtensions, type DataLoaderMeta } from './loaders';
0003 
0004 const DEX_META: DataLoaderMeta = {
0005   id: 'test-dex',
0006   label: 'Test DEX',
0007   fileExtensions: ['.firebird.json', '.firebird.zip', '.zip'],
0008   urlSchemes: ['asset://'],
0009 };
0010 
0011 describe('matchesFileExtensions', () => {
0012   it('matches by path extension', () => {
0013     expect(matchesFileExtensions('events.firebird.zip', DEX_META)).toBe(true);
0014     expect(matchesFileExtensions('https://host/d/events.firebird.zip?token=abc', DEX_META)).toBe(true);
0015     expect(matchesFileExtensions('detector.root', DEX_META)).toBe(false);
0016   });
0017 
0018   it('matches by scheme only a name without a file extension', () => {
0019     expect(matchesFileExtensions('asset://data/example', DEX_META)).toBe(true);
0020     expect(matchesFileExtensions('asset://data/example.firebird.zip', DEX_META)).toBe(true);
0021     // A known non-matching extension wins over the scheme
0022     expect(matchesFileExtensions('asset://data/example.whatever', DEX_META)).toBe(false);
0023     expect(matchesFileExtensions('asset://data/events.edm4eic.root', DEX_META)).toBe(false);
0024   });
0025 
0026   it('does not take the host of a URL for a file extension', () => {
0027     const xrootd: DataLoaderMeta = { id: 'xrootd', label: 'XRootD', fileExtensions: ['.root'], urlSchemes: ['root://'] };
0028     expect(matchesFileExtensions('root://dtn-eic.jlab.org', xrootd)).toBe(true);
0029     expect(matchesFileExtensions('root://dtn-eic.jlab.org//work/run', xrootd)).toBe(true);
0030     expect(matchesFileExtensions('root://dtn-eic.jlab.org//work/run.root', xrootd)).toBe(true);
0031     expect(matchesFileExtensions('root://dtn-eic.jlab.org//work/run.firebird.zip', xrootd)).toBe(false);
0032   });
0033 
0034   it('matches a picked file by its name', () => {
0035     expect(matchesFileExtensions(new File([], 'dropped.firebird.zip'), DEX_META)).toBe(true);
0036   });
0037 
0038   it('matches download-style URLs carrying the file name in a query parameter', () => {
0039     expect(matchesFileExtensions(
0040       'http://localhost:5454/api/v1/download?f=events.firebird.zip', DEX_META)).toBe(true);
0041     expect(matchesFileExtensions(
0042       'http://localhost:5454/api/v1/download?filename=dir%2Fevents.firebird.zip', DEX_META)).toBe(true);
0043     expect(matchesFileExtensions(
0044       'http://localhost:5454/api/v1/download?f=file.root', DEX_META)).toBe(false);
0045     // Malformed percent-encoding must not throw
0046     expect(matchesFileExtensions('http://host/x?f=%E0%A4%A', DEX_META)).toBe(false);
0047   });
0048 });