Skip to content

Commit

Permalink
Try prevent hanja panic (#402)
Browse files Browse the repository at this point in the history
* Add hanja empty test

* Try remove empty entries

* Fix test
  • Loading branch information
Riey authored Mar 21, 2021
1 parent 80952d8 commit 7149615
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 9 deletions.
38 changes: 38 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/engine/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
19 changes: 14 additions & 5 deletions src/engine/core/tests/hanja.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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), "", ""),
])
}
1 change: 1 addition & 0 deletions src/engine/core/tests/shared.rs
Original file line number Diff line number Diff line change
@@ -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)]) {
Expand Down
9 changes: 5 additions & 4 deletions src/engine/dict/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
7 changes: 7 additions & 0 deletions src/engine/dict/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 7149615

Please sign in to comment.