X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=crates%2Fide%2Fsrc%2Fhover%2Ftests.rs;h=c5c531c30b1a4896ed4e0c392c12457f5c0be30b;hb=842ffde43d2c4e4dff94b9f07675708f1ac4ca8c;hp=842643cb97c481ba755abaf9fb7cc5731ba08faf;hpb=85ed5a318264e5639caf1a98fde2c92291f15e75;p=rust.git diff --git a/crates/ide/src/hover/tests.rs b/crates/ide/src/hover/tests.rs index 842643cb97c..c5c531c30b1 100644 --- a/crates/ide/src/hover/tests.rs +++ b/crates/ide/src/hover/tests.rs @@ -552,7 +552,7 @@ fn hover_const_static() { ``` ```rust - const foo: u32 = 123 + const foo: u32 = 123 (0x7B) ``` "#]], ); @@ -1148,7 +1148,7 @@ fn bar() -> u32 { 0 } fn test_hover_through_literal_string_in_macro() { check( r#" -macro_rules! arr { ($($tt:tt)*) => { [$($tt)*)] } } +macro_rules! arr { ($($tt:tt)*) => { [$($tt)*] } } fn foo() { let mastered_for_itunes = ""; let _ = arr!("Tr$0acks", &mastered_for_itunes); @@ -1310,6 +1310,60 @@ async fn foo() ); } +#[test] +fn test_hover_function_show_types() { + check( + r#"fn foo$0(a: i32, b:i32) -> i32 { 0 }"#, + expect![[r#" + *foo* + + ```rust + test + ``` + + ```rust + fn foo(a: i32, b: i32) -> i32 + ``` + "#]], + ); +} + +#[test] +fn test_hover_function_pointer_show_identifiers() { + check( + r#"type foo$0 = fn(a: i32, b: i32) -> i32;"#, + expect![[r#" + *foo* + + ```rust + test + ``` + + ```rust + type foo = fn(a: i32, b: i32) -> i32 + ``` + "#]], + ); +} + +#[test] +fn test_hover_function_pointer_no_identifier() { + check( + r#"type foo$0 = fn(i32, _: i32) -> i32;"#, + expect![[r#" + *foo* + + ```rust + test + ``` + + ```rust + type foo = fn(i32, i32) -> i32 + ``` + "#]], + ); +} + #[test] fn test_hover_trait_show_qualifiers() { check_actions( @@ -3278,6 +3332,165 @@ impl Foo {} ); } +#[test] +fn hover_const_eval() { + check( + r#" +/// This is a doc +const FOO$0: usize = !0 & !(!0 >> 1); +"#, + expect![[r#" + *FOO* + + ```rust + test + ``` + + ```rust + const FOO: usize = 9223372036854775808 (0x8000000000000000) + ``` + + --- + + This is a doc + "#]], + ); + check( + r#" +/// This is a doc +const FOO$0: usize = { + let a = 3 + 2; + let b = a * a; + b +}; +"#, + expect![[r#" + *FOO* + + ```rust + test + ``` + + ```rust + const FOO: usize = 25 (0x19) + ``` + + --- + + This is a doc + "#]], + ); + check( + r#" +/// This is a doc +const FOO$0: usize = 1 << 10; +"#, + expect![[r#" + *FOO* + + ```rust + test + ``` + + ```rust + const FOO: usize = 1024 (0x400) + ``` + + --- + + This is a doc + "#]], + ); + check( + r#" +/// This is a doc +const FOO$0: usize = { + let b = 4; + let a = { let b = 2; let a = b; a } + { let a = 1; a + b }; + a +}; +"#, + expect![[r#" + *FOO* + + ```rust + test + ``` + + ```rust + const FOO: usize = 7 + ``` + + --- + + This is a doc + "#]], + ); + check( + r#" +/// This is a doc +const FOO$0: usize = 2 - 3; +"#, + expect![[r#" + *FOO* + + ```rust + test + ``` + + ```rust + const FOO: usize = 2 - 3 + ``` + + --- + + This is a doc + "#]], + ); + check( + r#" +/// This is a doc +const FOO$0: i32 = 2 - 3; +"#, + expect![[r#" + *FOO* + + ```rust + test + ``` + + ```rust + const FOO: i32 = -1 + ``` + + --- + + This is a doc + "#]], + ); + check( + r#" +/// This is a doc +const FOO$0: usize = 1 << 100; +"#, + expect![[r#" + *FOO* + + ```rust + test + ``` + + ```rust + const FOO: usize = 1 << 100 + ``` + + --- + + This is a doc + "#]], + ); +} + #[test] fn hover_const_pat() { check( @@ -3309,6 +3522,24 @@ fn foo() { ); } +#[test] +fn array_repeat_exp() { + check( + r#" +fn main() { + let til$0e4 = [0_u32; (4 * 8 * 8) / 32]; +} + "#, + expect![[r#" + *tile4* + + ```rust + let tile4: [u32; 8] + ``` + "#]], + ); +} + #[test] fn hover_mod_def() { check(