From bd700d6dde79a8485780c8c5e416d157a997324a Mon Sep 17 00:00:00 2001 From: Tim Oram Date: Thu, 1 Jul 2021 22:02:47 -0230 Subject: Move handle_event_test to components module The handle_event_test utility function was only used in the components module, so move it to that module and remove the dependency on module. --- src/components/choice/tests.rs | 2 +- src/components/help/tests.rs | 2 +- src/components/mod.rs | 3 +++ src/components/testutil.rs | 19 +++++++++++++++++++ src/module/testutil/handle_event_test.rs | 19 ------------------- src/module/testutil/mod.rs | 3 +-- 6 files changed, 25 insertions(+), 23 deletions(-) create mode 100644 src/components/testutil.rs delete mode 100644 src/module/testutil/handle_event_test.rs diff --git a/src/components/choice/tests.rs b/src/components/choice/tests.rs index 87629e5..1c7cf2e 100644 --- a/src/components/choice/tests.rs +++ b/src/components/choice/tests.rs @@ -3,7 +3,7 @@ use rstest::rstest; use view::assert_rendered_output; use super::*; -use crate::module::testutil::handle_event_test; +use crate::components::testutil::handle_event_test; #[derive(Clone, Debug, PartialEq)] pub enum TestAction { diff --git a/src/components/help/tests.rs b/src/components/help/tests.rs index b197fca..a0aeb8c 100644 --- a/src/components/help/tests.rs +++ b/src/components/help/tests.rs @@ -3,7 +3,7 @@ use rstest::rstest; use view::assert_rendered_output; use super::*; -use crate::module::testutil::handle_event_test; +use crate::components::testutil::handle_event_test; #[test] fn empty() { diff --git a/src/components/mod.rs b/src/components/mod.rs index b1ba9bf..7bcb88a 100644 --- a/src/components/mod.rs +++ b/src/components/mod.rs @@ -2,3 +2,6 @@ pub mod choice; pub mod confirm; pub mod edit; pub mod help; + +#[cfg(test)] +mod testutil; diff --git a/src/components/testutil.rs b/src/components/testutil.rs new file mode 100644 index 0000000..4545774 --- /dev/null +++ b/src/components/testutil.rs @@ -0,0 +1,19 @@ +use input::{testutil::with_event_handler, Event, EventHandler}; +use view::{testutil::with_view_sender, ViewSender}; + +pub struct TestContext { + pub event_handler: EventHandler, + pub view_sender: ViewSender, +} + +pub fn handle_event_test(events: &[Event], callback: C) +where C: FnOnce(TestContext) { + with_view_sender(|view_sender_context| { + with_event_handler(events, |event_handler_context| { + callback(TestContext { + event_handler: event_handler_context.event_handler, + view_sender: view_sender_context.sender, + }); + }); + }); +} diff --git a/src/module/testutil/handle_event_test.rs b/src/module/testutil/handle_event_test.rs deleted file mode 100644 index 4545774..0000000 --- a/src/module/testutil/handle_event_test.rs +++ /dev/null @@ -1,19 +0,0 @@ -use input::{testutil::with_event_handler, Event, EventHandler}; -use view::{testutil::with_view_sender, ViewSender}; - -pub struct TestContext { - pub event_handler: EventHandler, - pub view_sender: ViewSender, -} - -pub fn handle_event_test(events: &[Event], callback: C) -where C: FnOnce(TestContext) { - with_view_sender(|view_sender_context| { - with_event_handler(events, |event_handler_context| { - callback(TestContext { - event_handler: event_handler_context.event_handler, - view_sender: view_sender_context.sender, - }); - }); - }); -} diff --git a/src/module/testutil/mod.rs b/src/module/testutil/mod.rs index 74aaea7..3eceb57 100644 --- a/src/module/testutil/mod.rs +++ b/src/module/testutil/mod.rs @@ -1,4 +1,3 @@ mod assert_process_result; -mod handle_event_test; -pub use self::{assert_process_result::_assert_process_result, handle_event_test::handle_event_test}; +pub use self::assert_process_result::_assert_process_result; -- cgit v1.2.3