Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

Commit

Permalink
Add tests for is_doc_comment
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaReiser committed Aug 30, 2022
1 parent a8f3bce commit d89d467
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 15 deletions.
46 changes: 32 additions & 14 deletions crates/rome_js_formatter/src/comments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,30 +56,48 @@ impl FormatRule<SourceComment<JsLanguage>> for FormatJsLeadingComment {
///
/// # Examples
///
/// ## Doc Comments
/// ```
/// # use rome_js_parser::parse_module;
/// # use rome_js_syntax::JsLanguage;
/// # use rome_rowan::{Direction, SyntaxTriviaPieceComments};
/// use rome_js_formatter::comments::is_doc_comment;
///
/// ```javascript
/// /**
/// * Multiline doc comment
/// */
/// # fn parse_comment(source: &str) -> SyntaxTriviaPieceComments<JsLanguage> {
/// # let root = parse_module(source, 0).tree();
/// # root
/// # .eof_token()
/// # .expect("Root to have an EOF token")
/// # .leading_trivia()
/// # .pieces()
/// # .filter_map(|piece| piece.as_comments())
/// # .next()
/// # .expect("Source to contain a comment.")
/// # }
///
/// /*
/// * With single star
/// */
/// ```
/// assert!(is_doc_comment(&parse_comment(r#"
/// /**
/// * Multiline doc comment
/// */
/// "#)));
///
/// ## Non Doc Comments
/// assert!(is_doc_comment(&parse_comment(r#"
/// /*
/// * Single star
/// */
/// "#)));
///
/// ```javascript
/// /** has no line break */
///
/// // Non doc-comments
/// assert!(!is_doc_comment(&parse_comment(r#"/** has no line break */"#)));
///
/// assert!(!is_doc_comment(&parse_comment(r#"
/// /*
/// *
/// this line doesn't start with a star
/// */
/// "#)));
/// ```
///
fn is_doc_comment(comment: &SyntaxTriviaPieceComments<JsLanguage>) -> bool {
pub fn is_doc_comment(comment: &SyntaxTriviaPieceComments<JsLanguage>) -> bool {
if !comment.has_newline() {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion crates/rome_js_formatter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ mod check_reformat;
#[rustfmt::skip]
mod generated;
pub(crate) mod builders;
mod comments;
pub mod comments;
pub mod context;
mod parentheses;
pub(crate) mod separated;
Expand Down

0 comments on commit d89d467

Please sign in to comment.