From 8d4c69aefec32acdb8843a58b6db1659fac6d93b Mon Sep 17 00:00:00 2001 From: Yuuki Toriyama Date: Sat, 20 Jan 2024 20:04:24 +0900 Subject: [PATCH 1/8] =?UTF-8?q?update:=20JS=E5=81=B4=E3=81=AERegExp?= =?UTF-8?q?=E3=82=92=E4=BD=BF=E7=94=A8=E3=81=99=E3=82=8B:=20`extract=5Ftow?= =?UTF-8?q?n=5Fname=5Fwith=5Fjs=5Fsys=5Fregexp()`=E3=81=8CNone=E3=82=92?= =?UTF-8?q?=E8=BF=94=E3=81=99=E5=A0=B4=E5=90=88=E3=81=AE=E3=83=86=E3=82=B9?= =?UTF-8?q?=E3=83=88=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit リファクタリングのデグレ確認に使用するため --- src/parser/filter/invalid_town_name_format.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/parser/filter/invalid_town_name_format.rs b/src/parser/filter/invalid_town_name_format.rs index f633bc7a..57263d48 100644 --- a/src/parser/filter/invalid_town_name_format.rs +++ b/src/parser/filter/invalid_town_name_format.rs @@ -104,4 +104,13 @@ mod wasm_tests { assert!(result.is_some()); assert_eq!(result.unwrap(), "有楽町一丁目1-2"); } + + #[wasm_bindgen_test] + fn extract_town_name_with_js_sys_regexp_fail() { + let result = extract_town_name_with_js_sys_regexp("1-1"); + assert!(result.is_none()); + + let result = extract_town_name_with_js_sys_regexp("有楽町"); + assert!(result.is_none()); + } } From fed42267ae4be336596372929e878f00f6746f08 Mon Sep 17 00:00:00 2001 From: Yuuki Toriyama Date: Sat, 20 Jan 2024 20:12:21 +0900 Subject: [PATCH 2/8] =?UTF-8?q?update:=20JS=E5=81=B4=E3=81=AERegExp?= =?UTF-8?q?=E3=82=92=E4=BD=BF=E7=94=A8=E3=81=99=E3=82=8B:=20`unwrap()`?= =?UTF-8?q?=E3=82=92`ok()=3F`=E3=81=AB=E6=9B=B8=E3=81=8D=E6=8F=9B=E3=81=88?= =?UTF-8?q?=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/parser/filter/invalid_town_name_format.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/parser/filter/invalid_town_name_format.rs b/src/parser/filter/invalid_town_name_format.rs index 57263d48..36333df8 100644 --- a/src/parser/filter/invalid_town_name_format.rs +++ b/src/parser/filter/invalid_town_name_format.rs @@ -53,7 +53,7 @@ fn extract_town_name_with_js_sys_regexp(input: &str) -> Option { None => return None, }; let block_number = match captures.get(2).as_string() { - Some(matched) => matched.parse::().unwrap().to_japanese_form()?, + Some(matched) => matched.parse::().ok()?.to_japanese_form()?, None => return None, }; let rest = captures From f2cd308d41922d1cd5a5f902b26b2f2bf1595e18 Mon Sep 17 00:00:00 2001 From: Yuuki Toriyama Date: Sat, 20 Jan 2024 20:18:02 +0900 Subject: [PATCH 3/8] =?UTF-8?q?update:=20JS=E5=81=B4=E3=81=AERegExp?= =?UTF-8?q?=E3=82=92=E4=BD=BF=E7=94=A8=E3=81=99=E3=82=8B:=20match=E5=BC=8F?= =?UTF-8?q?=E3=82=92`=3F`=E3=81=A7=E6=9B=B8=E3=81=8D=E6=8F=9B=E3=81=88?= =?UTF-8?q?=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/parser/filter/invalid_town_name_format.rs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/parser/filter/invalid_town_name_format.rs b/src/parser/filter/invalid_town_name_format.rs index 36333df8..c036b61f 100644 --- a/src/parser/filter/invalid_town_name_format.rs +++ b/src/parser/filter/invalid_town_name_format.rs @@ -48,14 +48,13 @@ fn extract_town_name_with_js_sys_regexp(input: &str) -> Option { "", ); let captures = expression.exec(input)?; - let town_name = match captures.get(1).as_string() { - Some(matched) => matched, - None => return None, - }; - let block_number = match captures.get(2).as_string() { - Some(matched) => matched.parse::().ok()?.to_japanese_form()?, - None => return None, - }; + let town_name = captures.get(1).as_string()?; + let block_number = captures + .get(2) + .as_string()? + .parse::() + .ok()? + .to_japanese_form()?; let rest = captures .get(3) .as_string() From aaf362f7ee902fce8870d0134fb7947a6b04bde2 Mon Sep 17 00:00:00 2001 From: Yuuki Toriyama Date: Sat, 20 Jan 2024 20:21:10 +0900 Subject: [PATCH 4/8] =?UTF-8?q?update:=20JS=E5=81=B4=E3=81=AERegExp?= =?UTF-8?q?=E3=82=92=E4=BD=BF=E7=94=A8=E3=81=99=E3=82=8B:=20=E6=AD=A3?= =?UTF-8?q?=E8=A6=8F=E8=A1=A8=E7=8F=BE=E3=82=92=E7=B0=A1=E7=95=A5=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 名前付きキャプチャグループは使用しないので削除 --- src/parser/filter/invalid_town_name_format.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/parser/filter/invalid_town_name_format.rs b/src/parser/filter/invalid_town_name_format.rs index c036b61f..e7ce9ca9 100644 --- a/src/parser/filter/invalid_town_name_format.rs +++ b/src/parser/filter/invalid_town_name_format.rs @@ -43,10 +43,7 @@ fn extract_town_name_with_regex(input: &str) -> Option { #[cfg(target_arch = "wasm32")] fn extract_town_name_with_js_sys_regexp(input: &str) -> Option { - let expression = js_sys::RegExp::new( - r"^(?\D+)(?\d+)[-ー-]*(?.*)$", - "", - ); + let expression = js_sys::RegExp::new(r"^(\D+)(\d+)[-ー-]*(.*)$", ""); let captures = expression.exec(input)?; let town_name = captures.get(1).as_string()?; let block_number = captures From ec3cd3bbc8241ead931c0695ac94d1cc8d06ef83 Mon Sep 17 00:00:00 2001 From: Yuuki Toriyama Date: Sat, 20 Jan 2024 20:28:54 +0900 Subject: [PATCH 5/8] =?UTF-8?q?update:=20JS=E5=81=B4=E3=81=AERegExp?= =?UTF-8?q?=E3=82=92=E4=BD=BF=E7=94=A8=E3=81=99=E3=82=8B:=20`filter=5Fwith?= =?UTF-8?q?=5Fjs=5Fsys=5Fregexp()`=E3=81=AB=E5=AF=BE=E3=81=99=E3=82=8B?= =?UTF-8?q?=E3=83=86=E3=82=B9=E3=83=88=E9=96=A2=E6=95=B0=E3=81=AE=E5=91=BD?= =?UTF-8?q?=E5=90=8D=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit success/failではなくより実情にそぐうものに変更 --- src/parser/filter/non_kanji_block_number.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/parser/filter/non_kanji_block_number.rs b/src/parser/filter/non_kanji_block_number.rs index 1e714ebe..7b5dcbd1 100644 --- a/src/parser/filter/non_kanji_block_number.rs +++ b/src/parser/filter/non_kanji_block_number.rs @@ -82,13 +82,13 @@ mod wasm_tests { wasm_bindgen_test_configure!(run_in_browser); #[wasm_bindgen_test] - fn filter_with_js_sys_regexp_success() { + fn filter_with_js_sys_regexp_input_value_will_be_filtered() { let result = filter_with_js_sys_regexp("銀座1丁目".to_string()); assert_eq!(result, "銀座一丁目"); } #[wasm_bindgen_test] - fn filter_with_js_sys_regexp_fail() { + fn filter_with_js_sys_regexp_return_original_value() { let result = filter_with_js_sys_regexp("銀座1丁目".to_string()); assert_ne!(result, "銀座一丁目"); } From 60e1534c0bf953b246d916f09f67c382c9cedcb0 Mon Sep 17 00:00:00 2001 From: Yuuki Toriyama Date: Sat, 20 Jan 2024 20:38:29 +0900 Subject: [PATCH 6/8] =?UTF-8?q?update:=20JS=E5=81=B4=E3=81=AERegExp?= =?UTF-8?q?=E3=82=92=E4=BD=BF=E7=94=A8=E3=81=99=E3=82=8B:=20`filter=5Fwith?= =?UTF-8?q?=5Fjs=5Fsys=5Fregexp()`=E3=81=AB=E5=AF=BE=E3=81=99=E3=82=8B?= =?UTF-8?q?=E3=83=86=E3=82=B9=E3=83=88=E3=81=AB=E3=82=B1=E3=83=BC=E3=82=B9?= =?UTF-8?q?=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/parser/filter/non_kanji_block_number.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/parser/filter/non_kanji_block_number.rs b/src/parser/filter/non_kanji_block_number.rs index 7b5dcbd1..784e696a 100644 --- a/src/parser/filter/non_kanji_block_number.rs +++ b/src/parser/filter/non_kanji_block_number.rs @@ -85,11 +85,17 @@ mod wasm_tests { fn filter_with_js_sys_regexp_input_value_will_be_filtered() { let result = filter_with_js_sys_regexp("銀座1丁目".to_string()); assert_eq!(result, "銀座一丁目"); + + let result = filter_with_js_sys_regexp("銀座1丁目1-1".to_string()); + assert_eq!(result, "銀座一丁目1-1"); } #[wasm_bindgen_test] fn filter_with_js_sys_regexp_return_original_value() { - let result = filter_with_js_sys_regexp("銀座1丁目".to_string()); - assert_ne!(result, "銀座一丁目"); + let result = filter_with_js_sys_regexp("銀座A丁目".to_string()); + assert_eq!(result, "銀座A丁目"); + + let result = filter_with_js_sys_regexp("銀座2147483648丁目".to_string()); + assert_eq!(result, "銀座2147483648丁目"); } } From 7fbb8f2b7077c94a53f0c75ac13d3cd8ef083568 Mon Sep 17 00:00:00 2001 From: Yuuki Toriyama Date: Sat, 20 Jan 2024 20:53:23 +0900 Subject: [PATCH 7/8] =?UTF-8?q?update:=20JS=E5=81=B4=E3=81=AERegExp?= =?UTF-8?q?=E3=82=92=E4=BD=BF=E7=94=A8=E3=81=99=E3=82=8B:=20`to=5Fjapanese?= =?UTF-8?q?=5Fform()`=E3=81=AE=E5=91=BC=E3=81=B3=E5=87=BA=E3=81=97?= =?UTF-8?q?=E7=AE=87=E6=89=80=E3=81=AB=E3=82=A8=E3=83=A9=E3=83=BC=E3=83=8F?= =?UTF-8?q?=E3=83=B3=E3=83=89=E3=83=AA=E3=83=B3=E3=82=B0=E3=82=92=E8=BF=BD?= =?UTF-8?q?=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/parser/filter/non_kanji_block_number.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/parser/filter/non_kanji_block_number.rs b/src/parser/filter/non_kanji_block_number.rs index 784e696a..b09fcc55 100644 --- a/src/parser/filter/non_kanji_block_number.rs +++ b/src/parser/filter/non_kanji_block_number.rs @@ -47,11 +47,11 @@ fn filter_with_js_sys_regexp(input: String) -> String { Ok(x) => x, Err(_) => return input, }; - input.replacen( - &capture_block_number, - block_number.to_japanese_form().unwrap().as_str(), - 1, - ) + let block_number_in_japanese_form = match block_number.to_japanese_form() { + Some(x) => x, + None => return input, + }; + input.replacen(&capture_block_number, &block_number_in_japanese_form, 1) } None => input, } From 0d24d8101d7fbee0b378698c7b8ec1337c0f629d Mon Sep 17 00:00:00 2001 From: Yuuki Toriyama Date: Sat, 20 Jan 2024 20:54:19 +0900 Subject: [PATCH 8/8] =?UTF-8?q?update:=20JS=E5=81=B4=E3=81=AERegExp?= =?UTF-8?q?=E3=82=92=E4=BD=BF=E7=94=A8=E3=81=99=E3=82=8B:=20=E6=AD=A3?= =?UTF-8?q?=E8=A6=8F=E8=A1=A8=E7=8F=BE=E3=82=92=E7=B0=A1=E7=95=A5=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 名前付きキャプチャグループは使用しないので削除 --- src/parser/filter/non_kanji_block_number.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/parser/filter/non_kanji_block_number.rs b/src/parser/filter/non_kanji_block_number.rs index b09fcc55..64d9cfa9 100644 --- a/src/parser/filter/non_kanji_block_number.rs +++ b/src/parser/filter/non_kanji_block_number.rs @@ -36,7 +36,7 @@ fn filter_with_regex(input: String) -> String { #[cfg(target_arch = "wasm32")] fn filter_with_js_sys_regexp(input: String) -> String { - let expression = js_sys::RegExp::new(r"\D+(?\d+)丁目", ""); + let expression = js_sys::RegExp::new(r"\D+(\d+)丁目", ""); match expression.exec(&input) { Some(result) => { let capture_block_number = match result.get(1).as_string() {