diff options
| author | Weicao-CatilGrass <1992414357@qq.com> | 2026-06-09 21:08:20 +0800 |
|---|---|---|
| committer | Weicao-CatilGrass <1992414357@qq.com> | 2026-06-09 22:23:16 +0800 |
| commit | 514929c3b8ee0d4f540be5eb4bc8c1a10e62095d (patch) | |
| tree | 8faeeb71075a695354496af38eb527085bb37f92 /mingling_core/src/program/setup.rs | |
| parent | 92cccd9517e764508dfa0342ae2ea254661d0a8f (diff) | |
Add unit and integration tests for mingling_core
Diffstat (limited to 'mingling_core/src/program/setup.rs')
| -rw-r--r-- | mingling_core/src/program/setup.rs | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/mingling_core/src/program/setup.rs b/mingling_core/src/program/setup.rs index fa9d0eb..2bfced1 100644 --- a/mingling_core/src/program/setup.rs +++ b/mingling_core/src/program/setup.rs @@ -16,3 +16,85 @@ where S::setup(setup, self); } } + +#[cfg(test)] +mod tests { + use super::*; + use crate::{AnyOutput, ChainProcess, Groupped, RenderResult}; + + /// Minimal mock collector that satisfies `C: ProgramCollect<Enum = C>` + /// by setting `Enum = Self`. + #[derive(Debug, Clone, PartialEq)] + struct MockCollect; + + impl Groupped<MockCollect> 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<MockCollect> { + unimplemented!() + } + fn build_dispatcher_not_found(_args: Vec<String>) -> AnyOutput<MockCollect> { + unimplemented!() + } + fn build_empty_result() -> AnyOutput<MockCollect> { + unimplemented!() + } + fn render(_any: AnyOutput<MockCollect>, _r: &mut RenderResult) { + unimplemented!() + } + fn render_help(_any: AnyOutput<MockCollect>, _r: &mut RenderResult) { + unimplemented!() + } + fn do_chain(_any: AnyOutput<MockCollect>) -> ChainProcess<MockCollect> { + unimplemented!() + } + #[cfg(feature = "comp")] + fn do_comp(_any: &AnyOutput<MockCollect>, _ctx: &crate::ShellContext) -> crate::Suggest { + unimplemented!() + } + fn has_renderer(_any: &AnyOutput<MockCollect>) -> bool { + unimplemented!() + } + fn has_chain(_any: &AnyOutput<MockCollect>) -> bool { + unimplemented!() + } + + #[cfg(feature = "general_renderer")] + fn general_render( + _any: AnyOutput<MockCollect>, + _setting: &crate::GeneralRendererSetting, + ) -> Result<RenderResult, crate::error::GeneralRendererSerializeError> { + unimplemented!() + } + } + + struct TestSetup { + called: std::rc::Rc<std::cell::Cell<bool>>, + } + + impl ProgramSetup<MockCollect> for TestSetup { + fn setup(self, _program: &mut Program<MockCollect>) { + self.called.set(true); + } + } + + #[test] + fn test_with_setup_calls_setup() { + let called = std::rc::Rc::new(std::cell::Cell::new(false)); + let setup = TestSetup { + called: std::rc::Rc::clone(&called), + }; + let mut program: Program<MockCollect> = Program::new_with_args(["test"]); + program.with_setup(setup); + assert!(called.get()); + } +} |
