paste icon indicating copy to clipboard operation
paste copied to clipboard

Snake case preserving `/` (slash) characters

Open brownjohnf opened this issue 1 year ago • 1 comments

I'm attempting to use $expr:snake with a path containing slashes. My use-case is for automating tests, where test fixtures are in a hierarchical structure, and I'm auto-generating test modules based on the path I want to test:

mymacro!("some/file/path");

// I'd like this to expand to:
mod test_mymacro_some_file_path {..}

When using something like:

[< test_mymacro_ $expr:snake >]

it preserves the slash. I'm not sure what the expected/desired behavior is here; I see that the source explicitly only checks for case, not symbols, etc. Is there a way to achieve this with paste, or should I be doing something else, like using a $(path:ident)/+ pattern or something in my macro? I'm relatively new to writing macros, so apologies if I'm missing something obvious. This crate has been amazing for creating a robust test suite.

brownjohnf avatar Aug 17 '23 16:08 brownjohnf

I have the same problem now: needing to convert a path string to a valid Rust identifier.

ThinkerDreamer avatar May 28 '24 15:05 ThinkerDreamer