OXYGENHUB

Coverage / src/cli/json.rs 100.0%

23 of 23 lines run, 37 of 48 functions · run #411 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
6109×
pub fn obj<I: IntoIterator<Item = (&'static str, String)>>(pairs: I) -> String {
7109×
    let inner: Vec<String> = pairs
8109×
        .into_iter()
9686×
        .map(|(k, v)| format!("{}:{v}", s(k)))
10109×
        .collect();
11109×
    format!("{{{}}}", inner.join(","))
12109×
}
13102×
pub fn b(v: bool) -> String {
14102×
    v.to_string()
15102×
}
1678×
pub fn n<T: std::fmt::Display>(v: T) -> String {
1778×
    v.to_string()
1878×
}
1962×
pub fn opt<T>(v: Option<T>, f: impl Fn(T) -> String) -> String {
2062×
    match v {
2113×
        Some(x) => f(x),
2249×
        None => "null".into(),
23
    }
2462×
}
2537×
pub fn hashes(v: &[oxy_core::hash::ChangeHash]) -> String {
2639×
    arr(v.iter().map(|h| s(&h.to_hex())))
2737×
}