From ebb591a5704f767d783d57af7022272f665318ac Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 18 Jun 2021 00:30:22 +0300 Subject: internal: add derive and ord support to minicore --- crates/ide_assists/src/handlers/apply_demorgan.rs | 114 +++++++++++++--------- crates/ide_assists/src/tests.rs | 1 + 2 files changed, 67 insertions(+), 48 deletions(-) (limited to 'crates/ide_assists') diff --git a/crates/ide_assists/src/handlers/apply_demorgan.rs b/crates/ide_assists/src/handlers/apply_demorgan.rs index c93959e66..e2bd6e456 100644 --- a/crates/ide_assists/src/handlers/apply_demorgan.rs +++ b/crates/ide_assists/src/handlers/apply_demorgan.rs @@ -147,74 +147,92 @@ fn opposite_logic_op(kind: ast::BinOp) -> Option<&'static str> { #[cfg(test)] mod tests { - use ide_db::helpers::FamousDefs; - - use super::*; - use crate::tests::{check_assist, check_assist_not_applicable}; - const ORDABLE_FIXTURE: &'static str = r" -//- /lib.rs deps:core crate:ordable -struct NonOrderable; -struct Orderable; -impl core::cmp::Ord for Orderable {} -"; - - fn check(ra_fixture_before: &str, ra_fixture_after: &str) { - let before = &format!( - "//- /main.rs crate:main deps:core,ordable\n{}\n{}{}", - ra_fixture_before, - FamousDefs::FIXTURE, - ORDABLE_FIXTURE - ); - check_assist(apply_demorgan, before, &format!("{}\n", ra_fixture_after)); - } + use super::*; #[test] fn demorgan_handles_leq() { - check( - r"use ordable::Orderable; + check_assist( + apply_demorgan, + r#" +//- minicore: ord, derive +#[derive(PartialEq, Eq, PartialOrd, Ord)] +struct S; + fn f() { - Orderable < Orderable &&$0 Orderable <= Orderable -}", - r"use ordable::Orderable; + S < S &&$0 S <= S +} +"#, + r#" +#[derive(PartialEq, Eq, PartialOrd, Ord)] +struct S; + fn f() { - !(Orderable >= Orderable || Orderable > Orderable) -}", + !(S >= S || S > S) +} +"#, ); - check( - r"use ordable::NonOrderable; + + check_assist( + apply_demorgan, + r#" +//- minicore: ord, derive +struct S; + fn f() { - NonOrderable < NonOrderable &&$0 NonOrderable <= NonOrderable -}", - r"use ordable::NonOrderable; + S < S &&$0 S <= S +} +"#, + r#" +struct S; + fn f() { - !(!(NonOrderable < NonOrderable) || !(NonOrderable <= NonOrderable)) -}", + !(!(S < S) || !(S <= S)) +} +"#, ); } #[test] fn demorgan_handles_geq() { - check( - r"use ordable::Orderable; + check_assist( + apply_demorgan, + r#" +//- minicore: ord, derive +#[derive(PartialEq, Eq, PartialOrd, Ord)] +struct S; + fn f() { - Orderable > Orderable &&$0 Orderable >= Orderable -}", - r"use ordable::Orderable; + S > S &&$0 S >= S +} +"#, + r#" +#[derive(PartialEq, Eq, PartialOrd, Ord)] +struct S; + fn f() { - !(Orderable <= Orderable || Orderable < Orderable) -}", + !(S <= S || S < S) +} +"#, ); - check( - r"use ordable::NonOrderable; + check_assist( + apply_demorgan, + r#" +//- minicore: ord, derive +struct S; + fn f() { - Orderable > Orderable &&$0 Orderable >= Orderable -}", - r"use ordable::NonOrderable; + S > S &&$0 S >= S +} +"#, + r#" +struct S; + fn f() { - !(!(Orderable > Orderable) || !(Orderable >= Orderable)) -}", + !(!(S > S) || !(S >= S)) +} +"#, ); } diff --git a/crates/ide_assists/src/tests.rs b/crates/ide_assists/src/tests.rs index 29bd4a563..4e96ff1ec 100644 --- a/crates/ide_assists/src/tests.rs +++ b/crates/ide_assists/src/tests.rs @@ -35,6 +35,7 @@ pub(crate) fn with_single_file(text: &str) -> (RootDatabase, FileId) { RootDatabase::with_single_file(text) } +#[track_caller] pub(crate) fn check_assist(assist: Handler, ra_fixture_before: &str, ra_fixture_after: &str) { let ra_fixture_after = trim_indent(ra_fixture_after); check(assist, ra_fixture_before, ExpectedResult::After(&ra_fixture_after), None); -- cgit v1.2.3