on master help sign in
use system's appropriate line ending
commitef8fe5a5ce536c65f34e479db79b94c8435aa3b2 authorSkyler Hawthorne <skyler@dead10ck.com> dateFri 29 Apr 2022, 16:27 (4 years ago) parent28e94fb
3 files changed+25−4
helix-term/tests/integration/auto_indent.rs+4−3 helix-term/tests/integration/helpers.rs+17 helix-term/tests/integration/write.rs+4−1
helix-term/tests/integration/auto_indent.rs+4−3
@@ -10,13 +10,14 @@ async fn auto_indent_c() -> anyhow::Result<()> {
1010 Config::default(),
1111 // switches to append mode?
1212 (
13− "void foo() {#[|}]#\n",
13+ helpers::platform_line("void foo() {#[|}]#").as_ref(),
1414 "i<ret><esc>",
15− indoc! {"\
15+ helpers::platform_line(indoc! {"\
1616 void foo() {
1717 #[|\n]#\
1818 }
19− "},
19+ "})
20+ .as_ref(),
2021 ),
2122 )
2223 .await?;
helix-term/tests/integration/helpers.rs+17
@@ -138,3 +138,20 @@ pub fn temp_file_with_contents<S: AsRef<str>>(
138138 temp_file.as_file_mut().sync_all()?;
139139 Ok(temp_file)
140140}
141+
142+/// Replaces all LF chars with the system's appropriate line feed
143+/// character, and if one doesn't exist already, appends the system's
144+/// appropriate line ending to the end of a string.
145+pub fn platform_line(input: &str) -> String {
146+ let line_end = helix_core::DEFAULT_LINE_ENDING.as_str();
147+
148+ // we can assume that the source files in this code base will always
149+ // be LF, so indoc strings will always insert LF
150+ let mut output = input.replace("\n", line_end);
151+
152+ if !output.ends_with(line_end) {
153+ output.push_str(line_end);
154+ }
155+
156+ output
157+}
helix-term/tests/integration/write.rs+4−1
@@ -31,7 +31,10 @@ async fn test_write() -> anyhow::Result<()> {
3131
3232 let mut file_content = String::new();
3333 file.as_file_mut().read_to_string(&mut file_content)?;
34− assert_eq!("i can eat glass, it will not hurt me\n", file_content);
34+ assert_eq!(
35+ helpers::platform_line("i can eat glass, it will not hurt me"),
36+ file_content
37+ );
3538
3639 Ok(())
3740}