inspect-rs 0.1.0

Universal introspection for Rust
Documentation
use inspect_core::{Inspect, InspectCx, InspectLimits};

#[test]
fn test_max_items_limit() {
    let value: Vec<i32> = (0..100).collect();

    let mut cx = InspectCx::with_limits(InspectLimits { max_items: 5, ..Default::default() });

    let inspected = value.inspect(&mut cx);

    // Should only include first 5 items
    assert_eq!(inspected.children().unwrap().len(), 5);
}

#[test]
fn test_string_length_limit() {
    let long_string = "a".repeat(2000);

    let mut cx =
        InspectCx::with_limits(InspectLimits { max_string_length: 100, ..Default::default() });

    let inspected = long_string.as_str().inspect(&mut cx);

    if let inspect_core::Kind::Str(s) = inspected.kind() {
        assert_eq!(s.len(), 100);
    } else {
        panic!("Expected Str kind");
    }
}

#[test]
fn test_bytes_limit() {
    let bytes: Vec<u8> = (0..200).map(|i| i as u8).collect();
    let slice = bytes.as_slice();

    let mut cx = InspectCx::with_limits(InspectLimits { max_bytes: 50, ..Default::default() });

    let inspected = slice.inspect(&mut cx);

    if let inspect_core::Kind::Bytes(b) = inspected.kind() {
        assert_eq!(b.len(), 50);
    } else {
        panic!("Expected Bytes kind");
    }
}

#[test]
fn test_depth_tracking() {
    let cx = InspectCx::new();

    assert_eq!(cx.depth(), 0);
}