aboutsummaryrefslogtreecommitdiff
path: root/mingling_pathf/test
diff options
context:
space:
mode:
Diffstat (limited to 'mingling_pathf/test')
-rw-r--r--mingling_pathf/test/Cargo.lock2
-rw-r--r--mingling_pathf/test/src/lib.rs164
-rw-r--r--mingling_pathf/test/src/test_files/test_dispatcher.rs12
-rw-r--r--mingling_pathf/test/src/test_files/test_dispatcher_clap.rs14
-rw-r--r--mingling_pathf/test/src/test_files/test_dispatcher_dispatch_tree.rs8
-rw-r--r--mingling_pathf/test/src/test_files/test_pack.rs17
6 files changed, 91 insertions, 126 deletions
diff --git a/mingling_pathf/test/Cargo.lock b/mingling_pathf/test/Cargo.lock
index e7de689..58c7c9a 100644
--- a/mingling_pathf/test/Cargo.lock
+++ b/mingling_pathf/test/Cargo.lock
@@ -16,7 +16,7 @@ checksum = "6170dccbc3ea15dfb7f2da964097f814aba1dd8f746d4ffc56f33245c38e6d96"
[[package]]
name = "mingling_pathf"
-version = "0.4.0"
+version = "0.5.0"
dependencies = [
"just_fmt 0.2.0",
"proc-macro2",
diff --git a/mingling_pathf/test/src/lib.rs b/mingling_pathf/test/src/lib.rs
index 95d7410..22e1cc2 100644
--- a/mingling_pathf/test/src/lib.rs
+++ b/mingling_pathf/test/src/lib.rs
@@ -174,33 +174,6 @@ fn test_completion_analyze() {
}
#[test]
-fn test_pack_analyze() {
- let analyzer = mingling_pathf::pattern_analyzer::init();
- let file = current_dir().unwrap().join("src/test_files/test_pack.rs");
-
- let r = analyzer.analyze_file(file).unwrap();
- let required: Vec<&str> = vec![
- "::ResultPack1",
- "::ErrorPack1",
- "::ErrorPack2",
- "::ResultPack2",
- "::ErrorPack3",
- "::ErrorPack4",
- "::sub::ResultPack1",
- "::sub::ErrorPack1",
- "::sub::ErrorPack2",
- "::sub::ResultPack2",
- "::sub::ErrorPack3",
- "::sub::ErrorPack4",
- ];
-
- assert_eq!(r.len(), required.len());
- for entry in &required {
- assert!(r.contains(*entry), "Result should contain: {}", entry);
- }
-}
-
-#[test]
fn test_group_analyze() {
let analyzer = mingling_pathf::pattern_analyzer::init();
let file = current_dir().unwrap().join("src/test_files/test_group.rs");
@@ -258,17 +231,24 @@ fn test_dispatcher_analyze() {
let r = analyzer.analyze_file(file).unwrap();
let required: Vec<&str> = vec![
"::EntryGreet",
- "::CMDGreet",
+ "::__DispatcherGreet",
"::EntryRemoteAdd",
- "::CMDRemoteAdd",
+ "::__DispatcherRemoteAdd",
"::EntryDelete",
- "::CMDDelete",
+ "::__DispatcherDelete",
"::EntryRemoteRm",
- "::CMDRemoteRm",
+ "::__DispatcherRemoteRm",
"::sub::EntryGreet",
- "::sub::CMDGreet",
+ "::sub::__DispatcherGreet",
"::sub::EntryDelete",
- "::sub::CMDDelete",
+ "::sub::__DispatcherDelete",
+ // Dispatchers are always collected at compile time:
+ "::__internal_dispatcher_greet",
+ "::__internal_dispatcher_remote_add",
+ "::__internal_dispatcher_delete",
+ "::__internal_dispatcher_remote_rm",
+ "::sub::__internal_dispatcher_greet",
+ "::sub::__internal_dispatcher_delete",
];
assert_eq!(r.len(), required.len());
@@ -279,36 +259,29 @@ fn test_dispatcher_analyze() {
#[test]
fn test_dispatcher_dispatch_tree() {
- use mingling_pathf::config::PathfinderConfig;
use mingling_pathf::pattern_analyzer;
let file = current_dir()
.unwrap()
.join("src/test_files/test_dispatcher_dispatch_tree.rs");
- // Without dispatch_tree: only Entry + CMD types
- let r1 = pattern_analyzer::init().analyze_file(&file).unwrap();
- // 4 root (EntryGreet, CMDGreet, EntryDelete, CMDDelete)
- // + 4 sub (sub::EntryGreet, sub::CMDGreet, sub::EntryDelete, sub::CMDDelete)
- // = 8
- assert_eq!(r1.len(), 8);
- assert!(r1.contains("::EntryGreet"));
- assert!(r1.contains("::CMDGreet"));
- assert!(r1.contains("::EntryDelete"));
- assert!(r1.contains("::CMDDelete"));
- assert!(r1.contains("::sub::EntryGreet"));
- assert!(r1.contains("::sub::CMDGreet"));
-
- // With dispatch_tree: Entry + CMD + __internal_dispatcher
- let r2 = pattern_analyzer::init_with_config(&PathfinderConfig::with_dispatch_tree())
- .analyze_file(&file)
- .unwrap();
- // 8 (from above) + 2 __internal (root) + 2 __internal (sub) = 12
- assert_eq!(r2.len(), 12);
- assert!(r2.contains("::__internal_dispatcher_greet"));
- assert!(r2.contains("::__internal_dispatcher_delete"));
- assert!(r2.contains("::sub::__internal_dispatcher_greet"));
- assert!(r2.contains("::sub::__internal_dispatcher_delete"));
+ // Dispatchers are always collected at compile time, so the analyzer
+ // always extracts the hidden dispatcher structs and statics too:
+ // 8 (Entry + __Dispatcher, root + sub) + 4 __internal (root + sub) = 12
+ let r = pattern_analyzer::init().analyze_file(&file).unwrap();
+ assert_eq!(r.len(), 12);
+ assert!(r.contains("::EntryGreet"));
+ assert!(r.contains("::__DispatcherGreet"));
+ assert!(r.contains("::EntryDelete"));
+ assert!(r.contains("::__DispatcherDelete"));
+ assert!(r.contains("::sub::EntryGreet"));
+ assert!(r.contains("::sub::__DispatcherGreet"));
+ assert!(r.contains("::sub::EntryDelete"));
+ assert!(r.contains("::sub::__DispatcherDelete"));
+ assert!(r.contains("::__internal_dispatcher_greet"));
+ assert!(r.contains("::__internal_dispatcher_delete"));
+ assert!(r.contains("::sub::__internal_dispatcher_greet"));
+ assert!(r.contains("::sub::__internal_dispatcher_delete"));
}
#[test]
@@ -325,36 +298,44 @@ fn test_dispatcher_clap_analyze() {
"::EntryClap2",
"::EntryClap3",
"::EntryClap4",
- // Root: with CMD type
+ // Root: with command name only
"::EntryWithCmd",
- "::CMDGreet",
- // Root: with CMD + error
+ // Root: with error
"::EntryWithError",
- "::CMDDelete",
"::ErrorDelete",
- // Root: with CMD + help
+ // Root: with help
"::EntryWithHelp",
- "::CMDHelp",
- "::__internal_help_cmdhelp_help",
- // Root: with CMD + error + help
+ "::__internal_help_helpcmd_help",
+ // Root: with error + help
"::EntryFull",
- "::CMDFull",
"::ErrorFull",
- "::__internal_help_cmdfull_help",
+ "::__internal_help_full_help",
// Sub: entry types (bare dispatcher_clap)
"::sub::EntryClap1",
"::sub::EntryClap3",
- // Sub: with CMD type
+ // Sub: with command name only
"::sub::EntryWithCmd",
- "::sub::CMDGreet",
- // Sub: with CMD + error
+ // Sub: with error
"::sub::EntryWithError",
- "::sub::CMDDelete",
"::sub::ErrorDelete",
- // Sub: with CMD + help
+ // Sub: with help
"::sub::EntryWithHelp",
- "::sub::CMDHelp",
- "::sub::__internal_help_cmdhelp_help",
+ "::sub::__internal_help_helpcmd_help",
+ // Hidden dispatcher structs + statics are always collected:
+ "::__DispatcherGreet",
+ "::__internal_dispatcher_greet",
+ "::__DispatcherDelete",
+ "::__internal_dispatcher_delete",
+ "::__DispatcherHelpcmd",
+ "::__internal_dispatcher_helpcmd",
+ "::__DispatcherFull",
+ "::__internal_dispatcher_full",
+ "::sub::__DispatcherGreet",
+ "::sub::__internal_dispatcher_greet",
+ "::sub::__DispatcherDelete",
+ "::sub::__internal_dispatcher_delete",
+ "::sub::__DispatcherHelpcmd",
+ "::sub::__internal_dispatcher_helpcmd",
];
assert_eq!(r.len(), required.len());
@@ -365,29 +346,30 @@ fn test_dispatcher_clap_analyze() {
#[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"));
+ // Dispatchers are always collected at compile time:
+ // 19 (entry/error/help items) + 14 (hidden structs + statics, root + sub) = 33
+ let r = pattern_analyzer::init().analyze_file(&file).unwrap();
+ assert_eq!(r.len(), 33);
+ assert!(r.contains("::__DispatcherGreet"));
+ assert!(r.contains("::__internal_dispatcher_greet"));
+ assert!(r.contains("::__DispatcherDelete"));
+ assert!(r.contains("::__internal_dispatcher_delete"));
+ assert!(r.contains("::__DispatcherHelpcmd"));
+ assert!(r.contains("::__internal_dispatcher_helpcmd"));
+ assert!(r.contains("::__DispatcherFull"));
+ assert!(r.contains("::__internal_dispatcher_full"));
+ assert!(r.contains("::sub::__DispatcherGreet"));
+ assert!(r.contains("::sub::__internal_dispatcher_greet"));
+ assert!(r.contains("::sub::__DispatcherDelete"));
+ assert!(r.contains("::sub::__internal_dispatcher_delete"));
+ assert!(r.contains("::sub::__DispatcherHelpcmd"));
+ assert!(r.contains("::sub::__internal_dispatcher_helpcmd"));
}
#[test]
diff --git a/mingling_pathf/test/src/test_files/test_dispatcher.rs b/mingling_pathf/test/src/test_files/test_dispatcher.rs
index 48f5e4d..66e6a74 100644
--- a/mingling_pathf/test/src/test_files/test_dispatcher.rs
+++ b/mingling_pathf/test/src/test_files/test_dispatcher.rs
@@ -1,17 +1,17 @@
-mingling::macros::dispatcher!("greet", CMDGreet => EntryGreet);
+mingling::macros::dispatcher!("greet", EntryGreet);
mingling::macros::dispatcher!("greet");
-mingling::macros::dispatcher!("remote.add", CMDRemoteAdd => EntryRemoteAdd);
+mingling::macros::dispatcher!("remote.add", EntryRemoteAdd);
mingling::macros::dispatcher!("remote.add");
-dispatcher!("delete", CMDDelete => EntryDelete);
+dispatcher!("delete", EntryDelete);
dispatcher!("delete");
-dispatcher!("remote.rm", CMDRemoteRm => EntryRemoteRm);
+dispatcher!("remote.rm", EntryRemoteRm);
dispatcher!("remote.rm");
pub mod sub {
- mingling::macros::dispatcher!("greet", CMDGreet => EntryGreet);
+ mingling::macros::dispatcher!("greet", EntryGreet);
mingling::macros::dispatcher!("greet");
- dispatcher!("delete", CMDDelete => EntryDelete);
+ dispatcher!("delete", EntryDelete);
dispatcher!("delete");
}
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 33d86e0..c1d5ef0 100644
--- a/mingling_pathf/test/src/test_files/test_dispatcher_clap.rs
+++ b/mingling_pathf/test/src/test_files/test_dispatcher_clap.rs
@@ -22,25 +22,25 @@ pub struct EntryClap4 {
}
// With CMD type
-#[dispatcher_clap("greet", CMDGreet)]
+#[dispatcher_clap("greet", )]
struct EntryWithCmd {
name: String,
}
// With CMD + error
-#[dispatcher_clap("delete", CMDDelete, error = ErrorDelete)]
+#[dispatcher_clap("delete", error = ErrorDelete)]
struct EntryWithError {
id: u64,
}
// With CMD + help
-#[dispatcher_clap("helpcmd", CMDHelp, help = true)]
+#[dispatcher_clap("helpcmd", help = true)]
struct EntryWithHelp {
verbose: bool,
}
// With CMD + error + help
-#[dispatcher_clap("full", CMDFull, error = ErrorFull, help = true)]
+#[dispatcher_clap("full", error = ErrorFull, help = true)]
struct EntryFull {
all: bool,
}
@@ -56,17 +56,17 @@ pub mod sub {
value: String,
}
- #[dispatcher_clap("greet", CMDGreet)]
+ #[dispatcher_clap("greet", )]
struct EntryWithCmd {
name: String,
}
- #[dispatcher_clap("delete", CMDDelete, error = ErrorDelete)]
+ #[dispatcher_clap("delete", error = ErrorDelete)]
struct EntryWithError {
id: u64,
}
- #[dispatcher_clap("helpcmd", CMDHelp, help = true)]
+ #[dispatcher_clap("helpcmd", help = true)]
struct EntryWithHelp {
verbose: bool,
}
diff --git a/mingling_pathf/test/src/test_files/test_dispatcher_dispatch_tree.rs b/mingling_pathf/test/src/test_files/test_dispatcher_dispatch_tree.rs
index ac321ca..e319242 100644
--- a/mingling_pathf/test/src/test_files/test_dispatcher_dispatch_tree.rs
+++ b/mingling_pathf/test/src/test_files/test_dispatcher_dispatch_tree.rs
@@ -1,7 +1,7 @@
-mingling::macros::dispatcher!("greet", CMDGreet => EntryGreet);
-dispatcher!("delete", CMDDelete => EntryDelete);
+mingling::macros::dispatcher!("greet", EntryGreet);
+dispatcher!("delete", EntryDelete);
pub mod sub {
- mingling::macros::dispatcher!("greet", CMDGreet => EntryGreet);
- dispatcher!("delete", CMDDelete => EntryDelete);
+ mingling::macros::dispatcher!("greet", EntryGreet);
+ dispatcher!("delete", EntryDelete);
}
diff --git a/mingling_pathf/test/src/test_files/test_pack.rs b/mingling_pathf/test/src/test_files/test_pack.rs
deleted file mode 100644
index 759e35f..0000000
--- a/mingling_pathf/test/src/test_files/test_pack.rs
+++ /dev/null
@@ -1,17 +0,0 @@
-mingling::macros::pack!(ResultPack1 = String);
-mingling::macros::pack_err!(ErrorPack1);
-mingling::macros::pack_err!(ErrorPack2 = PathBuf);
-
-pack!(ResultPack2 = (u8, String));
-pack_err!(ErrorPack3);
-pack_err!(ErrorPack4 = PathBuf);
-
-pub mod sub {
- mingling::macros::pack!(ResultPack1 = String);
- mingling::macros::pack_err!(ErrorPack1);
- mingling::macros::pack_err!(ErrorPack2 = PathBuf);
-
- pack!(ResultPack2 = (u8, String));
- pack_err!(ErrorPack3);
- pack_err!(ErrorPack4 = PathBuf);
-}