diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-06-29 14:12:24 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-06-29 14:12:24 +0800 |
| commit | 2fa18e2190fb3c17892e13cb06d330e707dc05ec (patch) | |
| tree | 9a8a64565ee98a84c64c8677951df94bf3aa7176 /mingling_pathf/test/src | |
| parent | faae53e760743971c43800f6e6bc2fcbaec582b7 (diff) | |
feat(pathf): add dispatch tree config and pass feature to analyzer
Add `PathfinderConfig` struct to control dispatch tree extraction,
and wire `use_dispatch_tree` through `DispatcherPattern`,
`init_with_config`,
and `analyze_and_build_type_mapping_for`. Expose config and wrapper
from `mingling_core` under the `pathf` feature.
Diffstat (limited to 'mingling_pathf/test/src')
| -rw-r--r-- | mingling_pathf/test/src/lib.rs | 40 | ||||
| -rw-r--r-- | mingling_pathf/test/src/test_files/test_dispatcher_dispatch_tree.rs | 7 |
2 files changed, 47 insertions, 0 deletions
diff --git a/mingling_pathf/test/src/lib.rs b/mingling_pathf/test/src/lib.rs index 450316a..51e19a6 100644 --- a/mingling_pathf/test/src/lib.rs +++ b/mingling_pathf/test/src/lib.rs @@ -253,11 +253,17 @@ fn test_dispatcher_analyze() { let r = analyzer.analyze_file(file).unwrap(); let required: Vec<&str> = vec![ "::EntryGreet", + "::CMDGreet", "::EntryRemoteAdd", + "::CMDRemoteAdd", "::EntryDelete", + "::CMDDelete", "::EntryRemoteRm", + "::CMDRemoteRm", "::sub::EntryGreet", + "::sub::CMDGreet", "::sub::EntryDelete", + "::sub::CMDDelete", ]; assert_eq!(r.len(), required.len()); @@ -267,6 +273,40 @@ 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")); +} + +#[test] fn test_dispatcher_clap_analyze() { let analyzer = mingling_pathf::pattern_analyzer::init(); let file = current_dir() 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 new file mode 100644 index 0000000..ac321ca --- /dev/null +++ b/mingling_pathf/test/src/test_files/test_dispatcher_dispatch_tree.rs @@ -0,0 +1,7 @@ +mingling::macros::dispatcher!("greet", CMDGreet => EntryGreet); +dispatcher!("delete", CMDDelete => EntryDelete); + +pub mod sub { + mingling::macros::dispatcher!("greet", CMDGreet => EntryGreet); + dispatcher!("delete", CMDDelete => EntryDelete); +} |
