Fix unicode char parsing in comments.
This commit is contained in:
parent
fbf65de1dc
commit
539ed2dea4
|
@ -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"),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue