IF Commons GitHub

shell/block

Written to: 1 requirement: 1 proved, 0 partly, 0 failing, 0 with no test recorded. 0003-host FR-019

The one marked block of a start-up file (commons 0003-host FR-019): ergonex shell install writes a block between the lines # >>> ergonex >>> and # <<< ergonex <<<, leaves one block where it is run twice, and --uninstall removes exactly that block and nothing else, so that a file that had other text is, after both, as it was.

Pure: these are functions from the file's text to its new text; the host layer reads the file, shows the diff, asks and writes. The block is appended at the end of the file with no blank line of its own, so that removing it removes nothing the person wrote; where the file did not end in a newline, one is added before the block and stays after it is removed. A file that uses CRLF gets a block that uses CRLF. A block with a begin and no end is refused rather than guessed at. A file that does not exist is not made (0003-host FR-026): installBlock refuses it as absent, and the command says how the person creates it.

Source: commons/ergonex/src/shell/block.ts

4 of 4 exports are imported by a test of the run. A test that imports an export may not call it or check what it returns.

BEGINconst
const BEGIN: "# >>> ergonex >>>"

The line that begins the block.

Imported by 20 tests of the run (20 passed, 0 failed): the library's results

ENDconst
const END: "# <<< ergonex <<<"

The line that ends the block.

Imported by 20 tests of the run (20 passed, 0 failed): the library's results

installBlockfunction
function installBlock(existing: string | undefined, snippet: string): Result<Edit, BlockError>

The file after the block is installed: appended where there is none, replaced where one is there (so that the snippet is the current one), and one only where several are. existing is the file's text, or undefined where there is no file, which is refused as absent: a start-up file is never created (0003-host FR-026).

Imported by 10 tests of the run (10 passed, 0 failed): the library's results

removeBlockfunction
function removeBlock(existing: string): Result<Edit, BlockError>

The file after every block is removed, with exactly the lines of the blocks and nothing else; unchanged where there is none.

Imported by 10 tests of the run (10 passed, 0 failed): the library's results

Titles, headings, exports, tables, columns and requirements. Esc closes.