use serde::{Deserialize, Serialize};
use std::path::PathBuf;
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
#[non_exhaustive]
pub struct BacktraceGraph {
pub nodes: Vec<Node>,
pub commands: Vec<String>,
pub files: Vec<PathBuf>,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
#[non_exhaustive]
pub struct Node {
pub file: usize,
pub line: Option<usize>,
pub command: Option<usize>,
pub parent: Option<usize>,
}
#[cfg(test)]
mod tests {
use crate::objects::codemodel_v2::backtrace_graph::*;
use serde_json::json;
#[test]
fn test_backtrace_graph() {
let json = json!({
"commands" :
[
"add_executable",
"target_link_libraries"
],
"files" :
[
"CMakeLists.txt"
],
"nodes" :
[
{
"file" : 0
},
{
"command" : 0,
"file" : 0,
"line" : 4,
"parent" : 0
},
{
"command" : 1,
"file" : 0,
"line" : 9,
"parent" : 0
}
]
});
let graph = serde_json::from_value::<BacktraceGraph>(json).unwrap();
assert_eq!(
graph,
BacktraceGraph {
commands: vec![
"add_executable".to_string(),
"target_link_libraries".to_string()
],
files: vec![PathBuf::from("CMakeLists.txt")],
nodes: vec![
Node {
file: 0,
..Default::default()
},
Node {
file: 0,
command: Some(0),
line: Some(4),
parent: Some(0)
},
Node {
file: 0,
command: Some(1),
line: Some(9),
parent: Some(0)
}
]
}
);
}
}