diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-08-04 13:26:48 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-08-04 13:26:48 +0800 |
| commit | 4588e17f7ddacd8391a5c881a209735e08d48797 (patch) | |
| tree | 2b513f4d4f8a18ebd3a34cff7c0fb8abf5787321 /mingling_pathf/test/src | |
| parent | f7862affd74ac3b129f9e9791a4cd4e1c7e3e6d1 (diff) | |
feat: add entry metadata system with compile-time typed values
Add `Metadata<B>` trait and `#[metadata(Entry)]` attribute macro
to attach arbitrary, compile-time-typed metadata to entries.
Implement `ProgramCollect::get_metadata<T>()` for runtime retrieval,
backed by a global registry populated by `register_metadata!`.
Extend `pathf` with `MetadataPattern` to resolve metadata types
across modules at build time. Add two examples demonstrating
metadata usage with and without pathf integration.
Diffstat (limited to 'mingling_pathf/test/src')
| -rw-r--r-- | mingling_pathf/test/src/lib.rs | 33 | ||||
| -rw-r--r-- | mingling_pathf/test/src/test_files/test_metadata.rs | 40 |
2 files changed, 73 insertions, 0 deletions
diff --git a/mingling_pathf/test/src/lib.rs b/mingling_pathf/test/src/lib.rs index 7e7cbd5..8b13e52 100644 --- a/mingling_pathf/test/src/lib.rs +++ b/mingling_pathf/test/src/lib.rs @@ -387,3 +387,36 @@ fn test_dispatcher_clap_dispatch_tree() { assert!(r2.contains("::sub::__internal_dispatcher_delete")); assert!(r2.contains("::sub::__internal_dispatcher_helpcmd")); } + +#[test] +fn test_metadata_analyze() { + let analyzer = mingling_pathf::pattern_analyzer::init(); + let file = current_dir() + .unwrap() + .join("src/test_files/test_metadata.rs"); + + let r = analyzer.analyze_file(file).unwrap(); + let required: Vec<&str> = vec![ + // Root: BindType + DataType pairs + "::EntryGreet1", + "::Description1", + "::EntryGreet2", + "::Description2", + "::EntryGreet3", + "::LocalType3", + "::EntryGreet4", + "::std::collections::HashMap", + "::EntryGreet5", + "::Qualified5", + // Sub: BindType + DataType pairs + "::sub::EntrySub1", + "::sub::SubType1", + "::sub::EntrySub2", + "::sub::SubType2", + ]; + + assert_eq!(r.len(), required.len()); + for entry in &required { + assert!(r.contains(*entry), "Result should contain: {entry}"); + } +} diff --git a/mingling_pathf/test/src/test_files/test_metadata.rs b/mingling_pathf/test/src/test_files/test_metadata.rs new file mode 100644 index 0000000..52a2d4c --- /dev/null +++ b/mingling_pathf/test/src/test_files/test_metadata.rs @@ -0,0 +1,40 @@ +// Root-level metadata functions +#[mingling::macros::metadata(EntryGreet1)] +pub fn get_desc1() -> Description1 { + Description1 {} +} + +#[metadata(EntryGreet2)] +fn get_desc2() -> Description2 { + Description2 {} +} + +// Local DataType (defined in-crate) + foreign DataType +#[metadata(EntryGreet3)] +pub fn get_desc3() -> LocalType3 { + LocalType3 {} +} + +use std::collections::HashMap; + +#[metadata(EntryGreet4)] +fn get_desc4() -> HashMap<String, String> { + HashMap::new() +} + +#[metadata(EntryGreet5)] +pub fn get_desc5() -> crate::fully::Qualified5 { + crate::fully::Qualified5 {} +} + +pub mod sub { + #[mingling::macros::metadata(EntrySub1)] + pub fn get_sub1() -> SubType1 { + SubType1 {} + } + + #[metadata(EntrySub2)] + fn get_sub2() -> SubType2 { + SubType2 {} + } +} |
