aboutsummaryrefslogtreecommitdiff
path: root/mingling_core/tests/test-comp
diff options
context:
space:
mode:
authorWeicao-CatilGrass <1992414357@qq.com>2026-06-09 21:08:20 +0800
committerWeicao-CatilGrass <1992414357@qq.com>2026-06-09 22:23:16 +0800
commit514929c3b8ee0d4f540be5eb4bc8c1a10e62095d (patch)
tree8faeeb71075a695354496af38eb527085bb37f92 /mingling_core/tests/test-comp
parent92cccd9517e764508dfa0342ae2ea254661d0a8f (diff)
Add unit and integration tests for mingling_core
Diffstat (limited to 'mingling_core/tests/test-comp')
-rw-r--r--mingling_core/tests/test-comp/Cargo.lock86
-rw-r--r--mingling_core/tests/test-comp/Cargo.toml10
-rw-r--r--mingling_core/tests/test-comp/tests/integration.rs123
3 files changed, 219 insertions, 0 deletions
diff --git a/mingling_core/tests/test-comp/Cargo.lock b/mingling_core/tests/test-comp/Cargo.lock
new file mode 100644
index 0000000..ad384fe
--- /dev/null
+++ b/mingling_core/tests/test-comp/Cargo.lock
@@ -0,0 +1,86 @@
+# This file is automatically @generated by Cargo.
+# It is not intended for manual editing.
+version = 4
+
+[[package]]
+name = "just_fmt"
+version = "0.1.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5454cda0d57db59778608d7a47bff5b16c6705598265869fb052b657f66cf05e"
+
+[[package]]
+name = "just_template"
+version = "0.1.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "db3edb658c34b10b69c4b3b58f7ba989cd09c82c0621dee1eef51843c2327225"
+dependencies = [
+ "just_fmt",
+]
+
+[[package]]
+name = "mingling"
+version = "0.2.0"
+dependencies = [
+ "mingling_core",
+ "mingling_macros",
+]
+
+[[package]]
+name = "mingling_core"
+version = "0.2.0"
+dependencies = [
+ "just_fmt",
+ "just_template",
+]
+
+[[package]]
+name = "mingling_macros"
+version = "0.2.0"
+dependencies = [
+ "just_fmt",
+ "proc-macro2",
+ "quote",
+ "syn",
+]
+
+[[package]]
+name = "proc-macro2"
+version = "1.0.106"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934"
+dependencies = [
+ "unicode-ident",
+]
+
+[[package]]
+name = "quote"
+version = "1.0.45"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "41f2619966050689382d2b44f664f4bc593e129785a36d6ee376ddf37259b924"
+dependencies = [
+ "proc-macro2",
+]
+
+[[package]]
+name = "syn"
+version = "2.0.117"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e665b8803e7b1d2a727f4023456bbbbe74da67099c585258af0ad9c5013b9b99"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "unicode-ident",
+]
+
+[[package]]
+name = "test-comp"
+version = "0.1.0"
+dependencies = [
+ "mingling",
+]
+
+[[package]]
+name = "unicode-ident"
+version = "1.0.24"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75"
diff --git a/mingling_core/tests/test-comp/Cargo.toml b/mingling_core/tests/test-comp/Cargo.toml
new file mode 100644
index 0000000..9ceca3e
--- /dev/null
+++ b/mingling_core/tests/test-comp/Cargo.toml
@@ -0,0 +1,10 @@
+[package]
+name = "test-comp"
+version = "0.1.0"
+edition = "2024"
+publish = false
+
+[workspace]
+
+[dependencies]
+mingling = { path = "../../../mingling", features = ["comp", "builds"] }
diff --git a/mingling_core/tests/test-comp/tests/integration.rs b/mingling_core/tests/test-comp/tests/integration.rs
new file mode 100644
index 0000000..4e6455e
--- /dev/null
+++ b/mingling_core/tests/test-comp/tests/integration.rs
@@ -0,0 +1,123 @@
+use mingling::Groupped;
+use mingling::Program;
+use mingling::ProgramCollect;
+use mingling::RenderResult;
+use mingling::comp::{ShellContext, ShellFlag, Suggest, SuggestItem};
+
+/// 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) -> mingling::AnyOutput<MockCollect> {
+ unimplemented!()
+ }
+ fn build_dispatcher_not_found(_args: Vec<String>) -> mingling::AnyOutput<MockCollect> {
+ unimplemented!()
+ }
+ fn build_empty_result() -> mingling::AnyOutput<MockCollect> {
+ unimplemented!()
+ }
+ fn render(_any: mingling::AnyOutput<MockCollect>, _r: &mut RenderResult) {
+ unimplemented!()
+ }
+ fn render_help(_any: mingling::AnyOutput<MockCollect>, _r: &mut RenderResult) {
+ unimplemented!()
+ }
+ fn do_chain(_any: mingling::AnyOutput<MockCollect>) -> mingling::ChainProcess<MockCollect> {
+ unimplemented!()
+ }
+ fn do_comp(_any: &mingling::AnyOutput<MockCollect>, _ctx: &ShellContext) -> Suggest {
+ unimplemented!()
+ }
+ fn has_renderer(_any: &mingling::AnyOutput<MockCollect>) -> bool {
+ unimplemented!()
+ }
+ fn has_chain(_any: &mingling::AnyOutput<MockCollect>) -> bool {
+ unimplemented!()
+ }
+}
+
+#[test]
+fn test_shell_context_parsing_full() {
+ let args = vec![
+ "-f".to_string(),
+ "myapp hello ^world".to_string(),
+ "-C".to_string(),
+ "14".to_string(),
+ "-w".to_string(),
+ "hello".to_string(),
+ "-p".to_string(),
+ "myapp".to_string(),
+ "-c".to_string(),
+ "myapp".to_string(),
+ "-i".to_string(),
+ "1".to_string(),
+ "-F".to_string(),
+ "bash".to_string(),
+ ];
+ let ctx = ShellContext::try_from(args).unwrap();
+ assert_eq!(ctx.command_line, "myapp hello -world");
+ assert_eq!(ctx.cursor_position, 14);
+ assert_eq!(ctx.current_word, "hello");
+ assert_eq!(ctx.previous_word, "myapp");
+ assert_eq!(ctx.command_name, "myapp");
+ assert_eq!(ctx.word_index, 1);
+ assert!(matches!(ctx.shell_flag, ShellFlag::Bash));
+}
+
+#[test]
+fn test_shell_context_parsing_empty() {
+ let ctx = ShellContext::try_from(vec![]).unwrap();
+ assert!(ctx.all_words.is_empty());
+ assert!(matches!(ctx.shell_flag, ShellFlag::Other(_)));
+}
+
+#[test]
+fn test_suggest_from_vec() {
+ let s: Suggest = vec!["--help".to_string(), "--version".to_string()].into();
+ match &s {
+ Suggest::Suggest(items) => {
+ assert_eq!(items.len(), 2);
+ }
+ _ => panic!("expected Suggest::Suggest"),
+ }
+}
+
+#[test]
+fn test_suggest_item_new() {
+ let item = SuggestItem::new("hello".to_string());
+ assert_eq!(item.suggest(), "hello");
+ assert!(item.description().is_none());
+}
+
+#[test]
+fn test_suggest_item_with_description() {
+ let item = SuggestItem::new_with_desc("hello".to_string(), "a greeting".to_string());
+ assert_eq!(item.suggest(), "hello");
+ assert_eq!(item.description(), Some(&"a greeting".to_string()));
+}
+
+#[test]
+fn test_program_is_completing() {
+ let program: Program<MockCollect> = Program::new_with_args(["myapp", "__comp", "hello", ""]);
+ assert!(program.is_completing());
+}
+
+#[test]
+fn test_program_is_not_completing() {
+ let program: Program<MockCollect> = Program::new_with_args(["myapp", "hello"]);
+ assert!(!program.is_completing());
+}