Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

repl: Write test for JSON output (#48897)

Kyle Kelley770ff7cbd9c4
diff --git a/crates/repl/src/outputs/json.rs b/crates/repl/src/outputs/json.rs
index c4add05e56e..ee764764d83 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"));
+ });
+ }
+}