aboutsummaryrefslogtreecommitdiff
path: root/mingling_pathf/test/src
diff options
context:
space:
mode:
Diffstat (limited to 'mingling_pathf/test/src')
-rw-r--r--mingling_pathf/test/src/lib.rs59
-rw-r--r--mingling_pathf/test/src/test_files/test_dispatcher_clap.rs40
-rw-r--r--mingling_pathf/test/src/test_files/test_groupped_derive.rs17
3 files changed, 116 insertions, 0 deletions
diff --git a/mingling_pathf/test/src/lib.rs b/mingling_pathf/test/src/lib.rs
index 51e19a6..824cbbf 100644
--- a/mingling_pathf/test/src/lib.rs
+++ b/mingling_pathf/test/src/lib.rs
@@ -233,8 +233,11 @@ fn test_groupped_derive_analyze() {
"::Derived1",
"::Derived2",
"::Derived3",
+ "::EnumDerived1",
+ "::EnumDerived2",
"::sub::Derived1",
"::sub::Derived3",
+ "::sub::EnumDerived1",
];
assert_eq!(r.len(), required.len());
@@ -315,12 +318,41 @@ fn test_dispatcher_clap_analyze() {
let r = analyzer.analyze_file(file).unwrap();
let required: Vec<&str> = vec![
+ // Root: entry types (bare dispatcher_clap, no params)
"::EntryClap1",
"::EntryClap2",
"::EntryClap3",
"::EntryClap4",
+ // Root: with CMD type
+ "::EntryWithCmd",
+ "::CMDGreet",
+ // Root: with CMD + error
+ "::EntryWithError",
+ "::CMDDelete",
+ "::ErrorDelete",
+ // Root: with CMD + help
+ "::EntryWithHelp",
+ "::CMDHelp",
+ "::__internal_help_cmdhelp_help",
+ // Root: with CMD + error + help
+ "::EntryFull",
+ "::CMDFull",
+ "::ErrorFull",
+ "::__internal_help_cmdfull_help",
+ // Sub: entry types (bare dispatcher_clap)
"::sub::EntryClap1",
"::sub::EntryClap3",
+ // Sub: with CMD type
+ "::sub::EntryWithCmd",
+ "::sub::CMDGreet",
+ // Sub: with CMD + error
+ "::sub::EntryWithError",
+ "::sub::CMDDelete",
+ "::sub::ErrorDelete",
+ // Sub: with CMD + help
+ "::sub::EntryWithHelp",
+ "::sub::CMDHelp",
+ "::sub::__internal_help_cmdhelp_help",
];
assert_eq!(r.len(), required.len());
@@ -328,3 +360,30 @@ fn test_dispatcher_clap_analyze() {
assert!(r.contains(*entry), "Result should contain: {}", entry);
}
}
+
+#[test]
+fn test_dispatcher_clap_dispatch_tree() {
+ use mingling_pathf::config::PathfinderConfig;
+ use mingling_pathf::pattern_analyzer;
+
+ let file = current_dir()
+ .unwrap()
+ .join("src/test_files/test_dispatcher_clap.rs");
+
+ // Without dispatch_tree: 26 items (same set as test_dispatcher_clap_analyze)
+ let r1 = pattern_analyzer::init().analyze_file(&file).unwrap();
+ assert_eq!(r1.len(), 26);
+
+ // With dispatch_tree: 26 + 4 __internal (root) + 3 __internal (sub, no "full") = 33
+ let r2 = pattern_analyzer::init_with_config(PathfinderConfig::with_dispatch_tree())
+ .analyze_file(&file)
+ .unwrap();
+ assert_eq!(r2.len(), 33);
+ assert!(r2.contains("::__internal_dispatcher_greet"));
+ assert!(r2.contains("::__internal_dispatcher_delete"));
+ assert!(r2.contains("::__internal_dispatcher_helpcmd"));
+ assert!(r2.contains("::__internal_dispatcher_full"));
+ assert!(r2.contains("::sub::__internal_dispatcher_greet"));
+ assert!(r2.contains("::sub::__internal_dispatcher_delete"));
+ assert!(r2.contains("::sub::__internal_dispatcher_helpcmd"));
+}
diff --git a/mingling_pathf/test/src/test_files/test_dispatcher_clap.rs b/mingling_pathf/test/src/test_files/test_dispatcher_clap.rs
index 0ba884d..33d86e0 100644
--- a/mingling_pathf/test/src/test_files/test_dispatcher_clap.rs
+++ b/mingling_pathf/test/src/test_files/test_dispatcher_clap.rs
@@ -1,3 +1,4 @@
+// Basic: entry type only (no CMD type specified)
#[mingling::macros::dispatcher_clap]
struct EntryClap1 {
name: String,
@@ -20,6 +21,30 @@ pub struct EntryClap4 {
value: i32,
}
+// With CMD type
+#[dispatcher_clap("greet", CMDGreet)]
+struct EntryWithCmd {
+ name: String,
+}
+
+// With CMD + error
+#[dispatcher_clap("delete", CMDDelete, error = ErrorDelete)]
+struct EntryWithError {
+ id: u64,
+}
+
+// With CMD + help
+#[dispatcher_clap("helpcmd", CMDHelp, help = true)]
+struct EntryWithHelp {
+ verbose: bool,
+}
+
+// With CMD + error + help
+#[dispatcher_clap("full", CMDFull, error = ErrorFull, help = true)]
+struct EntryFull {
+ all: bool,
+}
+
pub mod sub {
#[mingling::macros::dispatcher_clap]
struct EntryClap1 {
@@ -30,4 +55,19 @@ pub mod sub {
struct EntryClap3 {
value: String,
}
+
+ #[dispatcher_clap("greet", CMDGreet)]
+ struct EntryWithCmd {
+ name: String,
+ }
+
+ #[dispatcher_clap("delete", CMDDelete, error = ErrorDelete)]
+ struct EntryWithError {
+ id: u64,
+ }
+
+ #[dispatcher_clap("helpcmd", CMDHelp, help = true)]
+ struct EntryWithHelp {
+ verbose: bool,
+ }
}
diff --git a/mingling_pathf/test/src/test_files/test_groupped_derive.rs b/mingling_pathf/test/src/test_files/test_groupped_derive.rs
index f6c6fa9..913587c 100644
--- a/mingling_pathf/test/src/test_files/test_groupped_derive.rs
+++ b/mingling_pathf/test/src/test_files/test_groupped_derive.rs
@@ -13,6 +13,18 @@ struct Derived3 {
value: bool,
}
+#[derive(Groupped)]
+enum EnumDerived1 {
+ A,
+ B,
+}
+
+#[derive(GrouppedSerialize)]
+enum EnumDerived2 {
+ X(String),
+ Y(i32),
+}
+
pub mod sub {
#[derive(Groupped)]
struct Derived1 {
@@ -23,4 +35,9 @@ pub mod sub {
struct Derived3 {
value: bool,
}
+
+ #[derive(Groupped)]
+ enum EnumDerived1 {
+ A,
+ }
}