From 4c1f4644eccb8dcc0446d08f6414d72732f8fa6d Mon Sep 17 00:00:00 2001 From: Kevin Amado Date: Wed, 9 Feb 2022 21:04:06 -0500 Subject: [PATCH] fix: pattern comments --- src/rules/pattern.rs | 7 ++--- tests/cases/pattern/in | 39 +++++++++++++++++++++++++ tests/cases/pattern/out | 64 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 105 insertions(+), 5 deletions(-) diff --git a/src/rules/pattern.rs b/src/rules/pattern.rs index c8c3879..dd17f35 100644 --- a/src/rules/pattern.rs +++ b/src/rules/pattern.rs @@ -92,11 +92,8 @@ pub fn rule( steps.push_back(crate::builder::Step::Pad); } - children.drain_comments_and_newlines(|element| match element { - crate::children::DrainCommentOrNewline::Comment(text) => { - steps.push_back(crate::builder::Step::Comment(text)); - } - crate::children::DrainCommentOrNewline::Newline(_) => {} + children.drain_comment(|text| { + steps.push_back(crate::builder::Step::Comment(text)); }); if let rnix::SyntaxKind::TOKEN_COMMA diff --git a/tests/cases/pattern/in b/tests/cases/pattern/in index 7afd85b..1c6b7a0 100644 --- a/tests/cases/pattern/in +++ b/tests/cases/pattern/in @@ -74,4 +74,43 @@ ({ a ? null }: _) ({ /*a*/ b /*a*/ ? /*a*/ null /*c*/ , /*d*/ e /*a*/ ? /*a*/ null /*f*/ , /*g*/ ... /*h*/ }: _) + + ({ + /*a*/ + # + b + /*a*/ + # + ? + /*a*/ + # + null + /*c*/ + # + , + /*d*/ + # + e + /*a*/ + # + ? + /*a*/ + # + null + /*f*/ + # + , + /*g*/ + # + ... + /*h*/ + # + } + /*i*/ + # + : + /*j*/ + # + _ + ) ] diff --git a/tests/cases/pattern/out b/tests/cases/pattern/out index a09a076..f60344d 100644 --- a/tests/cases/pattern/out +++ b/tests/cases/pattern/out @@ -1094,4 +1094,68 @@ }: _ ) + + ( + { + /* + a + */ + # + b + /* + a + */ + # + ? + /* + a + */ + # + null + /* + c + */ + # + , + /* + d + */ + # + e + /* + a + */ + # + ? + /* + a + */ + # + null + /* + f + */ + # + , + /* + g + */ + # + ... + /* + h + */ + # + } + /* + i + */ + # + : + /* + j + */ + # + _ + ) ]