OXYGENHUB

Coverage / src/cli/json.rs 100.0%

23 of 23 lines run, 35 of 46 functions · run #250 on main · run missed

1
//! Tiny JSON building for `--json` outputs: one document on stdout,
2
//! nothing else, with string escaping shared with the hooks payloads.
3
4
pub use oxy_core::repo::{json_array as arr, json_str as s};
5
685×
pub fn obj<I: IntoIterator<Item = (&'static str, String)>>(pairs: I) -> String {
785×
    let inner: Vec<String> = pairs
885×
        .into_iter()
9516×
        .map(|(k, v)| format!("{}:{v}", s(k)))
1085×
        .collect();
1185×
    format!("{{{}}}", inner.join(","))
1285×
}
1383×
pub fn b(v: bool) -> String {
1483×
    v.to_string()
1583×
}
1662×
pub fn n<T: std::fmt::Display>(v: T) -> String {
1762×
    v.to_string()
1862×
}
1941×
pub fn opt<T>(v: Option<T>, f: impl Fn(T) -> String) -> String {
2041×
    match v {
2112×
        Some(x) => f(x),
2229×
        None => "null".into(),
23
    }
2441×
}
2527×
pub fn hashes(v: &[oxy_core::hash::ChangeHash]) -> String {
2628×
    arr(v.iter().map(|h| s(&h.to_hex())))
2727×
}