parent
feb2698e5e
commit
1747090931
|
@ -24,7 +24,7 @@ pub struct Comment<'a> {
|
||||||
impl<'a> From<(&Span, &'a str)> for Comment<'a> {
|
impl<'a> From<(&Span, &'a str)> for Comment<'a> {
|
||||||
fn from(src: (&Span, &'a str)) -> Comment<'a> {
|
fn from(src: (&Span, &'a str)) -> Comment<'a> {
|
||||||
fn char_indice(s: &str, i: usize) -> usize {
|
fn char_indice(s: &str, i: usize) -> usize {
|
||||||
s.char_indices().nth(i).expect("char at given indice").0
|
s.char_indices().nth(i).unwrap_or((i, ' ')).0
|
||||||
}
|
}
|
||||||
|
|
||||||
let start = char_indice(src.1, src.0.start);
|
let start = char_indice(src.1, src.0.start);
|
||||||
|
|
|
@ -17,6 +17,23 @@ fn assert_fmt(src: &str, expected: &str) {
|
||||||
assert_eq!(out, out2, "formatting isn't idempotent");
|
assert_eq!(out, out2, "formatting isn't idempotent");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn comment_at_end_of_file() {
|
||||||
|
let input = indoc! { r#"
|
||||||
|
type Foo =
|
||||||
|
Int
|
||||||
|
|
||||||
|
//"#};
|
||||||
|
|
||||||
|
let output = indoc! { r#"
|
||||||
|
type Foo =
|
||||||
|
Int
|
||||||
|
//
|
||||||
|
"#};
|
||||||
|
|
||||||
|
assert_fmt(input, output);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_format_if() {
|
fn test_format_if() {
|
||||||
let src = indoc! {r#"
|
let src = indoc! {r#"
|
||||||
|
|
Loading…
Reference in New Issue