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/src/comp/comp_ctx.rs | 65 ++++---------------------------------- 1 file changed, 6 insertions(+), 59 deletions(-) (limited to 'mingling_core/src/comp') diff --git a/mingling_core/src/comp/comp_ctx.rs b/mingling_core/src/comp/comp_ctx.rs index b9f9020..8d7fa5c 100644 --- a/mingling_core/src/comp/comp_ctx.rs +++ b/mingling_core/src/comp/comp_ctx.rs @@ -20,80 +20,27 @@ where #[cfg(test)] mod tests { - use super::*; - use crate::{AnyOutput, ChainProcess, Groupped, RenderResult}; - - /// 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 - } - } + use crate::MockProgramCollect; - impl ProgramCollect for MockCollect { - type Enum = MockCollect; - type ErrorDispatcherNotFound = MockCollect; - type ErrorRendererNotFound = MockCollect; - type ResultEmpty = MockCollect; - - fn build_renderer_not_found(_member_id: MockCollect) -> AnyOutput { - unimplemented!() - } - fn build_dispatcher_not_found(_args: Vec) -> AnyOutput { - unimplemented!() - } - fn build_empty_result() -> AnyOutput { - unimplemented!() - } - fn render(_any: AnyOutput, _r: &mut RenderResult) { - unimplemented!() - } - fn render_help(_any: AnyOutput, _r: &mut RenderResult) { - unimplemented!() - } - fn do_chain(_any: AnyOutput) -> ChainProcess { - unimplemented!() - } - #[cfg(feature = "comp")] - fn do_comp(_any: &AnyOutput, _ctx: &crate::ShellContext) -> crate::Suggest { - unimplemented!() - } - fn has_renderer(_any: &AnyOutput) -> bool { - unimplemented!() - } - fn has_chain(_any: &AnyOutput) -> bool { - unimplemented!() - } - - #[cfg(feature = "general_renderer")] - fn general_render( - _any: AnyOutput, - _setting: &crate::GeneralRendererSetting, - ) -> Result { - unimplemented!() - } - } + use super::*; #[test] fn test_is_completing_with_comp_subcommand() { - let program: Program = + let program: Program = Program::new_with_args(["program", "__comp", "some", "args"]); assert!(program.is_completing()); } #[test] fn test_is_completing_with_normal_subcommand() { - let program: Program = Program::new_with_args(["program", "normal", "cmd"]); + let program: Program = + Program::new_with_args(["program", "normal", "cmd"]); assert!(!program.is_completing()); } #[test] fn test_is_completing_with_no_args() { - let program: Program = Program::new_with_args(["program"]); + let program: Program = Program::new_with_args(["program"]); assert!(!program.is_completing()); } } -- cgit