Skip to content
This repository was archived by the owner on Nov 24, 2023. It is now read-only.

Commit 8aef421

Browse files
killercupalexcrichton
authored andcommitted
Add test for preserving line endings
Closes #77
1 parent d150af8 commit 8aef421

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

cargo-fix/tests/all/main.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ extern crate difference;
22
extern crate url;
33

44
use std::env;
5-
use std::fs;
6-
use std::io::Write;
5+
use std::fs::{self, File};
6+
use std::io::{Read, Write};
77
use std::path::{Path, PathBuf};
88
use std::process::Command;
99
use std::str;
@@ -84,6 +84,15 @@ impl Project {
8484
cwd: None,
8585
}
8686
}
87+
88+
fn read(&self, path: &str) -> String {
89+
let mut ret = String::new();
90+
File::open(self.root.join(path))
91+
.unwrap()
92+
.read_to_string(&mut ret)
93+
.unwrap();
94+
return ret
95+
}
8796
}
8897

8998
struct ExpectCmd<'a> {

cargo-fix/tests/all/smoke.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,16 @@ fn tricky_ampersand() {
8787
.stderr(stderr)
8888
.run();
8989
}
90+
91+
#[test]
92+
fn preserve_line_endings() {
93+
let p = project()
94+
.file("src/lib.rs", "\
95+
fn add(a: &u32) -> u32 { a + 1 }\r\n\
96+
pub fn foo() -> u32 { add(1) }\r\n\
97+
")
98+
.build();
99+
100+
p.expect_cmd("cargo fix").run();
101+
assert!(p.read("src/lib.rs").contains("\r\n"));
102+
}

0 commit comments

Comments
 (0)