Luigit
repositories / dotfiles

dotfiles

bugabingas dorkfiles

owned by admin

nugu/mdbook.test.nu

Raw
use mdbook.nu

def generate [destination: string] {
    ^just --shell nu --clear-shell-args --shell-arg=--no-config-file --shell-arg=--commands mdbook $destination | complete
}

def main [] {
    let scratch = (mktemp -d | str trim)
    try {
        let expected = (mdbook css)
        if not (($expected | str contains 'html.light, html.rust') and ($expected | str contains 'html.navy, html.coal, html.ayu')) {
            error make {msg: 'mdBook CSS must support light and dark theme selectors'}
        }
        for filename in ['theme.css' 'theme with spaces.css' "theme's.css"] {
            let destination = ($scratch | path join $filename)
            let result = (generate $destination)
            if $result.exit_code != 0 {
                error make {msg: $"mdBook generation failed: ($result.stderr)"}
            }
            if (open --raw $destination) != $expected {
                error make {msg: $"mdBook output differs from generator: ($filename)"}
            }
        }
        if (generate $scratch).exit_code == 0 {
            error make {msg: 'mdBook generation must reject a directory destination'}
        }
    } catch { |err|
        rm -rf $scratch
        error make {msg: $err.msg}
    }
    rm -rf $scratch
    print 'mdBook CLI: plain, spaced, quoted, and invalid destinations verified'
}