use std::{path::Path, sync::Arc};
use serde::{Deserialize, Serialize};
use typed_builder::TypedBuilder;
use crate::{
diagnostic::Diagnostic,
ir::{Component, Edge, Environment, Module},
};
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, TypedBuilder)]
#[non_exhaustive]
#[serde(rename_all = "camelCase")]
#[builder(field_defaults(setter(into)))]
pub struct Workspace {
#[serde(with = "crate::ir::path_serde::arc_path")]
pub root: Arc<Path>,
#[builder(default)]
pub components: Vec<Component>,
#[builder(default)]
pub modules: Vec<Module>,
#[builder(default)]
pub environments: Vec<Environment>,
#[builder(default)]
pub diagnostics: Vec<Diagnostic>,
#[builder(default)]
pub edges: Vec<Edge>,
}
#[cfg(test)]
#[allow(clippy::unwrap_used)]
mod tests {
use std::path::PathBuf;
use super::*;
#[test]
fn test_should_build_minimal_workspace() {
let w = Workspace::builder()
.root(Arc::<Path>::from(PathBuf::from("/tmp/repo")))
.build();
assert!(w.components.is_empty());
assert!(w.modules.is_empty());
assert!(w.environments.is_empty());
assert!(w.diagnostics.is_empty());
}
#[test]
fn test_should_serde_round_trip_workspace() {
let w = Workspace::builder()
.root(Arc::<Path>::from(PathBuf::from("/tmp/repo")))
.build();
let json = serde_json::to_string(&w).unwrap();
let back: Workspace = serde_json::from_str(&json).unwrap();
assert_eq!(w, back);
}
}