use gukhanmun::{Builder, ContextWindow, DirectiveAction, HomophoneDetection, MapDictionary};
#[test]
fn earlier_dictionaries_win_over_later_ones() {
let mut high = MapDictionary::new();
high.insert("學校", "교실");
let mut low = MapDictionary::new();
low.insert("學校", "학교");
let converter = Builder::new()
.no_bundled_stdict()
.push_dictionary(high)
.push_dictionary(low)
.build()
.expect("builder");
assert_eq!(
converter.convert_text_to_string("學校").expect("convert"),
"교실"
);
}
#[test]
fn context_local_detection_emits_hanja_for_in_text_collision() {
let mut user = MapDictionary::new();
user.insert("家長", "가장");
user.insert("假裝", "가장");
let converter = Builder::new()
.no_bundled_stdict()
.push_dictionary(user)
.homophone_window(ContextWindow::PerDocument)
.build()
.expect("builder");
assert_eq!(
converter
.convert_text_to_string("家長과 假裝")
.expect("convert"),
"가장(家長)과 가장(假裝)"
);
}
#[test]
fn context_local_detection_leaves_isolated_word_unglossed() {
let mut user = MapDictionary::new();
user.insert("家長", "가장");
user.insert("假裝", "가장");
let converter = Builder::new()
.no_bundled_stdict()
.push_dictionary(user)
.homophone_window(ContextWindow::PerDocument)
.build()
.expect("builder");
assert_eq!(
converter.convert_text_to_string("家長").expect("convert"),
"가장"
);
}
#[test]
fn dictionary_wide_detection_emits_hanja_without_in_text_collision() {
let mut user = MapDictionary::new();
user.insert("家長", "가장");
user.insert("假裝", "가장");
let converter = Builder::new()
.no_bundled_stdict()
.push_dictionary(user)
.homophone_window(ContextWindow::PerDocument)
.homophone_detection(HomophoneDetection::DictionaryWide)
.build()
.expect("builder");
assert_eq!(
converter.convert_text_to_string("家長").expect("convert"),
"가장(家長)"
);
}
#[test]
fn user_directive_skip_annotation_collapses_to_plain_hangul() {
let mut user = MapDictionary::new();
user.insert_marked(
"學校",
"학교",
gukhanmun::MatchMark {
require_hanja: true,
require_hangul: false,
},
);
let converter = Builder::new()
.no_bundled_stdict()
.push_dictionary(user)
.directive("學校", DirectiveAction::SkipAnnotation)
.build()
.expect("builder");
assert_eq!(
converter.convert_text_to_string("學校").expect("convert"),
"학교"
);
}