1use crate::dict::PinyinDict;
8use crate::fuzzy::FuzzyConfig;
9
10pub struct PinyinEngine {
13 dict: PinyinDict,
14 fuzzy: FuzzyConfig,
15}
16
17impl PinyinEngine {
18 pub fn new() -> Self {
20 Self {
21 dict: PinyinDict::embedded(),
22 fuzzy: FuzzyConfig::strict(),
23 }
24 }
25
26 pub fn with_fuzzy(fuzzy: FuzzyConfig) -> Self {
28 Self {
29 dict: PinyinDict::embedded(),
30 fuzzy,
31 }
32 }
33
34 pub fn dict(&self) -> &PinyinDict {
37 &self.dict
38 }
39
40 pub fn fuzzy(&self) -> FuzzyConfig {
42 self.fuzzy
43 }
44}
45
46impl Default for PinyinEngine {
47 fn default() -> Self {
48 Self::new()
49 }
50}
51
52#[cfg(test)]
53mod tests {
54 use super::*;
55
56 #[test]
57 fn new_loads_dict() {
58 let e = PinyinEngine::new();
59 assert!(e.dict().len() >= 50);
60 }
61
62 #[test]
63 fn with_fuzzy_keeps_dict() {
64 let e = PinyinEngine::with_fuzzy(FuzzyConfig::permissive());
65 assert!(e.dict().len() >= 50);
66 assert!(e.fuzzy().z_zh);
67 }
68}