Fix unicode char parsing in comments.

This commit is contained in:
KtorZ 2023-02-22 17:33:13 +01:00
parent fbf65de1dc
commit 539ed2dea4
No known key found for this signature in database
GPG Key ID: 33173CB6F77F4277
2 changed files with 21 additions and 3 deletions

View File

@ -23,10 +23,15 @@ pub struct Comment<'a> {
impl<'a> From<(&Span, &'a str)> for Comment<'a> {
fn from(src: (&Span, &'a str)) -> Comment<'a> {
let start = src.0.start;
let end = src.0.end;
fn char_indice(s: &str, i: usize) -> usize {
s.char_indices().nth(i).expect("char at given indice").0
}
let start = char_indice(src.1, src.0.start);
let end = char_indice(src.1, src.0.end);
Comment {
start,
start: src.0.start,
content: src.1.get(start..end).expect("From span to comment"),
}
}

View File

@ -547,3 +547,16 @@ fn test_string_literal() {
assert_fmt(src, src);
}
#[test]
fn test_unicode() {
let src = indoc! {r#"
/// ∞ ★ ♩ ♫ ✓
fn foo() {
trace @"∀💩"
Void
}
"#};
assert_fmt(src, src);
}