Skip to content

Commit

Permalink
test(iconv): add test cases for utf16be to utf16le, utf32(BE & LE), u…
Browse files Browse the repository at this point in the history
…tf8 and ascii
  • Loading branch information
rishadbaniya committed Oct 14, 2024
1 parent e4926ea commit a3150f2
Show file tree
Hide file tree
Showing 7 changed files with 214 additions and 1 deletion.
177 changes: 176 additions & 1 deletion i18n/tests/iconv/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -874,7 +874,7 @@ fn iconv_UTF16LE_to_UTF32LE_conversion_without_c_flag() {
}

#[test]
fn iconv_UTF16LE_to_UTF8_conversion_with_c_flag() {
fn iconv_UTF16LE_to_UTF8_conversion_without_c_flag() {
let cargo_manifest_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap());

let input_file = cargo_manifest_dir.join("tests/iconv/test_data_utf16le");
Expand Down Expand Up @@ -907,3 +907,178 @@ fn iconv_UTF16LE_to_UTF8_conversion_with_c_flag() {
Vec::new(),
);
}

#[test]
fn iconv_UTF16BE_to_UTF16LE_conversion_without_c_flag() {
let cargo_manifest_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap());

let input_file = cargo_manifest_dir.join("tests/iconv/test_data_utf16be");
let mut input: Vec<u8> = Vec::new();
File::open(&input_file)
.unwrap()
.read_to_end(&mut input)
.unwrap();

let expected_output_file =
cargo_manifest_dir.join("tests/iconv/test_data_utf16be_to_utf16le_without_c_flag");

let mut expected_output: Vec<u8> = Vec::new();
File::open(&expected_output_file)
.unwrap()
.read_to_end(&mut expected_output)
.unwrap();

iconv_test(
&["-f", "UTF-16BE", "-t", "UTF-16LE"],
input.clone(),
expected_output.clone(),
Vec::new(),
);

iconv_test(
&["-f", "UTF-16BE", "-t", "UTF-16LE", "-"],
input,
expected_output,
Vec::new(),
);
}

#[test]
fn iconv_UTF16BE_to_ASCII_conversion_with_c_flag() {
let cargo_manifest_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap());

let input_file = cargo_manifest_dir.join("tests/iconv/test_data_utf16be");
let mut input: Vec<u8> = Vec::new();
File::open(&input_file)
.unwrap()
.read_to_end(&mut input)
.unwrap();

let expected_output_file =
cargo_manifest_dir.join("tests/iconv/test_data_utf16be_to_ascii_with_c_flag");

let mut expected_output: Vec<u8> = Vec::new();
File::open(&expected_output_file)
.unwrap()
.read_to_end(&mut expected_output)
.unwrap();

iconv_test(
&["-c", "-f", "UTF-16BE", "-t", "ASCII"],
input.clone(),
expected_output.clone(),
Vec::new(),
);

iconv_test(
&["-c", "-f", "UTF-16BE", "-t", "ASCII", "-"],
input,
expected_output,
Vec::new(),
);
}

#[test]
fn iconv_UTF16BE_to_UTF32BE_conversion_without_c_flag() {
let cargo_manifest_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap());

let input_file = cargo_manifest_dir.join("tests/iconv/test_data_utf16be");
let mut input: Vec<u8> = Vec::new();
File::open(&input_file)
.unwrap()
.read_to_end(&mut input)
.unwrap();

let expected_output_file =
cargo_manifest_dir.join("tests/iconv/test_data_utf16be_to_utf32be_without_c_flag");

let mut expected_output: Vec<u8> = Vec::new();
File::open(&expected_output_file)
.unwrap()
.read_to_end(&mut expected_output)
.unwrap();

iconv_test(
&["-f", "UTF-16BE", "-t", "UTF-32BE"],
input.clone(),
expected_output.clone(),
Vec::new(),
);

iconv_test(
&["-f", "UTF-16BE", "-t", "UTF-32BE", "-"],
input,
expected_output,
Vec::new(),
);
}

#[test]
fn iconv_UTF16BE_to_UTF32LE_conversion_without_c_flag() {
let cargo_manifest_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap());

let input_file = cargo_manifest_dir.join("tests/iconv/test_data_utf16be");
let mut input: Vec<u8> = Vec::new();
File::open(&input_file)
.unwrap()
.read_to_end(&mut input)
.unwrap();

let expected_output_file =
cargo_manifest_dir.join("tests/iconv/test_data_utf16be_to_utf32le_without_c_flag");

let mut expected_output: Vec<u8> = Vec::new();
File::open(&expected_output_file)
.unwrap()
.read_to_end(&mut expected_output)
.unwrap();

iconv_test(
&["-f", "UTF-16BE", "-t", "UTF-32LE"],
input.clone(),
expected_output.clone(),
Vec::new(),
);

iconv_test(
&["-f", "UTF-16BE", "-t", "UTF-32LE", "-"],
input,
expected_output,
Vec::new(),
);
}

#[test]
fn iconv_UTF16BE_to_UTF8_conversion_without_c_flag() {
let cargo_manifest_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap());

let input_file = cargo_manifest_dir.join("tests/iconv/test_data_utf16be");
let mut input: Vec<u8> = Vec::new();
File::open(&input_file)
.unwrap()
.read_to_end(&mut input)
.unwrap();

let expected_output_file =
cargo_manifest_dir.join("tests/iconv/test_data_utf16be_to_utf8_without_c_flag");

let mut expected_output: Vec<u8> = Vec::new();
File::open(&expected_output_file)
.unwrap()
.read_to_end(&mut expected_output)
.unwrap();

iconv_test(
&["-f", "UTF-16BE", "-t", "UTF-8"],
input.clone(),
expected_output.clone(),
Vec::new(),
);

iconv_test(
&["-f", "UTF-16BE", "-t", "UTF-8", "-"],
input,
expected_output,
Vec::new(),
);
}
Binary file added i18n/tests/iconv/test_data_utf16be
Binary file not shown.
19 changes: 19 additions & 0 deletions i18n/tests/iconv/test_data_utf16be_to_ascii_with_c_flag
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
This test data was originally written for UTF16BE

It emojis + latin characters



8
6






7




Binary file not shown.
Binary file not shown.
Binary file not shown.
19 changes: 19 additions & 0 deletions i18n/tests/iconv/test_data_utf16be_to_utf8_without_c_flag
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
This test data was originally written for UTF16BE

It emojis + latin characters

🔥 🏣 🚫 🅰️ 🎏 🤖 🐲 🔳 🔷 🐩 🕹 😁 🛫 🌊 ℹ️ 😦 🔍 🏇 🏨 🏰 💥 🌓 ◾️ 🍄 ⌛️ 😎 👁
🗞 🚽 🎸 🆗 😯 🔬 🌷 😞 Ⓜ️ 🚣 🔰 🍭 💯 🍟 🍚 🎻 ♨️ 🚇 💩 🐋 🐢 ⛵️ 🆘 ㊙️ 😊 🔢 🗣
🍶 ↘️ 😉 💇 ⚗ 🍺 👣 💭 🌛 😰 👘 🚠 🍽 🏑 😽 ™️ 🐿 👄 👀 🙋 🖱 8️⃣ 🕡 🏬 📮 🐜 🖼 📰
🌙 🈺 🔣 🍲 ⚔ 🚂 🔎 📑 6️⃣ 🔤 💖 🏟 ♌️ 💳 ♋️ 📢 ↪️ 🏥 ⛅️ 🛣 🎁 🔱 😈 😑 ⏯ 🎥 💆 🎒
💁 ◽️ 👾 👞 😚 🚁 🌾 📓 🐔 🗄 🕣 ⛈ 🕉 ☠ ➕ 🎿 💘 🗾 🌤 🙉 🐄 🚿 🍫 🕳 💙 🐳 ⚰ 💧
🗑 🎓 🎑 ♍️ 📠 💗 🏄 🐗 🃏 🎗 🔽 🌐 📇 💢 😅 💕 💺 🔏 👋 🏐 🍞 😢 🅿️ 🐱 🛩 ☮ ⛳️ 🍊
😣 🌍 💃 ☢ ☔️ 💊 🗨 🚢 ⛷ 🤓 🏀 📫 🖍 🍒 🍡 🎊 🔈 🌞 🔆 🕎 🎇 ⛸ 🌿 🐭 💴 ✨ ⏰ 🤔
🔼 ♐️ 💱 ⚡️ 🌮 🕛 🌗 🛢 🎋 🏊 😘 ✖️ 🌰 🗜 🔃 👹 🛏 💚 🍏 🚒 🌶 👩 🛰 🚩 💏 🌫 😶
🛡 ⤴️ ⏺ 🚀 🤑 🈵 🎙 ▫️ 🐇 🚯 📔 👧 😪 🍵 🏹 🕠 🕖 🤗 🔜 🈁 ⏫ 👏 🚖 🚐 🚆 🏈 🍥
🌀 📸 🎮 🚌 🚔 💞 ✌️ ◀️ 👌 ➿ 🌂 🌋 🎢 ☪ 🐟 🌯 🔄 💌 📹 😥 🐬 🔺 🙆 😼 🐚 〽️ 👈
🚊 🐂 ❓ 7️⃣ ✂️ 🏭 🔻 🆚 ☸ 🎎 🈲 🅾️ 🕶 🏯 🕷 💐 🈚️ 🏗 ✉️ 📧 🚤 🆕 ⁉️ 🆎 ⏏ 🚄 🈳 🏺 🍼
📦 ◼️ 🍻 ⬛️ 🌥 ⏸ 🏳 🛬 🦃 ⛰ ☦ 💒 🖥 🏓 🏫 ☃ 🕓 ⛑ 🕴 🖊 🛀 👷 🏞 ⚜ 📞 🌠 🌨 🗂 😩
📋 📡 📿 🎧 🏩 😡 💛 ⛎ 🐌 🕚 ⚒ 🔔 😻 👦 🔦 🈯️ 🚜 💔 🚸 👿 🍢 ®️ 🕯 🚱 🗓 ↩️ 👛 🔚

𐌀𐌁𐌂𐌃𐌄𐌅𐌆𐌇𐌉𐌊𐌋𐌌𐌍𐌏𐌐𐌒𐌓𐌔𐌕𐌖𐌗

0 comments on commit a3150f2

Please sign in to comment.