use simd_json::ValueType;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ConstDoc {
pub name: String,
pub doc: Option<String>,
pub value_type: ValueType,
}
impl ToString for ConstDoc {
fn to_string(&self) -> String {
format!(
r#"
### {}
*type*: {:?}
{}
"#,
self.name,
self.value_type,
&self.doc.clone().unwrap_or_default()
)
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct FnDoc {
pub name: String,
pub args: Vec<String>,
pub doc: Option<String>,
pub open: bool,
}
impl ToString for FnDoc {
fn to_string(&self) -> String {
format!(
r#"
### {}({})
{}
"#,
self.name,
self.args.join(", "),
self.doc.clone().unwrap_or_default()
)
}
}
#[derive(Debug, Clone, PartialEq, Serialize, Eq)]
pub struct ModDoc {
pub name: String,
pub doc: Option<String>,
}
impl ModDoc {
#[must_use]
pub fn print_with_name(&self, name: &str) -> String {
format!(
r#"
# {}
{}
"#,
name,
&self.doc.clone().unwrap_or_default()
)
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct QueryDoc {
pub name: String,
pub doc: Option<String>,
}
impl ToString for QueryDoc {
fn to_string(&self) -> String {
format!(
r#"
### {}
{}
"#,
self.name,
&self.doc.clone().unwrap_or_default()
)
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct FlowDoc {
pub name: String,
pub doc: Option<String>,
}
impl ToString for FlowDoc {
fn to_string(&self) -> String {
format!(
r#"
### {}
{}
"#,
self.name,
&self.doc.clone().unwrap_or_default()
)
}
}
#[derive(Debug, Clone, PartialEq, Default, Eq)]
pub struct Docs {
pub consts: Vec<ConstDoc>,
pub fns: Vec<FnDoc>,
pub queries: Vec<QueryDoc>,
pub flows: Vec<FlowDoc>,
pub module: Option<ModDoc>,
}
#[cfg(test)]
mod test {
use super::*;
#[test]
fn const_doc() {
let c = ConstDoc {
name: "const test".into(),
doc: Some("hello".into()),
value_type: ValueType::Null,
};
assert_eq!(
c.to_string(),
r#"
### const test
*type*: Null
hello
"#
);
}
#[test]
fn fn_doc() {
let c = FnDoc {
name: "fn_test".into(),
args: vec!["snot".into(), "badger".into()],
doc: Some("hello".into()),
open: false,
};
assert_eq!(
c.to_string(),
r#"
### fn_test(snot, badger)
hello
"#
);
}
#[test]
fn mod_doc() {
let c = ModDoc {
name: "test mod".into(),
doc: Some("hello".into()),
};
assert_eq!(
c.print_with_name(&c.name),
r#"
# test mod
hello
"#
);
}
#[test]
fn query_doc() {
let q = QueryDoc {
name: "test query".into(),
doc: Some("hello".into()),
};
assert_eq!(
q.to_string(),
r#"
### test query
hello
"#
);
}
}