@@ -1080,6 +1080,112 @@ fn test_fold_action_multiple_line_breaks(cx: &mut TestAppContext) {
});
}
+#[gpui::test]
+fn test_fold_at_level(cx: &mut TestAppContext) {
+ init_test(cx, |_| {});
+
+ let view = cx.add_window(|cx| {
+ let buffer = MultiBuffer::build_simple(
+ &"
+ class Foo:
+ # Hello!
+
+ def a():
+ print(1)
+
+ def b():
+ print(2)
+
+
+ class Bar:
+ # World!
+
+ def a():
+ print(1)
+
+ def b():
+ print(2)
+
+
+ "
+ .unindent(),
+ cx,
+ );
+ build_editor(buffer.clone(), cx)
+ });
+
+ _ = view.update(cx, |view, cx| {
+ view.fold_at_level(&FoldAtLevel { level: 2 }, cx);
+ assert_eq!(
+ view.display_text(cx),
+ "
+ class Foo:
+ # Hello!
+
+ def a():⋯
+
+ def b():⋯
+
+
+ class Bar:
+ # World!
+
+ def a():⋯
+
+ def b():⋯
+
+
+ "
+ .unindent(),
+ );
+
+ view.fold_at_level(&FoldAtLevel { level: 1 }, cx);
+ assert_eq!(
+ view.display_text(cx),
+ "
+ class Foo:⋯
+
+
+ class Bar:⋯
+
+
+ "
+ .unindent(),
+ );
+
+ view.unfold_all(&UnfoldAll, cx);
+ view.fold_at_level(&FoldAtLevel { level: 0 }, cx);
+ assert_eq!(
+ view.display_text(cx),
+ "
+ class Foo:
+ # Hello!
+
+ def a():
+ print(1)
+
+ def b():
+ print(2)
+
+
+ class Bar:
+ # World!
+
+ def a():
+ print(1)
+
+ def b():
+ print(2)
+
+
+ "
+ .unindent(),
+ );
+
+ assert_eq!(view.display_text(cx), view.buffer.read(cx).read(cx).text());
+ });
+}
+
#[gpui::test]
fn test_move_cursor(cx: &mut TestAppContext) {
init_test(cx, |_| {});