on master help sign in
use system's appropriate line ending
ef8fe5aSkyler Hawthorne
helix-term/tests/integration/auto_indent.rs+4−3
@@ -10,13 +10,14 @@ async fn auto_indent_c() -> anyhow::Result<()> {
10 Config::default(),
10 Config::default(),
11 // switches to append mode?
11 // switches to append mode?
12 (
12 (
13− "void foo() {#[|}]#\n",
13+ helpers::platform_line("void foo() {#[|}]#").as_ref(),
14 "i<ret><esc>",
14 "i<ret><esc>",
15− indoc! {"\
15+ helpers::platform_line(indoc! {"\
16 void foo() {
16 void foo() {
17 #[|\n]#\
17 #[|\n]#\
18 }
18 }
19− "},
19+ "})
20+ .as_ref(),
20 ),
21 ),
21 )
22 )
22 .await?;
23 .await?;
helix-term/tests/integration/helpers.rs+17
@@ -138,3 +138,20 @@ pub fn temp_file_with_contents<S: AsRef<str>>(
138 temp_file.as_file_mut().sync_all()?;
138 temp_file.as_file_mut().sync_all()?;
139 Ok(temp_file)
139 Ok(temp_file)
140}
140}
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<()> {
31
31
32 let mut file_content = String::new();
32 let mut file_content = String::new();
33 file.as_file_mut().read_to_string(&mut file_content)?;
33 file.as_file_mut().read_to_string(&mut file_content)?;
34+ assert_eq!(
34− assert_eq!("i can eat glass, it will not hurt me\n", file_content);
35+ helpers::platform_line("i can eat glass, it will not hurt me"),
36+ file_content
37+ );
35
38
36 Ok(())
39 Ok(())
37}
40}