More thorough tests for UTF16LE

This commit is contained in:
Keith Hall
2025-08-16 15:33:30 +03:00
parent 6675153460
commit 40c4c8e542
4 changed files with 39 additions and 3 deletions

View File

@@ -371,11 +371,13 @@ fn utf16le() {
#[test]
fn utf16le_issue3367() {
let content = b"\xFF\xFE\x0A\x4E\x00\x4E\x0A\x4F\x00\x52";
let content = b"\xFF\xFE\x0A\x4E\x00\x4E\x0A\x4F\x00\x52\x0A\x00\
\x6F\x00\x20\x00\x62\x00\x61\x00\x72\x00\x0A\x00\
\x68\x00\x65\x00\x6C\x00\x6C\x00\x6F\x00\x20\x00\x77\x00\x6F\x00\x72\x00\x6C\x00\x64\x00";
let mut reader = InputReader::new(&content[..]);
assert_eq!(
b"\xFF\xFE\x0A\x4E\x00\x4E\x0A\x4F\x00\x52",
b"\xFF\xFE\x0A\x4E\x00\x4E\x0A\x4F\x00\x52\x0A\x00",
&reader.first_line[..]
);
@@ -384,7 +386,21 @@ fn utf16le_issue3367() {
let res = reader.read_line(&mut buffer);
assert!(res.is_ok());
assert!(res.unwrap());
assert_eq!(b"\xFF\xFE\x0A\x4E\x00\x4E\x0A\x4F\x00\x52", &buffer[..]);
assert_eq!(b"\xFF\xFE\x0A\x4E\x00\x4E\x0A\x4F\x00\x52\x0A\x00", &buffer[..]);
buffer.clear();
let res = reader.read_line(&mut buffer);
assert!(res.is_ok());
assert!(res.unwrap());
assert_eq!(b"\x6F\x00\x20\x00\x62\x00\x61\x00\x72\x00\x0A\x00", &buffer[..]);
buffer.clear();
let res = reader.read_line(&mut buffer);
assert!(res.is_ok());
assert!(res.unwrap());
assert_eq!(b"\x68\x00\x65\x00\x6C\x00\x6C\x00\x6F\x00\x20\x00\x77\x00\x6F\x00\x72\x00\x6C\x00\x64\x00", &buffer[..]);
buffer.clear();

BIN
tests/examples/test_UTF-16BE.txt vendored Normal file

Binary file not shown.

Binary file not shown.

View File

@@ -1321,6 +1321,26 @@ fn utf16() {
.assert()
.success()
.stdout("hello world\n");
bat()
.arg("--plain")
.arg("--decorations=always")
.arg("test_UTF-16BE.txt")
.assert()
.success()
.stdout("hello world\nthis is a test\n");
}
#[test]
fn utf16le() {
bat()
.arg("--decorations=always")
.arg("--style=numbers")
.arg("--color=never")
.arg("test_UTF-16LE-complicated.txt")
.assert()
.success()
.stdout(" 1 上一伊刀\n 2 foo bar\n 3 hello world\n");
}
// Regression test for https://github.com/sharkdp/bat/issues/1922