silcrow 0.2.1

Deterministic CLI for a citable, checkable graph of laws in a git tree.
use super::*;

#[test]
fn arg_change_moves() {
    let a = "f() {\n  save \"$1\" a\n}\n";
    let b = "f() {\n  save \"$1\" b\n}\n";
    assert_ne!(pair(&BASH, a, 1).shape, pair(&BASH, b, 1).shape);
}

#[test]
fn callee_rename_moves() {
    let a = "f() {\n  save \"$1\"\n}\n";
    let b = "f() {\n  log \"$1\"\n}\n";
    assert_ne!(pair(&BASH, a, 1).shape, pair(&BASH, b, 1).shape);
}

#[test]
fn variable_rename_moves() {
    let a = "f() {\n  local x=1\n  save \"$x\"\n}\n";
    let b = "f() {\n  local y=1\n  save \"$y\"\n}\n";
    assert_ne!(pair(&BASH, a, 1).shape, pair(&BASH, b, 1).shape);
}

#[test]
fn call_order_moves() {
    let a = "f() {\n  debit\n  credit\n}\n";
    let b = "f() {\n  credit\n  debit\n}\n";
    assert_ne!(pair(&BASH, a, 1).shape, pair(&BASH, b, 1).shape);
}

#[test]
fn quoting_is_not_formatting() {
    let a = "f() {\n  rm \"$1\"\n}\n";
    let b = "f() {\n  rm $1\n}\n";
    assert_ne!(pair(&BASH, a, 1).shape, pair(&BASH, b, 1).shape);
}

#[test]
fn parse_error_has_no_digest() {
    assert!(mint_span_digests(&BASH, "f() {\n  if then\n}\n", 1, &[]).is_none());
}

#[test]
fn whitespace_in_a_string_or_heredoc_moves() {
    moves(
        &BASH,
        "f() {\n  echo \"a  b\"\n}\n",
        "f() {\n  echo \"a b\"\n}\n",
        1,
    );
    moves(
        &BASH,
        "f() {\n  cat <<EOF\n  hi  $x\nEOF\n}\n",
        "f() {\n  cat <<EOF\nhi  $x\nEOF\n}\n",
        1,
    );
}

#[test]
fn a_line_continuation_stays() {
    stays(
        &BASH,
        "f() {\n  curl -X POST u\n}\n",
        "f() {\n  curl -X POST \\\n    u\n}\n",
        1,
    );
}

#[test]
fn an_arithmetic_base_before_a_plain_expansion_parses() {
    let src =
        "f() {\n  # pin\n  y=$((10#$x + 1))\n  echo $((16#$hex)) 10#$w\n  (( n = 2#$1 ))\n}\n";
    assert!(!parse(&BASH, src).unwrap().root_node().has_error());
    for (from, to) in [
        ("10#$x", "8#$x"),
        ("10#$x", "10#$z"),
        ("10#$x", "10+$x"),
        ("16#$hex", "16#${hex}"),
        ("10#$w", "10#$v"),
        ("2#$1", "2#$2"),
    ] {
        moves(&BASH, src, &src.replace(from, to), 2);
    }
    stays(
        &BASH,
        src,
        &src.replace("$((10#$x + 1))", "$(( 10#$x  +  1 ))"),
        2,
    );
    every_byte_reaches_the_walk(&BASH, src, 2);
}