nash-parse 0.5.0

Parser for the nash programming language
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
//! Helpers for snapshot tests.

/// Indent every non-empty line of a fragment by four spaces, so multiline
/// layout tests exercise the fragment as it would appear inside a
/// definition. A token at column 1 always starts a new top-level
/// declaration, so bare multiline fragments are not valid input.
pub(crate) fn indent_fragment(fragment: &str) -> String {
    let mut out = String::with_capacity(fragment.len() + 4 * fragment.lines().count());
    for line in fragment.lines() {
        if !line.is_empty() {
            out.push_str("    ");
            out.push_str(line);
        }
        out.push('\n');
    }
    out
}