yaml_subset/
utils.rs

1pub fn indent(amount: usize) -> String {
2    (0..amount).map(|_| " ").collect::<Vec<_>>().join("")
3}
4
5fn should_write_literal(s: &String) -> bool {
6    s.contains("\n") || s.contains("\\") // TODO
7}
8
9fn needs_quotes(s: &String) -> bool {
10    s.is_empty() || s.contains(": ") || s.contains(" #")
11}
12
13mod tests {
14
15    #[test]
16    fn indent() {
17        assert_eq!(super::indent(1), " ".to_string());
18        assert_eq!(super::indent(2), "  ".to_string());
19        assert_eq!(super::indent(3), "   ".to_string());
20        assert_eq!(super::indent(4), "    ".to_string());
21        assert_eq!(super::indent(5), "     ".to_string());
22        assert_eq!(super::indent(6), "      ".to_string());
23        assert_eq!(super::indent(7), "       ".to_string());
24        assert_eq!(super::indent(8), "        ".to_string());
25    }
26}