diff options
Diffstat (limited to 'plugins/code-modernization/tests/fixtures')
| -rw-r--r-- | plugins/code-modernization/tests/fixtures/stacks.ts | 22 | ||||
| -rw-r--r-- | plugins/code-modernization/tests/fixtures/world.ts | 34 |
2 files changed, 43 insertions, 13 deletions
diff --git a/plugins/code-modernization/tests/fixtures/stacks.ts b/plugins/code-modernization/tests/fixtures/stacks.ts index 15f60e21..9de66e02 100644 --- a/plugins/code-modernization/tests/fixtures/stacks.ts +++ b/plugins/code-modernization/tests/fixtures/stacks.ts @@ -8,7 +8,12 @@ import type { ReaderFs } from '../../hooks/reader/fs' */ /** A file tree in memory, read the way the reader reads `$.fs`. */ -export function memoryFs(files: Readonly<Record<string, string>>, mtimes: Readonly<Record<string, number>> = {}): ReaderFs { +export function memoryFs( + files: Readonly<Record<string, string>>, + mtimes: Readonly<Record<string, number>> = {}, + /** Paths that are symbolic links to a directory: listed as `other`, as the engine lists a link; `stat` says `dir`. */ + links: readonly string[] = [], +): ReaderFs { const dirs = new Set<string>(['']) for (const path of Object.keys(files)) { @@ -61,11 +66,16 @@ export function memoryFs(files: Readonly<Record<string, string>>, mtimes: Readon names.set(name, rest.includes('/') ? 'dir' : 'file') } - return [...names.entries()].sort().map(([name, kind]) => ({ - name, - kind, - size: kind === 'file' ? (files[dir === '' ? name : `${dir}/${name}`]?.length ?? 0) : 0, - })) + return [...names.entries()].sort().map(([name, kind]) => { + const isLink = links.includes(dir === '' ? name : `${dir}/${name}`) + + return { + name, + kind: isLink ? ('other' as const) : kind, + size: kind === 'file' ? (files[dir === '' ? name : `${dir}/${name}`]?.length ?? 0) : 0, + isLink, + } + }) }, } } diff --git a/plugins/code-modernization/tests/fixtures/world.ts b/plugins/code-modernization/tests/fixtures/world.ts index 076c7879..43b8d154 100644 --- a/plugins/code-modernization/tests/fixtures/world.ts +++ b/plugins/code-modernization/tests/fixtures/world.ts @@ -15,6 +15,8 @@ export type World = { statuses: (string | undefined)[] blits: number invalidations: number + /** How many of the next opens the engine holds back undrawn (unasked, on a terminal too narrow to dock a pane). */ + unplaced: number fills: string[] commands: string[] aborted: string[] @@ -29,7 +31,13 @@ export const CWD = '/work' const relOf = (path: string) => (path.startsWith(`${CWD}/`) ? path.slice(CWD.length + 1) : path.replace(/^\.\//, '')) /** Seats the in-memory world beneath the plugin. */ -export function worldOf(on: On, files: Readonly<Record<string, string>>, env: Readonly<Record<string, string>> = {}): World { +export function worldOf( + on: On, + files: Readonly<Record<string, string>>, + env: Readonly<Record<string, string>> = {}, + /** Paths (relative to the working directory) that are symbolic links to a directory: the engine lists a link as `other`. */ + links: readonly string[] = [], +): World { let tick = 1_000 const world: World = { @@ -43,6 +51,7 @@ export function worldOf(on: On, files: Readonly<Record<string, string>>, env: Re statuses: [], blits: 0, invalidations: 0, + unplaced: 0, fills: [], commands: [], aborted: [], @@ -99,11 +108,16 @@ export function worldOf(on: On, files: Readonly<Record<string, string>>, env: Re } return { - value: [...names.entries()].sort().map(([name, kind]) => ({ - name, - kind, - size: kind === 'file' ? (world.files.get(`${dir}/${name}`)?.length ?? 0) : 0, - })), + value: [...names.entries()].sort().map(([name, kind]) => { + const isLink = links.includes(dir === '' ? name : `${dir}/${name}`) + + return { + name, + kind: isLink ? ('other' as const) : kind, + size: kind === 'file' ? (world.files.get(`${dir}/${name}`)?.length ?? 0) : 0, + isLink, + } + }), } }) @@ -127,7 +141,13 @@ export function worldOf(on: On, files: Readonly<Record<string, string>>, env: Re on('ui.open', ($, e) => { world.opened.push({ id: e.id, focus: e.focus === true }) - return { value: undefined } + if (world.unplaced > 0) { + world.unplaced -= 1 + + return { value: { isPlaced: false, reason: 'unasked below 144 columns (120 now): press the pane\'s button or type /modernize-panel' } } as never + } + + return { value: { isPlaced: true } } as never }) on('ui.close', ($, e) => { |
