orchestrator_collab/
lib.rs1#![cfg_attr(
7 not(test),
8 deny(clippy::panic, clippy::unwrap_used, clippy::expect_used)
9)]
10#![deny(missing_docs)]
11
12pub mod artifact;
14pub mod context;
16pub mod dag;
18pub mod output;
20
21pub use artifact::*;
22pub use context::*;
23pub use dag::*;
24pub use output::*;
25
26pub(crate) fn escape_for_bash_dquote(s: &str) -> String {
32 let mut out = String::with_capacity(s.len() + s.len() / 8);
33 for ch in s.chars() {
34 match ch {
35 '\\' => out.push_str("\\\\"),
36 '$' => out.push_str("\\$"),
37 '`' => out.push_str("\\`"),
38 '"' => out.push_str("\\\""),
39 '!' => out.push_str("\\!"),
40 _ => out.push(ch),
41 }
42 }
43 out
44}
45
46#[cfg(test)]
47mod tests {
48 use super::*;
49
50 #[test]
51 fn test_escape_for_bash_dquote() {
52 assert_eq!(escape_for_bash_dquote("`resource.rs`"), "\\`resource.rs\\`");
53 assert_eq!(escape_for_bash_dquote("$HOME"), "\\$HOME");
54 assert_eq!(escape_for_bash_dquote(r#"say "hello""#), r#"say \"hello\""#);
55 assert_eq!(escape_for_bash_dquote(r"path\to"), r"path\\to");
56 assert_eq!(escape_for_bash_dquote("wow!"), "wow\\!");
57 assert_eq!(escape_for_bash_dquote("hello world"), "hello world");
58
59 let plan = "| `mod.rs` | ~200 | Core types, `pub(super)` |\n| $cost | ~$5 |";
60 let escaped = escape_for_bash_dquote(plan);
61 assert!(escaped.contains("\\`mod.rs\\`"));
62 assert!(escaped.contains("\\`pub(super)\\`"));
63 assert!(escaped.contains("\\$cost"));
64 assert!(escaped.contains("\\$5"));
65 assert!(!escaped.contains(" `m"));
66 }
67}