Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cli): include markdown documents with test --doc #11421

Merged
merged 21 commits into from
Jul 29, 2021

Conversation

caspervonb
Copy link
Contributor

@caspervonb caspervonb commented Jul 16, 2021

Closes #11170

cli/fs_util.rs Outdated Show resolved Hide resolved
@caspervonb caspervonb changed the title [WIP] feat(cli): include markdown documents with test --doc feat(cli): include markdown documents with test --doc Jul 16, 2021
cli/tools/test_runner.rs Outdated Show resolved Hide resolved
@bartlomieju bartlomieju added this to the 1.13.0 milestone Jul 20, 2021
Comment on lines 355 to 389
let parsed_module =
ast::parse(&file.specifier.as_str(), &file.source, &file.media_type)?;

let mut comments = parsed_module.get_comments();
comments.sort_by_key(|comment| {
let location = parsed_module.get_location(&comment.span);
location.line
});

let blocks_regex = Regex::new(r"```([^\n]*)\n([\S\s]*?)```")?;
let lines_regex = Regex::new(r"(?:\* ?)(?:\# ?)?(.*)")?;

for comment in comments {
if comment.kind != CommentKind::Block || !comment.text.starts_with('*') {
continue;
}

for block in blocks_regex.captures_iter(&comment.text) {
let maybe_attributes = block.get(1).map(|m| m.as_str().split(' '));
let media_type = if let Some(mut attributes) = maybe_attributes {
match attributes.next() {
Some("js") => MediaType::JavaScript,
Some("jsx") => MediaType::Jsx,
Some("ts") => MediaType::TypeScript,
Some("tsx") => MediaType::Tsx,
Some("") => file.media_type,
_ => MediaType::Unknown,
}
} else {
file.media_type
};

if media_type == MediaType::Unknown {
continue;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a lot of duplication in programs_from_fenced_blocks; could you extract some helpers?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've rewritten it to be less awful.

Copy link
Member

@bartlomieju bartlomieju left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@bartlomieju bartlomieju merged commit c276b52 into denoland:main Jul 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

deno test --doc should be able to typecheck Markdown files
2 participants