From 514929c3b8ee0d4f540be5eb4bc8c1a10e62095d Mon Sep 17 00:00:00 2001 From: Weicao-CatilGrass <1992414357@qq.com> Date: Tue, 9 Jun 2026 21:08:20 +0800 Subject: Add unit and integration tests for mingling_core --- mingling_core/src/comp/comp_ctx.rs | 80 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) (limited to 'mingling_core/src/comp/comp_ctx.rs') diff --git a/mingling_core/src/comp/comp_ctx.rs b/mingling_core/src/comp/comp_ctx.rs index 02e79c5..b9f9020 100644 --- a/mingling_core/src/comp/comp_ctx.rs +++ b/mingling_core/src/comp/comp_ctx.rs @@ -17,3 +17,83 @@ where .is_some_and(|arg| arg == COMPLETION_SUBCOMMAND) } } + +#[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 + } + } + + 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!() + } + } + + #[test] + fn test_is_completing_with_comp_subcommand() { + 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"]); + assert!(!program.is_completing()); + } + + #[test] + fn test_is_completing_with_no_args() { + let program: Program = Program::new_with_args(["program"]); + assert!(!program.is_completing()); + } +} -- cgit