isoloom_render/
powershell.rs1pub const UNTAR: &str = include_str!("powershell/untar.ps1");
7
8#[must_use]
12pub fn quote(s: &str) -> String {
13 let mut out = String::with_capacity(s.len() + 2);
14 out.push('\'');
15 for c in s.chars() {
16 if is_quote(c) {
17 out.push(c);
18 }
19 out.push(c);
20 }
21 out.push('\'');
22 out
23}
24
25fn is_quote(c: char) -> bool {
27 matches!(c, '\'' | '\u{2018}' | '\u{2019}' | '\u{201A}' | '\u{201B}')
28}
29
30#[cfg(test)]
31mod tests {
32 use super::{UNTAR, quote};
33
34 #[test]
35 fn every_kind_of_single_quote_is_doubled() {
36 assert_eq!(quote("it's"), "'it''s'");
37 assert_eq!(
38 quote("a\u{2018}b\u{2019}c\u{201A}d\u{201B}e"),
39 "'a\u{2018}\u{2018}b\u{2019}\u{2019}c\u{201A}\u{201A}d\u{201B}\u{201B}e'"
40 );
41 assert_eq!(quote("$x `n \""), "'$x `n \"'");
42 }
43
44 #[test]
45 fn the_untar_script_reads_the_archive_it_is_given() {
46 assert!(UNTAR.contains("$archive") && UNTAR.contains("$dest") && UNTAR.contains("$strip"));
47 }
48}