-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
feat(cli): include markdown documents with test --doc #11421
Conversation
…nb/deno into feat-cli-support-markdown-tests
…nb/deno into feat-cli-support-markdown-tests
cli/tools/test_runner.rs
Outdated
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; | ||
} |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Closes #11170