use dictutils::prelude::*;
use std::path::Path;
#[test]
fn test_mdx_encoding_fix() {
println!("Testing MDX encoding fix...");
let loader = DictLoader::new();
let result = loader.load(Path::new("test_dict/test.mdx"));
match result {
Ok(dict) => {
println!("✓ Dictionary loaded successfully!");
let test_words = ["hello", "world", "test", "example", "a", "the", "and"];
for word in test_words.iter() {
match dict.get(&word.to_string()) {
Ok(entry) => {
println!("✓ Found '{}': {}", word, String::from_utf8_lossy(&entry));
return; }
Err(e) => {
println!("✗ Word '{}' not found: {}", word, e);
}
}
}
println!("✓ Dictionary loaded but no test words found");
}
Err(e) => {
panic!("✗ Failed to load dictionary: {}", e);
}
}
}
#[test]
fn test_encoding_conversion_function() {
println!("Testing encoding conversion function...");
let test_data = vec![
0xD6, 0xD0, 0xB9, 0xFA, 0xC8, 0xCB, 0xC2, 0xDB, 0xCA, 0xC7, ];
assert!(String::from_utf8(test_data.clone()).is_err(), "Test data should not be valid UTF-8");
let result = dictutils::dict::mdict::convert_entry_data_if_needed(&test_data);
match result {
Ok(converted) => {
let utf8_str = String::from_utf8(converted).expect("Converted data should be valid UTF-8");
println!("✓ Successfully converted GBK to UTF-8: {}", utf8_str);
assert!(!utf8_str.is_empty(), "Converted string should not be empty");
}
Err(e) => {
panic!("✗ Conversion failed: {}", e);
}
}
}