From 213658f1e9105628a7b137058973601ea030e015 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Fri, 6 Jan 2023 17:56:21 -0700 Subject: [PATCH] Fix tests that failed due to defaulting the grouping interval to zero in tests --- crates/collab/src/tests/integration_tests.rs | 7 ++++++- crates/editor/src/editor.rs | 2 ++ crates/editor/src/editor_tests.rs | 8 +++++++- crates/language/src/buffer_tests.rs | 11 ++++++++++- 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/crates/collab/src/tests/integration_tests.rs b/crates/collab/src/tests/integration_tests.rs index 4a1aaf64d1d9d4233e2bcfa51bd01fd2d1f59f9c..729da6d10980a6d8b8a7a335fbd16bd01d0b06e3 100644 --- a/crates/collab/src/tests/integration_tests.rs +++ b/crates/collab/src/tests/integration_tests.rs @@ -1131,6 +1131,7 @@ async fn test_unshare_project( .unwrap(); let worktree_a = project_a.read_with(cx_a, |project, cx| project.worktrees(cx).next().unwrap()); let project_b = client_b.build_remote_project(project_id, cx_b).await; + deterministic.run_until_parked(); assert!(worktree_a.read_with(cx_a, |tree, _| tree.as_local().unwrap().is_shared())); project_b @@ -1160,6 +1161,7 @@ async fn test_unshare_project( .await .unwrap(); let project_c2 = client_c.build_remote_project(project_id, cx_c).await; + deterministic.run_until_parked(); assert!(worktree_a.read_with(cx_a, |tree, _| tree.as_local().unwrap().is_shared())); project_c2 .update(cx_c, |p, cx| p.open_buffer((worktree_id, "a.txt"), cx)) @@ -1213,6 +1215,7 @@ async fn test_host_disconnect( .unwrap(); let project_b = client_b.build_remote_project(project_id, cx_b).await; + deterministic.run_until_parked(); assert!(worktree_a.read_with(cx_a, |tree, _| tree.as_local().unwrap().is_shared())); let (_, workspace_b) = cx_b.add_window(|cx| { @@ -1467,7 +1470,7 @@ async fn test_project_reconnect( .read_with(cx_a, |tree, _| tree.as_local().unwrap().scan_complete()) .await; let worktree3_id = worktree_a3.read_with(cx_a, |tree, _| { - assert!(tree.as_local().unwrap().is_shared()); + assert!(!tree.as_local().unwrap().is_shared()); tree.id() }); deterministic.run_until_parked(); @@ -1489,6 +1492,7 @@ async fn test_project_reconnect( deterministic.run_until_parked(); project_a1.read_with(cx_a, |project, cx| { assert!(project.is_shared()); + assert!(worktree_a1.read(cx).as_local().unwrap().is_shared()); assert_eq!( worktree_a1 .read(cx) @@ -1510,6 +1514,7 @@ async fn test_project_reconnect( "subdir2/i.txt" ] ); + assert!(worktree_a3.read(cx).as_local().unwrap().is_shared()); assert_eq!( worktree_a3 .read(cx) diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index d8ee49866b404d4d1d12efbd540b467096485d81..85da12658a8a97e8904b8fcf820ae815726c8804 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -3611,7 +3611,9 @@ impl Editor { } pub fn undo(&mut self, _: &Undo, cx: &mut ViewContext) { + dbg!("undo"); if let Some(tx_id) = self.buffer.update(cx, |buffer, cx| buffer.undo(cx)) { + dbg!(tx_id); if let Some((selections, _)) = self.selection_history.transaction(tx_id).cloned() { self.change_selections(None, cx, |s| { s.select_anchors(selections.to_vec()); diff --git a/crates/editor/src/editor_tests.rs b/crates/editor/src/editor_tests.rs index 2fcc5f0014ef942a9d12762a6ae424de1aabfcc1..b9f3c67f38bfb23239eb3cd0d6f9063d87f003bc 100644 --- a/crates/editor/src/editor_tests.rs +++ b/crates/editor/src/editor_tests.rs @@ -29,7 +29,11 @@ use workspace::{ #[gpui::test] fn test_edit_events(cx: &mut MutableAppContext) { cx.set_global(Settings::test(cx)); - let buffer = cx.add_model(|cx| language::Buffer::new(0, "123456", cx)); + let buffer = cx.add_model(|cx| { + let mut buffer = language::Buffer::new(0, "123456", cx); + buffer.set_group_interval(Duration::from_secs(1)); + buffer + }); let events = Rc::new(RefCell::new(Vec::new())); let (_, editor1) = cx.add_window(Default::default(), { @@ -3502,6 +3506,8 @@ async fn test_surround_with_pair(cx: &mut gpui::TestAppContext) { ] ); + view.undo(&Undo, cx); + view.undo(&Undo, cx); view.undo(&Undo, cx); assert_eq!( view.text(cx), diff --git a/crates/language/src/buffer_tests.rs b/crates/language/src/buffer_tests.rs index e0b7d080cb1320f944b9ff2c4d72c82a0953779d..09ccc5d62138e1a351fcc60b9b5cb02088f17fb8 100644 --- a/crates/language/src/buffer_tests.rs +++ b/crates/language/src/buffer_tests.rs @@ -289,6 +289,9 @@ async fn test_reparse(cx: &mut gpui::TestAppContext) { ); buffer.update(cx, |buf, cx| { + buf.undo(cx); + buf.undo(cx); + buf.undo(cx); buf.undo(cx); assert_eq!(buf.text(), "fn a() {}"); assert!(buf.is_parsing()); @@ -304,6 +307,9 @@ async fn test_reparse(cx: &mut gpui::TestAppContext) { ); buffer.update(cx, |buf, cx| { + buf.redo(cx); + buf.redo(cx); + buf.redo(cx); buf.redo(cx); assert_eq!(buf.text(), "fn a(b: C) { d.e::(f); }"); assert!(buf.is_parsing()); @@ -1022,8 +1028,11 @@ fn test_autoindent_block_mode(cx: &mut MutableAppContext) { .unindent() ); + // Grouping is disabled in tests, so we need 2 undos + buffer.undo(cx); // Undo the auto-indent + buffer.undo(cx); // Undo the original edit + // Insert the block at a deeper indent level. The entire block is outdented. - buffer.undo(cx); buffer.edit([(Point::new(2, 0)..Point::new(2, 0), " ")], None, cx); buffer.edit( [(Point::new(2, 8)..Point::new(2, 8), inserted_text)],