Add some tests for documentation gen

This commit is contained in:
Pablo Hirafuji 2020-10-25 20:08:43 -03:00
parent c982f968c2
commit 43f390d80c
5 changed files with 266 additions and 101 deletions

View file

@ -1,5 +1,3 @@
// This file was copied from file.rs and modified to expose information
// required to auto-generate documentation
use inlinable_string::InlinableString;
use roc_module::ident::ModuleName;
use roc_module::symbol::IdentIds;
@ -71,7 +69,7 @@ fn generate_module_doc<'a>(
// If there are comments before, attach to this definition
generate_module_doc(exposed_ident_ids, acc, before_comments_or_new_lines, sub_def);
// Comments after a definition are attached to the next defition
// Comments after a definition are attached to the next definition
(new_acc, Some(comments_or_new_lines))
}
@ -98,7 +96,11 @@ fn generate_module_doc<'a>(
name: _,
vars: _,
ann: _,
} => (acc, None),
} =>
// TODO
{
(acc, None)
}
Body(_, _) | Nested(_) => (acc, None),
}
@ -113,9 +115,16 @@ fn comments_or_new_lines_to_docs<'a>(
for comment_or_new_line in comments_or_new_lines.iter() {
match comment_or_new_line {
Newline => {}
LineComment(_) => {}
DocComment(doc_str) => docs.push_str(doc_str),
DocComment(doc_str) => {
docs.push_str(doc_str);
docs.push_str("\n");
}
// TODO: Lines with only `##` are not being parsed as a
// DocComment, but as a LineComment("#\r"). This pattern should cover this.
// The problem is that this is only valid if it is at the start
// of a line. False positive example: `x = 2 ##`.
LineComment("#\r") => docs.push_str("\n"),
Newline | LineComment(_) => {}
}
}
if docs.is_empty() {