From bc4ecb199b4ad3a580d3b29e659e707ce1a29f04 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Wed, 10 Mar 2021 21:05:02 +0100 Subject: Use expect-test for builtin macro/derive tests --- crates/hir_expand/src/builtin_derive.rs | 66 +++++++++++++++------------------ 1 file changed, 29 insertions(+), 37 deletions(-) (limited to 'crates/hir_expand/src/builtin_derive.rs') diff --git a/crates/hir_expand/src/builtin_derive.rs b/crates/hir_expand/src/builtin_derive.rs index b7f1aae8f..dfdb9cf59 100644 --- a/crates/hir_expand/src/builtin_derive.rs +++ b/crates/hir_expand/src/builtin_derive.rs @@ -267,13 +267,14 @@ fn partial_ord_expand( #[cfg(test)] mod tests { use base_db::{fixture::WithFixture, CrateId, SourceDatabase}; + use expect_test::{expect, Expect}; use name::{known, Name}; use crate::{test_db::TestDB, AstId, MacroCallId, MacroCallKind, MacroCallLoc}; use super::*; - fn expand_builtin_derive(s: &str, name: Name) -> String { + fn expand_builtin_derive(ra_fixture: &str, name: Name) -> String { let expander = BuiltinDeriveExpander::find_by_name(&name).unwrap(); let fixture = format!( r#"//- /main.rs crate:main deps:core @@ -282,7 +283,7 @@ $0 //- /lib.rs crate:core // empty "#, - s + ra_fixture ); let (db, file_pos) = TestDB::with_position(&fixture); @@ -314,66 +315,57 @@ $0 parsed.text().to_string() } + fn check_derive(ra_fixture: &str, name: Name, expected: Expect) { + let expanded = expand_builtin_derive(ra_fixture, name); + expected.assert_eq(&expanded); + } + #[test] fn test_copy_expand_simple() { - let expanded = expand_builtin_derive( + check_derive( r#" - #[derive(Copy)] - struct Foo; -"#, + #[derive(Copy)] + struct Foo; + "#, known::Copy, + expect![["impl< >core::marker::CopyforFoo< >{}"]], ); - - assert_eq!(expanded, "impl< >core::marker::CopyforFoo< >{}"); } #[test] fn test_copy_expand_with_type_params() { - let expanded = expand_builtin_derive( + check_derive( r#" - #[derive(Copy)] - struct Foo; -"#, + #[derive(Copy)] + struct Foo; + "#, known::Copy, - ); - - assert_eq!( - expanded, - "implcore::marker::CopyforFoo{}" + expect![["implcore::marker::CopyforFoo{}"]], ); } #[test] fn test_copy_expand_with_lifetimes() { - let expanded = expand_builtin_derive( + check_derive( r#" - #[derive(Copy)] - struct Foo; -"#, + #[derive(Copy)] + struct Foo; + "#, known::Copy, - ); - - // We currently just ignore lifetimes - - assert_eq!( - expanded, - "implcore::marker::CopyforFoo{}" + // We currently just ignore lifetimes + expect![["implcore::marker::CopyforFoo{}"]], ); } #[test] fn test_clone_expand() { - let expanded = expand_builtin_derive( + check_derive( r#" - #[derive(Clone)] - struct Foo; -"#, + #[derive(Clone)] + struct Foo; + "#, known::Clone, - ); - - assert_eq!( - expanded, - "implcore::clone::CloneforFoo{}" + expect![["implcore::clone::CloneforFoo{}"]], ); } } -- cgit v1.2.3