From 351d59076f58780b5e84b78e2285bf4f373bc692 Mon Sep 17 00:00:00 2001 From: faizaan Date: Sat, 28 Nov 2026 21:19:03 +0530 Subject: [PATCH] Fix pud fmt continuation indentation for character literals (fixes #11) --- CHANGELOG.md | 1 + src/tools.rs | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 52b88ac..108e04e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ All notable changes to Puddi are recorded here. The format follows [Keep a Chang ### Fixed +- `pud fmt` preserves continuation indentation when a line contains a character literal. - `pud doc` preserves paragraph breaks in module documentation. - Integer literals too large for the compiler's integer representation report an error instead of wrapping. - List pattern exhaustiveness accounts for the exact lengths covered by rest patterns. diff --git a/src/tools.rs b/src/tools.rs index bebac68..00d238d 100644 --- a/src/tools.rs +++ b/src/tools.rs @@ -123,6 +123,18 @@ mod tests { assert_eq!(super::format(source), source); } + #[test] + fn format_handles_continuation_with_char_literal() { + let source = "fn is_quote(c: Char) -> Bool {\n c == '\"' || // quote check\n c == '\\''\n}\n"; + assert_eq!(super::format(source), source); + } + + #[test] + fn format_char_literal_comment_does_not_trigger_continuation() { + let source = "fn main() {\n let c = '\"' // check +\n let next = 1\n}\n"; + assert_eq!(super::format(source), source); + } + #[test] fn doc_preserves_module_paragraphs() { let source = "// First paragraph.\n// More detail.\n//\n// Second paragraph.\npub fn example() {}\n"; @@ -257,6 +269,19 @@ fn strip_line_comment(line: &str) -> &str { match b[i] { b'\\' if in_str => i += 1, b'"' => in_str = !in_str, + b'\'' if !in_str => { + let mut j = i + 1; + if b.get(j) == Some(&b'\\') { + j += 2; + } else { + j += 1; + } + while j < b.len() && b[j] != b'\'' { + j += 1; + } + i = j + 1; + continue; + } b'/' if !in_str && b.get(i + 1) == Some(&b'/') => return line[..i].trim_end(), _ => {} }