Skip to content

Commit bf6480b

Browse files
committed
test(iconv): add test cases for ascii to utf8, (utf16, utf32) both LE and BE
1 parent 1ebb431 commit bf6480b

File tree

6 files changed

+175
-0
lines changed

6 files changed

+175
-0
lines changed

i18n/tests/iconv/mod.rs

Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,3 +208,177 @@ fn iconv_UTF8_to_UTF32LE_conversion_without_c_flag() {
208208
Vec::new(),
209209
);
210210
}
211+
212+
#[test]
213+
fn iconv_ASCII_to_UTF8_conversion_without_c_flag() {
214+
let cargo_manifest_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap());
215+
216+
let input_file = cargo_manifest_dir.join("tests/iconv/test_data_ascii");
217+
let mut input: Vec<u8> = Vec::new();
218+
File::open(&input_file)
219+
.unwrap()
220+
.read_to_end(&mut input)
221+
.unwrap();
222+
223+
let expected_output_file = cargo_manifest_dir.join("tests/iconv/test_data_ascii");
224+
225+
let mut expected_output: Vec<u8> = Vec::new();
226+
File::open(&expected_output_file)
227+
.unwrap()
228+
.read_to_end(&mut expected_output)
229+
.unwrap();
230+
231+
iconv_test(
232+
&["-f", "ASCII", "-t", "UTF-8"],
233+
input.clone(),
234+
expected_output.clone(),
235+
Vec::new(),
236+
);
237+
238+
iconv_test(
239+
&["-f", "ASCII", "-t", "UTF-8", "-"],
240+
input,
241+
expected_output,
242+
Vec::new(),
243+
);
244+
}
245+
246+
#[test]
247+
fn iconv_ASCII_to_UTF16LE_conversion_without_c_flag() {
248+
let cargo_manifest_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap());
249+
250+
let input_file = cargo_manifest_dir.join("tests/iconv/test_data_ascii");
251+
let mut input: Vec<u8> = Vec::new();
252+
File::open(&input_file)
253+
.unwrap()
254+
.read_to_end(&mut input)
255+
.unwrap();
256+
257+
let expected_output_file =
258+
cargo_manifest_dir.join("tests/iconv/test_data_ascii_to_utf16le_without_c_flag");
259+
260+
let mut expected_output: Vec<u8> = Vec::new();
261+
File::open(&expected_output_file)
262+
.unwrap()
263+
.read_to_end(&mut expected_output)
264+
.unwrap();
265+
266+
iconv_test(
267+
&["-f", "ASCII", "-t", "UTF-16LE"],
268+
input.clone(),
269+
expected_output.clone(),
270+
Vec::new(),
271+
);
272+
273+
iconv_test(
274+
&["-f", "ASCII", "-t", "UTF-16LE", "-"],
275+
input,
276+
expected_output,
277+
Vec::new(),
278+
);
279+
}
280+
281+
#[test]
282+
fn iconv_ASCII_to_UTF16BE_conversion_without_c_flag() {
283+
let cargo_manifest_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap());
284+
285+
let input_file = cargo_manifest_dir.join("tests/iconv/test_data_ascii");
286+
let mut input: Vec<u8> = Vec::new();
287+
File::open(&input_file)
288+
.unwrap()
289+
.read_to_end(&mut input)
290+
.unwrap();
291+
292+
let expected_output_file =
293+
cargo_manifest_dir.join("tests/iconv/test_data_ascii_to_utf16be_without_c_flag");
294+
295+
let mut expected_output: Vec<u8> = Vec::new();
296+
File::open(&expected_output_file)
297+
.unwrap()
298+
.read_to_end(&mut expected_output)
299+
.unwrap();
300+
301+
iconv_test(
302+
&["-f", "ASCII", "-t", "UTF-16BE"],
303+
input.clone(),
304+
expected_output.clone(),
305+
Vec::new(),
306+
);
307+
308+
iconv_test(
309+
&["-f", "ASCII", "-t", "UTF-16BE", "-"],
310+
input,
311+
expected_output,
312+
Vec::new(),
313+
);
314+
}
315+
316+
#[test]
317+
fn iconv_ASCII_to_UTF32LE_conversion_without_c_flag() {
318+
let cargo_manifest_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap());
319+
320+
let input_file = cargo_manifest_dir.join("tests/iconv/test_data_ascii");
321+
let mut input: Vec<u8> = Vec::new();
322+
File::open(&input_file)
323+
.unwrap()
324+
.read_to_end(&mut input)
325+
.unwrap();
326+
327+
let expected_output_file =
328+
cargo_manifest_dir.join("tests/iconv/test_data_ascii_to_utf32le_without_c_flag");
329+
330+
let mut expected_output: Vec<u8> = Vec::new();
331+
File::open(&expected_output_file)
332+
.unwrap()
333+
.read_to_end(&mut expected_output)
334+
.unwrap();
335+
336+
iconv_test(
337+
&["-f", "ASCII", "-t", "UTF-32LE"],
338+
input.clone(),
339+
expected_output.clone(),
340+
Vec::new(),
341+
);
342+
343+
iconv_test(
344+
&["-f", "ASCII", "-t", "UTF-32LE", "-"],
345+
input,
346+
expected_output,
347+
Vec::new(),
348+
);
349+
}
350+
351+
#[test]
352+
fn iconv_ASCII_to_UTF32BE_conversion_without_c_flag() {
353+
let cargo_manifest_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap());
354+
355+
let input_file = cargo_manifest_dir.join("tests/iconv/test_data_ascii");
356+
let mut input: Vec<u8> = Vec::new();
357+
File::open(&input_file)
358+
.unwrap()
359+
.read_to_end(&mut input)
360+
.unwrap();
361+
362+
let expected_output_file =
363+
cargo_manifest_dir.join("tests/iconv/test_data_ascii_to_utf32be_without_c_flag");
364+
365+
let mut expected_output: Vec<u8> = Vec::new();
366+
File::open(&expected_output_file)
367+
.unwrap()
368+
.read_to_end(&mut expected_output)
369+
.unwrap();
370+
371+
iconv_test(
372+
&["-f", "ASCII", "-t", "UTF-32BE"],
373+
input.clone(),
374+
expected_output.clone(),
375+
Vec::new(),
376+
);
377+
378+
iconv_test(
379+
&["-f", "ASCII", "-t", "UTF-32BE", "-"],
380+
input,
381+
expected_output,
382+
Vec::new(),
383+
);
384+
}

i18n/tests/iconv/test_data_ascii

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
these are ascii characters 24234o1203572hkd f98882 2380 !@#$%~^&!(123423*/+*-/////////""""""
186 Bytes
Binary file not shown.
186 Bytes
Binary file not shown.
372 Bytes
Binary file not shown.
372 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)