Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Fix errors in passing TestAppContext in async gpui2 tests
Antonio Scandurrac5763cdb99cc
diff --git a/crates/gpui2/src/app/test_context.rs b/crates/gpui2/src/app/test_context.rsindex 15e6dcb3a47..c4f9abd7cb5 100644--- a/crates/gpui2/src/app/test_context.rs+++ b/crates/gpui2/src/app/test_context.rs@@ -48,6 +48,14 @@ impl TestAppContext {}}+ pub fn remove_all_windows(&self) {+ // todo!("use app quit instead")+ }++ pub fn clear_globals(&self) {+ // todo!("use app quit instead")+ }+pub fn refresh(&mut self) -> Result<()> {let mut lock = self.app.lock();lock.refresh();diff --git a/crates/gpui2_macros/src/test.rs b/crates/gpui2_macros/src/test.rsindex 4185e4850a0..cbab11fcd05 100644--- a/crates/gpui2_macros/src/test.rs+++ b/crates/gpui2_macros/src/test.rs@@ -3,8 +3,8 @@ use proc_macro2::Ident;use quote::{format_ident, quote};use std::mem;use syn::{- parse_macro_input, parse_quote, spanned::Spanned as _, AttributeArgs, DeriveInput, FnArg,- GenericParam, Generics, ItemFn, Lit, Meta, NestedMeta, Type, WhereClause,+ parse_macro_input, parse_quote, spanned::Spanned as _, AttributeArgs, FnArg,+ ItemFn, Lit, Meta, NestedMeta, Type,};pub fn test(args: TokenStream, function: TokenStream) -> TokenStream {@@ -106,13 +106,13 @@ pub fn test(args: TokenStream, function: TokenStream) -> TokenStream {let cx_varname = format_ident!("cx_{}", ix);cx_vars.extend(quote!(let mut #cx_varname = gpui2::TestAppContext::new(- std::sync::Arc::new(dispatcher.clone())+ dispatcher.clone());));cx_teardowns.extend(quote!(#cx_varname.remove_all_windows();dispatcher.run_until_parked();- #cx_varname.update(|cx| cx.clear_globals());+ #cx_varname.clear_globals();dispatcher.run_until_parked();));inner_fn_args.extend(quote!(&mut #cx_varname,));@@ -170,7 +170,7 @@ pub fn test(args: TokenStream, function: TokenStream) -> TokenStream {let cx_varname_lock = format_ident!("cx_{}_lock", ix);cx_vars.extend(quote!(let mut #cx_varname = gpui2::TestAppContext::new(- std::sync::Arc::new(dispatcher.clone())+ dispatcher.clone());let mut #cx_varname_lock = cx_varname.app.lock();));@@ -178,7 +178,7 @@ pub fn test(args: TokenStream, function: TokenStream) -> TokenStream {cx_teardowns.extend(quote!(#cx_varname.remove_all_windows();dispatcher.run_until_parked();- #cx_varname.update(|cx| cx.clear_globals());+ #cx_varname.clear_globals();dispatcher.run_until_parked();));continue;@@ -187,13 +187,13 @@ pub fn test(args: TokenStream, function: TokenStream) -> TokenStream {let cx_varname = format_ident!("cx_{}", ix);cx_vars.extend(quote!(let mut #cx_varname = gpui2::TestAppContext::new(- std::sync::Arc::new(dispatcher.clone())+ dispatcher.clone());));cx_teardowns.extend(quote!(#cx_varname.remove_all_windows();dispatcher.run_until_parked();- #cx_varname.update(|cx| cx.clear_globals());+ #cx_varname.clear_globals();dispatcher.run_until_parked();));inner_fn_args.extend(quote!(&mut #cx_varname,));@@ -243,13 +243,3 @@ fn parse_int(literal: &Lit) -> Result<usize, TokenStream> {result.map_err(|err| TokenStream::from(err.into_compile_error()))}--fn parse_bool(literal: &Lit) -> Result<bool, TokenStream> {- let result = if let Lit::Bool(result) = &literal {- Ok(result.value)- } else {- Err(syn::Error::new(literal.span(), "must be a boolean"))- };-- result.map_err(|err| TokenStream::from(err.into_compile_error()))-}diff --git a/crates/language2/src/buffer_tests.rs b/crates/language2/src/buffer_tests.rsindex 054b3fc7822..b40253da21a 100644--- a/crates/language2/src/buffer_tests.rs+++ b/crates/language2/src/buffer_tests.rs@@ -1,3 +1,7 @@+use crate::Buffer;+use gpui2::{Context, TestAppContext};+use text::{Point, ToPoint};+// use crate::language_settings::{// AllLanguageSettings, AllLanguageSettingsContent, LanguageSettingsContent,// };@@ -219,28 +223,29 @@// );// }-// #[gpui::test]-// async fn test_apply_diff(cx: &mut gpui::TestAppContext) {-// let text = "a\nbb\nccc\ndddd\neeeee\nffffff\n";-// let buffer = cx.add_model(|cx| Buffer::new(0, cx.model_id() as u64, text));-// let anchor = buffer.read_with(cx, |buffer, _| buffer.anchor_before(Point::new(3, 3)));--// let text = "a\nccc\ndddd\nffffff\n";-// let diff = buffer.read_with(cx, |b, cx| b.diff(text.into(), cx)).await;-// buffer.update(cx, |buffer, cx| {-// buffer.apply_diff(diff, cx).unwrap();-// assert_eq!(buffer.text(), text);-// assert_eq!(anchor.to_point(buffer), Point::new(2, 3));-// });--// let text = "a\n1\n\nccc\ndd2dd\nffffff\n";-// let diff = buffer.read_with(cx, |b, cx| b.diff(text.into(), cx)).await;-// buffer.update(cx, |buffer, cx| {-// buffer.apply_diff(diff, cx).unwrap();-// assert_eq!(buffer.text(), text);-// assert_eq!(anchor.to_point(buffer), Point::new(4, 4));-// });-// }+// #[gpui::test] todo!()+#[gpui2::test]+async fn test_apply_diff(cx: &mut TestAppContext) {+ let text = "a\nbb\nccc\ndddd\neeeee\nffffff\n";+ let buffer = cx.entity(|cx| Buffer::new(0, cx.entity_id().as_u64(), text));+ let anchor = buffer.update(cx, |buffer, _| buffer.anchor_before(Point::new(3, 3)));++ let text = "a\nccc\ndddd\nffffff\n";+ let diff = buffer.update(cx, |b, cx| b.diff(text.into(), cx)).await;+ buffer.update(cx, |buffer, cx| {+ buffer.apply_diff(diff, cx).unwrap();+ assert_eq!(buffer.text(), text);+ assert_eq!(anchor.to_point(buffer), Point::new(2, 3));+ });++ let text = "a\n1\n\nccc\ndd2dd\nffffff\n";+ let diff = buffer.update(cx, |b, cx| b.diff(text.into(), cx)).await;+ buffer.update(cx, |buffer, cx| {+ buffer.apply_diff(diff, cx).unwrap();+ assert_eq!(buffer.text(), text);+ assert_eq!(anchor.to_point(buffer), Point::new(4, 4));+ });+}// #[gpui::test(iterations = 10)]// async fn test_normalize_whitespace(cx: &mut gpui::TestAppContext) {