use crate::core::util::error::lucene_error::Result;
use crate::core::util::unicode_util::{UTF8CodePoint, UnicodeUtil};
use crate::test_framework::core::util::lucene_test_case::{at_least, random};
use crate::test_framework::core::util::test_util::TestUtil;
#[allow(dead_code)] struct TestUnicodeUtil;
#[test]
fn test_code_point_count() -> Result<()> {
Ok(())
}
#[test]
fn test_utf8_to_utf32() -> Result<()> {
Ok(())
}
#[test]
fn test_utf8_code_point_at() -> Result<()> {
let mut random = random();
let num = at_least(&mut random, 50_000);
let mut reuse = UTF8CodePoint::default();
let mut expected = Vec::new();
for _ in 0..num {
let s = TestUtil::random_unicode_string(&mut random);
let utf8 = s.as_bytes();
expected.clear();
expected.extend(s.chars().map(|ch| ch as i32));
let mut pos = 0;
let mut expected_upto = 0;
while pos < utf8.len() {
UnicodeUtil::code_point_at(utf8, pos, &mut reuse)?;
assert_eq!(expected[expected_upto], reuse.code_point);
expected_upto += 1;
pos += reuse.num_bytes;
}
assert_eq!(utf8.len(), pos);
assert_eq!(expected.len(), expected_upto);
}
Ok(())
}
#[test]
fn test_utf8_span_multiple_bytes() -> Result<()> {
Ok(())
}
#[test]
fn test_new_string() -> Result<()> {
let code_points = [0x103FF, 0x10FC00, 0xDBFF, 'A' as i32, -1];
let first = char::from_u32(code_points[0] as u32).unwrap().to_string();
let second = char::from_u32(code_points[1] as u32).unwrap().to_string();
let first_second = format!("{first}{second}");
assert_eq!(first, UnicodeUtil::new_string(&code_points, 0, 1)?);
assert_eq!(first_second, UnicodeUtil::new_string(&code_points, 0, 2)?);
assert_eq!(second, UnicodeUtil::new_string(&code_points, 1, 1)?);
assert!(UnicodeUtil::new_string(&code_points, 1, 2).is_err());
assert!(UnicodeUtil::new_string(&code_points, 1, 3).is_err());
assert!(UnicodeUtil::new_string(&code_points, 2, 2).is_err());
assert!(UnicodeUtil::new_string(&code_points, 2, 3).is_err());
assert!(UnicodeUtil::new_string(&code_points, 4, 5).is_err());
Ok(())
}
#[test]
fn test_utf8_utf16_chars_ref() -> Result<()> {
Ok(())
}
#[test]
fn test_calc_utf16_to_utf8_length() -> Result<()> {
Ok(())
}