From 81fae4cab66cee4da8a4ff478a84e996d6eb7f5f Mon Sep 17 00:00:00 2001 From: mhead Date: Wed, 10 Jul 2024 14:48:46 +0530 Subject: [PATCH] added test, added doc --- src/uucore/src/lib/features/quoting_style.rs | 35 ++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/uucore/src/lib/features/quoting_style.rs b/src/uucore/src/lib/features/quoting_style.rs index e6531474076..1be5238a42a 100644 --- a/src/uucore/src/lib/features/quoting_style.rs +++ b/src/uucore/src/lib/features/quoting_style.rs @@ -123,6 +123,13 @@ impl EscapedChar { } } + /// Create a new c shell styled `EscapedChar` + /// + /// # Arguments + /// * `c` - The character to create the `EscapedChar` for. + /// * `quotes` - The type of quotes to use for escaping. + /// * `force_escape` - A list of extra characters that should be treated as + /// escaped characters for a specific context. fn new_c(c: char, quotes: Quotes, force_escape: &[char]) -> Self { use EscapeState::*; let init_state = match c { @@ -853,6 +860,34 @@ mod tests { ], &[':'], ); + check_names( + "one:two:three", + &[ + ("one:two:three", "literal"), + ("'one:two:three'", "shell"), + ("'one:two:three'", "shell-always"), + ("'one:two:three'", "shell-escape"), + ("'one:two:three'", "shell-escape-always"), + ("\"one\\:two\\:three\"", "c"), + ("one\\:two\\:three", "escape"), + ], + &[':'], + ); + // note: this is just to check multiple escaped chars are working + // properly no util has this behavior. + check_names( + "one:two@three", + &[ + ("one:two@three", "literal"), + ("'one:two@three'", "shell"), + ("'one:two@three'", "shell-always"), + ("'one:two@three'", "shell-escape"), + ("'one:two@three'", "shell-escape-always"), + ("\"one\\:two\\@three\"", "c"), + ("one\\:two\\@three", "escape"), + ], + &[':', '@'], + ); } #[test]