aboutsummaryrefslogtreecommitdiff
path: root/helix-term/tests/test/commands
diff options
context:
space:
mode:
authorAlexis-Lapierre2023-04-30 22:40:06 +0000
committerGitHub2023-04-30 22:40:06 +0000
commitb0b3f45b80931e73eadaf7e73f1981283b8e49fc (patch)
tree77329232f1ca98e5eaa131f471ea25b23e5eb0d5 /helix-term/tests/test/commands
parentefd09b6c7ccf8cdfde5856fd9db0d9b29ea5bd81 (diff)
Conserve BOM and properly support UTF16 (#6497)
Diffstat (limited to 'helix-term/tests/test/commands')
-rw-r--r--helix-term/tests/test/commands/write.rs38
1 files changed, 38 insertions, 0 deletions
diff --git a/helix-term/tests/test/commands/write.rs b/helix-term/tests/test/commands/write.rs
index 26515b7a..f33c8aaf 100644
--- a/helix-term/tests/test/commands/write.rs
+++ b/helix-term/tests/test/commands/write.rs
@@ -407,3 +407,41 @@ async fn test_write_fail_new_path() -> anyhow::Result<()> {
Ok(())
}
+
+#[tokio::test(flavor = "multi_thread")]
+async fn test_write_utf_bom_file() -> anyhow::Result<()> {
+ // "ABC" with utf8 bom
+ const UTF8_FILE: [u8; 6] = [0xef, 0xbb, 0xbf, b'A', b'B', b'C'];
+
+ // "ABC" in UTF16 with bom
+ const UTF16LE_FILE: [u8; 8] = [0xff, 0xfe, b'A', 0x00, b'B', 0x00, b'C', 0x00];
+ const UTF16BE_FILE: [u8; 8] = [0xfe, 0xff, 0x00, b'A', 0x00, b'B', 0x00, b'C'];
+
+ edit_file_with_content(&UTF8_FILE).await?;
+ edit_file_with_content(&UTF16LE_FILE).await?;
+ edit_file_with_content(&UTF16BE_FILE).await?;
+
+ Ok(())
+}
+
+async fn edit_file_with_content(file_content: &[u8]) -> anyhow::Result<()> {
+ let mut file = tempfile::NamedTempFile::new()?;
+
+ file.as_file_mut().write_all(&file_content)?;
+
+ helpers::test_key_sequence(
+ &mut helpers::AppBuilder::new().build()?,
+ Some(&format!(":o {}<ret>:x<ret>", file.path().to_string_lossy())),
+ None,
+ true,
+ )
+ .await?;
+
+ file.rewind()?;
+ let mut new_file_content: Vec<u8> = Vec::new();
+ file.read_to_end(&mut new_file_content)?;
+
+ assert_eq!(file_content, new_file_content);
+
+ Ok(())
+}