diff --git a/Cargo.lock b/Cargo.lock index 3cfc8a8b..322b6924 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -192,6 +192,16 @@ dependencies = [ "vec_map", ] +[[package]] +name = "ctor" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8f45d9ad417bcef4817d614a501ab55cdd96a6fdb24f49aab89a54acfd66b19" +dependencies = [ + "quote", + "syn", +] + [[package]] name = "cty" version = "0.2.1" @@ -263,6 +273,12 @@ dependencies = [ "dbus", ] +[[package]] +name = "diff" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e25ea47919b1560c4e3b7fe0aaab9becf5b84a10325ddf7db0f0ba5e1026499" + [[package]] name = "downcast-rs" version = "1.2.0" @@ -684,6 +700,7 @@ dependencies = [ "kime-engine-backend-math", "kime-run-dir", "maplit", + "pretty_assertions", "serde", "serde_yaml", "xdg", @@ -958,6 +975,15 @@ version = "1.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "af8b08b04175473088b46763e51ee54da5f9a164bc162f615b91bc179dbf15a3" +[[package]] +name = "output_vt100" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53cdc5b785b7a58c5aad8216b3dfa114df64b0b06ae6e1501cef91df2fbdf8f9" +dependencies = [ + "winapi", +] + [[package]] name = "pad" version = "0.1.6" @@ -1009,6 +1035,18 @@ version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857" +[[package]] +name = "pretty_assertions" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f297542c27a7df8d45de2b0e620308ab883ad232d06c14b76ac3e144bda50184" +dependencies = [ + "ansi_term 0.12.1", + "ctor", + "diff", + "output_vt100", +] + [[package]] name = "proc-macro-crate" version = "0.1.5" diff --git a/src/engine/core/Cargo.toml b/src/engine/core/Cargo.toml index 85076c47..67b7c1df 100644 --- a/src/engine/core/Cargo.toml +++ b/src/engine/core/Cargo.toml @@ -26,3 +26,6 @@ maplit = "1.0.2" [target.'cfg(unix)'.dependencies] xdg = "2.2.0" kime-run-dir = { path = "../../tools/run_dir" } + +[dev-dependencies] +pretty_assertions = "0.7.1" diff --git a/src/engine/core/tests/hanja.rs b/src/engine/core/tests/hanja.rs index b70db6cb..31a750c7 100644 --- a/src/engine/core/tests/hanja.rs +++ b/src/engine/core/tests/hanja.rs @@ -10,13 +10,22 @@ fn ra() { (Key::normal(K), "라", ""), ( Key::normal(HangulHanja), - "/囉(exclamatory final particle, nag)摞瘰砢儸臝蓏倮覶鑼騾驘拏", + "/倮(bare, naked, uncovered)儸囉摞瘰砢臝蓏覶鑼騾驘拏", "", ), - (Key::normal(Enter), "", "囉"), + (Key::normal(Enter), "", "倮"), ]) } +#[test] +fn empty() { + test_input(&[(Key::normal(HangulHanja), "", "")]); + test_input(&[ + (Key::normal(R), "ㄱ", ""), + (Key::normal(HangulHanja), "ㄱ", ""), + ]); +} + // issue #381 #[test] fn ra_arrow() { @@ -25,14 +34,14 @@ fn ra_arrow() { (Key::normal(K), "라", ""), ( Key::normal(HangulHanja), - "/囉(exclamatory final particle, nag)摞瘰砢儸臝蓏倮覶鑼騾驘拏", + "/倮(bare, naked, uncovered)儸囉摞瘰砢臝蓏覶鑼騾驘拏", "", ), ( Key::normal(Right), - "囉/摞(to pile up)瘰砢儸臝蓏倮覶鑼騾驘拏", + "倮/儸(bandit, daredevil)囉摞瘰砢臝蓏覶鑼騾驘拏", "", ), - (Key::normal(Enter), "", "摞"), + (Key::normal(Enter), "", "儸"), ]) } diff --git a/src/engine/core/tests/shared.rs b/src/engine/core/tests/shared.rs index d07c58c4..f1bc5435 100644 --- a/src/engine/core/tests/shared.rs +++ b/src/engine/core/tests/shared.rs @@ -1,4 +1,5 @@ use kime_engine_core::{Config, InputCategory, InputEngine, InputResult, Key, RawConfig}; +use pretty_assertions::assert_eq; #[track_caller] pub fn test_input_impl(config: RawConfig, category: InputCategory, keys: &[(Key, &str, &str)]) { diff --git a/src/engine/dict/build.rs b/src/engine/dict/build.rs index 9fc09976..d95e62a8 100644 --- a/src/engine/dict/build.rs +++ b/src/engine/dict/build.rs @@ -176,12 +176,13 @@ fn main() { .unwrap(); for (k, mut values) in load_hanja_dict() { - write!(out, "('{}', &[", k).unwrap(); + values.retain(|e| e.hanja != '\0'); values.sort_unstable_by_key(|x| x.ty); + if values.is_empty() { + continue; + } + write!(out, "('{}', &[", k).unwrap(); for value in values { - if value.hanja == '\0' { - continue; - } write!(out, "('{}', \"{}\"),", value.hanja, value.definition).unwrap(); } writeln!(out, "]),").unwrap(); diff --git a/src/engine/dict/src/lib.rs b/src/engine/dict/src/lib.rs index ba6e156c..80b054d3 100644 --- a/src/engine/dict/src/lib.rs +++ b/src/engine/dict/src/lib.rs @@ -13,6 +13,13 @@ mod tests { assert_eq!(crate::lookup('가').unwrap()[0].0, '家'); } + #[test] + fn hanja_no_empty() { + for (k, v) in crate::dict::HANJA_ENTRIES { + assert!(!v.is_empty(), "With: ({}, {:?})", k, v); + } + } + #[test] fn math_symbols() { use crate::lookup_math_symbol;