1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
use crate::{Cons, Dart, FormatTokens, Tokens};
pub struct DocComment<'el>(pub Vec<Cons<'el>>);
impl<'el> FormatTokens<'el, Dart> for DocComment<'el> {
fn format_tokens(self, tokens: &mut Tokens<'el, Dart>) {
if self.0.is_empty() {
return;
}
for line in self.0 {
tokens.push("/// ");
tokens.append(line);
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_doc_comment() {
let toks = toks![
DocComment(vec![Cons::from("Foo")]),
DocComment(vec![]),
DocComment(vec![]),
DocComment(vec![]),
DocComment(vec![Cons::from("Bar")]),
];
let expected = vec!["/// Foo", "/// Bar", ""];
assert_eq!(
Ok(expected.join("\n").as_str()),
toks.to_file_string().as_ref().map(|s| s.as_str())
);
}
}