From 770ff7cbd9c44a905a277f574f319ac955bc0a33 Mon Sep 17 00:00:00 2001 From: Kyle Kelley Date: Wed, 11 Feb 2026 08:23:12 -0800 Subject: [PATCH] repl: Write test for JSON output (#48897) Tests for JSON output in the REPL. Release Notes: - N/A --- crates/repl/src/outputs/json.rs | 41 +++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/crates/repl/src/outputs/json.rs b/crates/repl/src/outputs/json.rs index c4add05e56eaec814f543a45a38cffeab2577b10..ee764764d83a9131458981a7f8c238750d2ee4d8 100644 --- a/crates/repl/src/outputs/json.rs +++ b/crates/repl/src/outputs/json.rs @@ -253,3 +253,44 @@ impl OutputContent for JsonView { Some(buffer) } } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_json_view_from_value_root_expanded() { + let view = JsonView::from_value(serde_json::json!({"key": "value"})).unwrap(); + assert!( + view.is_expanded("root"), + "root should be expanded by default" + ); + } + + #[test] + fn test_json_view_is_expanded_unknown_path() { + let view = JsonView::from_value(serde_json::json!({"key": "value"})).unwrap(); + assert!( + !view.is_expanded("root.key"), + "non-root paths should not be expanded by default" + ); + assert!( + !view.is_expanded("nonexistent"), + "unknown paths should not be expanded" + ); + } + + #[gpui::test] + fn test_json_view_toggle_path(cx: &mut gpui::App) { + let view = + cx.new(|_cx| JsonView::from_value(serde_json::json!({"nested": {"a": 1}})).unwrap()); + + view.update(cx, |view, cx| { + assert!(!view.is_expanded("root.nested")); + view.toggle_path("root.nested", cx); + assert!(view.is_expanded("root.nested")); + view.toggle_path("root.nested", cx); + assert!(!view.is_expanded("root.nested")); + }); + } +}