// How Java FILIUS finds a file by path (Dateisystem.holeDatei), as the DNS // server and the e-mail programs use it. import { describe, expect, it } from 'vitest'; import type { FlsFileTree } from '../src/index.js'; import { javaFileContent } from '../src/javaFileSystem.js'; const file = (name: string, content: string | null): FlsFileTree => ({ kind: 'file', name, type: 'text', content, children: [] }); const directory = (name: string, ...children: FlsFileTree[]): FlsFileTree => ({ kind: 'directory', name, children }); describe('javaFileContent', () => { it('finds a path ignoring case, as Java does', () => { expect(javaFileContent(directory('root', directory('DNS', file('Hosts', 'x'))), '/dns/hosts')).toBe('x'); }); it('takes the four units Java also equals with an ASCII letter (measured on the JDK)', () => { expect(javaFileContent(directory('root', directory('dns', file('ho\u017Fts', 'long s'))), '/dns/hosts')).toBe('long s'); expect(javaFileContent(directory('root', file('\u212Aonten.txt', 'kelvin')), '/konten.txt')).toBe('kelvin'); expect(javaFileContent(directory('root', directory('ma\u0130lserver', file('konten.txt', 'dotted'))), '/mailserver/konten.txt')).toBe('dotted'); expect(javaFileContent(directory('root', directory('ma\u0131lserver', file('konten.txt', 'dotless'))), '/mailserver/konten.txt')).toBe('dotless'); expect(javaFileContent(directory('root', file('k\u00F6nten.txt', 'umlaut')), '/konten.txt')).toBeUndefined(); }); it('takes the first match in preorder, and nothing when that is a directory', () => { const twice = directory('root', directory('dns', file('hosts', 'first')), directory('DNS', file('hosts', 'second'))); expect(javaFileContent(twice, '/dns/hosts')).toBe('first'); expect(javaFileContent(directory('root', directory('dns', directory('hosts'), file('HOSTS', 'later'))), '/dns/hosts')).toBeUndefined(); }); it('is undefined without the file, and empty for a file without content', () => { expect(javaFileContent(undefined, '/dns/hosts')).toBeUndefined(); expect(javaFileContent(directory('root', file('hosts', 'x')), '/dns/hosts')).toBeUndefined(); expect(javaFileContent(directory('root', directory('dns', file('hosts', null))), '/dns/hosts')).toBe(''); }); });