simple-update-in 0.2.0

Immutable nested update with structural sharing
Documentation
//! Empty-path behavior and the API shape that has no JavaScript analogue.
//!
//! An empty path resolves to no concrete leaf, so the updater never runs and the
//! root comes back unchanged. The "path must be an array" check from the source
//! has no analogue here, since the signature already requires a slice.

mod common;

use common::*;

#[test]
fn empty_path_with_updater_returns_root_unchanged() {
    // The updater would append, but an empty path runs it zero times.
    let from = arr(vec![n(0.0), n(1.0)]);
    let actual = run(from.clone(), &[], |v| match v {
        simple_update_in::Value::Array(items) => {
            let mut next = (*items).clone();
            next.push(n(2.0));
            arr(next)
        }
        other => other,
    });
    assert!(from.ptr_eq(&actual));
    assert_eq!(actual, arr(vec![n(0.0), n(1.0)]));
}

#[test]
fn empty_path_without_updater_returns_root_unchanged() {
    let from = obj(vec![("a", n(1.0))]);
    let actual = remove(from.clone(), &[]);
    assert!(from.ptr_eq(&actual));
    assert_eq!(actual, obj(vec![("a", n(1.0))]));
}