From 9d491352d161ee629cc47459537344ba0ea4bb35 Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Sat, 20 Jun 2026 01:11:25 +0800 Subject: Add shared `MockProgramCollect` and conditional `Groupped` bounds Extract duplicate `MockCollect` implementations into a reusable `MockProgramCollect` type. Conditionally require `Serialize` on the `Groupped` trait when the `general_renderer` feature is enabled. --- mingling_core/tests/test-all/tests/integration.rs | 76 ++-------------------- mingling_core/tests/test-comp/tests/integration.rs | 55 ++-------------- 2 files changed, 8 insertions(+), 123 deletions(-) (limited to 'mingling_core/tests') diff --git a/mingling_core/tests/test-all/tests/integration.rs b/mingling_core/tests/test-all/tests/integration.rs index f910729..c622835 100644 --- a/mingling_core/tests/test-all/tests/integration.rs +++ b/mingling_core/tests/test-all/tests/integration.rs @@ -1,11 +1,10 @@ use mingling::Flag; use mingling::GeneralRenderer; use mingling::GeneralRendererSetting; -use mingling::Groupped; +use mingling::MockProgramCollect; use mingling::NextProcess; use mingling::Node; use mingling::Program; -use mingling::ProgramCollect; use mingling::RenderResult; use mingling::StringVec; use mingling::comp::{ShellContext, ShellFlag, Suggest}; @@ -14,73 +13,6 @@ use mingling::hook::ProgramHook; use serde::Serialize; use std::sync::atomic::{AtomicBool, Ordering}; -// MockCollect for is_completing tests - -#[derive(Debug, Clone, PartialEq)] -struct MockCollect; - -impl Groupped for MockCollect { - fn member_id() -> MockCollect { - MockCollect - } -} - -impl ProgramCollect for MockCollect { - type Enum = MockCollect; - type ErrorDispatcherNotFound = MockCollect; - type ErrorRendererNotFound = MockCollect; - type ResultEmpty = MockCollect; - - fn build_renderer_not_found(_member_id: MockCollect) -> mingling::AnyOutput { - unimplemented!() - } - fn build_dispatcher_not_found(_args: Vec) -> mingling::AnyOutput { - unimplemented!() - } - fn build_empty_result() -> mingling::AnyOutput { - unimplemented!() - } - fn render(_any: mingling::AnyOutput, _r: &mut RenderResult) { - unimplemented!() - } - fn render_help(_any: mingling::AnyOutput, _r: &mut RenderResult) { - unimplemented!() - } - fn do_chain(_any: mingling::AnyOutput) -> mingling::ChainProcess { - unimplemented!() - } - fn do_comp(_any: &mingling::AnyOutput, _ctx: &ShellContext) -> Suggest { - unimplemented!() - } - fn has_renderer(_any: &mingling::AnyOutput) -> bool { - unimplemented!() - } - fn has_chain(_any: &mingling::AnyOutput) -> bool { - unimplemented!() - } - - fn dispatch_args_trie( - _raw: &[String], - ) -> Result, mingling::error::ProgramInternalExecuteError> - { - unimplemented!() - } - - fn get_nodes() -> Vec<( - String, - &'static (dyn mingling::Dispatcher + Send + Sync), - )> { - unimplemented!() - } - - fn general_render( - _any: mingling::AnyOutput, - _setting: &GeneralRendererSetting, - ) -> Result { - unimplemented!() - } -} - // ShellContext #[test] @@ -192,13 +124,13 @@ fn test_general_renderer_json() { #[test] fn test_is_completing() { - let program: Program = Program::new_with_args(["app", "__comp"]); + let program: Program = Program::new_with_args(["app", "__comp"]); assert!(program.is_completing()); } #[test] fn test_is_not_completing() { - let program: Program = Program::new_with_args(["app", "greet"]); + let program: Program = Program::new_with_args(["app", "greet"]); assert!(!program.is_completing()); } @@ -208,7 +140,7 @@ fn test_is_not_completing() { fn test_hook_setup() { static CALLED: AtomicBool = AtomicBool::new(false); - let hook = ProgramHook::::empty().on_begin(|| { + let hook = ProgramHook::::empty().on_begin(|| { CALLED.store(true, Ordering::SeqCst); }); diff --git a/mingling_core/tests/test-comp/tests/integration.rs b/mingling_core/tests/test-comp/tests/integration.rs index 4e6455e..37aa716 100644 --- a/mingling_core/tests/test-comp/tests/integration.rs +++ b/mingling_core/tests/test-comp/tests/integration.rs @@ -1,55 +1,7 @@ -use mingling::Groupped; +use mingling::MockProgramCollect; use mingling::Program; -use mingling::ProgramCollect; -use mingling::RenderResult; use mingling::comp::{ShellContext, ShellFlag, Suggest, SuggestItem}; -/// Minimal mock collector that satisfies `C: ProgramCollect` -/// by setting `Enum = Self`. -#[derive(Debug, Clone, PartialEq)] -struct MockCollect; - -impl Groupped for MockCollect { - fn member_id() -> MockCollect { - MockCollect - } -} - -impl ProgramCollect for MockCollect { - type Enum = MockCollect; - type ErrorDispatcherNotFound = MockCollect; - type ErrorRendererNotFound = MockCollect; - type ResultEmpty = MockCollect; - - fn build_renderer_not_found(_member_id: MockCollect) -> mingling::AnyOutput { - unimplemented!() - } - fn build_dispatcher_not_found(_args: Vec) -> mingling::AnyOutput { - unimplemented!() - } - fn build_empty_result() -> mingling::AnyOutput { - unimplemented!() - } - fn render(_any: mingling::AnyOutput, _r: &mut RenderResult) { - unimplemented!() - } - fn render_help(_any: mingling::AnyOutput, _r: &mut RenderResult) { - unimplemented!() - } - fn do_chain(_any: mingling::AnyOutput) -> mingling::ChainProcess { - unimplemented!() - } - fn do_comp(_any: &mingling::AnyOutput, _ctx: &ShellContext) -> Suggest { - unimplemented!() - } - fn has_renderer(_any: &mingling::AnyOutput) -> bool { - unimplemented!() - } - fn has_chain(_any: &mingling::AnyOutput) -> bool { - unimplemented!() - } -} - #[test] fn test_shell_context_parsing_full() { let args = vec![ @@ -112,12 +64,13 @@ fn test_suggest_item_with_description() { #[test] fn test_program_is_completing() { - let program: Program = Program::new_with_args(["myapp", "__comp", "hello", ""]); + let program: Program = + Program::new_with_args(["myapp", "__comp", "hello", ""]); assert!(program.is_completing()); } #[test] fn test_program_is_not_completing() { - let program: Program = Program::new_with_args(["myapp", "hello"]); + let program: Program = Program::new_with_args(["myapp", "hello"]); assert!(!program.is_completing()); } -- cgit