From b7f3596157095cb03270ae7cd46e6343cda07c83 Mon Sep 17 00:00:00 2001 From: Yuuki Toriyama Date: Sat, 13 Jan 2024 17:00:28 +0900 Subject: [PATCH 1/6] =?UTF-8?q?rename:=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`read=5Fhouse?= =?UTF-8?q?=5Fnumber()`=20->=20`read=5Fhouse=5Fnumber=5Fwith=5Fregex()`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/parser/read_house_number.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/parser/read_house_number.rs b/src/parser/read_house_number.rs index 4208ec13..acceec1b 100644 --- a/src/parser/read_house_number.rs +++ b/src/parser/read_house_number.rs @@ -1,8 +1,6 @@ -use regex::Regex; - #[allow(dead_code)] -pub fn read_house_number(input: &str) -> Option<(String, String)> { - let expression = Regex::new(r"(?\d+)\D*(?.*)$").unwrap(); +pub fn read_house_number_with_regex(input: &str) -> Option<(String, String)> { + let expression = regex::Regex::new(r"(?\d+)\D*(?.*)$").unwrap(); let captures = expression.captures(input)?; let house_number = if let Some(matched) = captures.name("house_number") { matched.as_str() @@ -19,18 +17,18 @@ pub fn read_house_number(input: &str) -> Option<(String, String)> { #[cfg(test)] mod read_house_number_tests { - use crate::parser::read_house_number::read_house_number; + use crate::parser::read_house_number::read_house_number_with_regex; #[test] fn read_house_number_1番() { - let (rest, house_number) = read_house_number("1").unwrap(); + let (rest, house_number) = read_house_number_with_regex("1").unwrap(); assert_eq!(house_number, "1番"); assert_eq!(rest, ""); } #[test] fn read_house_number_3番2() { - let (rest, house_number) = read_house_number("3-2").unwrap(); + let (rest, house_number) = read_house_number_with_regex("3-2").unwrap(); assert_eq!(house_number, "3番"); assert_eq!(rest, "2"); } From dbf76b1005c4ab12f5f50ef62340519f192c851d Mon Sep 17 00:00:00 2001 From: Yuuki Toriyama Date: Sat, 13 Jan 2024 17:01:12 +0900 Subject: [PATCH 2/6] =?UTF-8?q?rename:=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`read=5Fhouse?= =?UTF-8?q?=5Fnumber=5Ftests`=20->=20`tests`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/parser/read_house_number.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/parser/read_house_number.rs b/src/parser/read_house_number.rs index acceec1b..d6be5904 100644 --- a/src/parser/read_house_number.rs +++ b/src/parser/read_house_number.rs @@ -16,7 +16,7 @@ pub fn read_house_number_with_regex(input: &str) -> Option<(String, String)> { } #[cfg(test)] -mod read_house_number_tests { +mod tests { use crate::parser::read_house_number::read_house_number_with_regex; #[test] From 3b66817de1f8760ce2c718ea8cdf06044b221ce2 Mon Sep 17 00:00:00 2001 From: Yuuki Toriyama Date: Sat, 13 Jan 2024 17:02:27 +0900 Subject: [PATCH 3/6] =?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`read=5Fhouse?= =?UTF-8?q?=5Fnumber=5Fwith=5Fregex()`=E3=82=92private=E3=81=AB=E5=A4=89?= =?UTF-8?q?=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 現状使用されていないため --- src/parser/read_house_number.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/parser/read_house_number.rs b/src/parser/read_house_number.rs index d6be5904..e2d50c16 100644 --- a/src/parser/read_house_number.rs +++ b/src/parser/read_house_number.rs @@ -1,5 +1,5 @@ #[allow(dead_code)] -pub fn read_house_number_with_regex(input: &str) -> Option<(String, String)> { +fn read_house_number_with_regex(input: &str) -> Option<(String, String)> { let expression = regex::Regex::new(r"(?\d+)\D*(?.*)$").unwrap(); let captures = expression.captures(input)?; let house_number = if let Some(matched) = captures.name("house_number") { From 50eea0ca3d16fecb864d1c4de45165785876f4a8 Mon Sep 17 00:00:00 2001 From: Yuuki Toriyama Date: Sat, 13 Jan 2024 17:20:32 +0900 Subject: [PATCH 4/6] =?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`read=5Fhouse?= =?UTF-8?q?=5Fnumber=5Fwith=5Fjs=5Fsys=5Fregexp()`=E3=82=92=E5=AE=9A?= =?UTF-8?q?=E7=BE=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/parser/read_house_number.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/parser/read_house_number.rs b/src/parser/read_house_number.rs index e2d50c16..36ad9176 100644 --- a/src/parser/read_house_number.rs +++ b/src/parser/read_house_number.rs @@ -15,6 +15,18 @@ fn read_house_number_with_regex(input: &str) -> Option<(String, String)> { Some((rest.to_string(), format!("{}番", house_number))) } +#[allow(dead_code)] +fn read_house_number_with_js_sys_regexp(input: &str) -> Option<(String, String)> { + let expression = js_sys::RegExp::new(r"(?\d+)\D*(?.*)$", ""); + let captures = expression.exec(input)?; + let house_number = captures.get(1).as_string()?; + let rest = captures + .get(2) + .as_string() + .unwrap_or_else(|| "".to_string()); + Some((rest, format!("{}番", house_number))) +} + #[cfg(test)] mod tests { use crate::parser::read_house_number::read_house_number_with_regex; From a7fecb0f0da3620757d27a1c549a17f699957d77 Mon Sep 17 00:00:00 2001 From: Yuuki Toriyama Date: Sat, 13 Jan 2024 17:23:40 +0900 Subject: [PATCH 5/6] =?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=E3=82=BF?= =?UTF-8?q?=E3=83=BC=E3=82=B2=E3=83=83=E3=83=88=E8=A8=AD=E5=AE=9A=E3=82=92?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/parser/read_house_number.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/parser/read_house_number.rs b/src/parser/read_house_number.rs index 36ad9176..8b12b2b2 100644 --- a/src/parser/read_house_number.rs +++ b/src/parser/read_house_number.rs @@ -1,4 +1,5 @@ #[allow(dead_code)] +#[cfg(not(target_arch = "wasm32"))] fn read_house_number_with_regex(input: &str) -> Option<(String, String)> { let expression = regex::Regex::new(r"(?\d+)\D*(?.*)$").unwrap(); let captures = expression.captures(input)?; @@ -16,6 +17,7 @@ fn read_house_number_with_regex(input: &str) -> Option<(String, String)> { } #[allow(dead_code)] +#[cfg(target_arch = "wasm32")] fn read_house_number_with_js_sys_regexp(input: &str) -> Option<(String, String)> { let expression = js_sys::RegExp::new(r"(?\d+)\D*(?.*)$", ""); let captures = expression.exec(input)?; @@ -27,7 +29,7 @@ fn read_house_number_with_js_sys_regexp(input: &str) -> Option<(String, String)> Some((rest, format!("{}番", house_number))) } -#[cfg(test)] +#[cfg(all(test, not(target_arch = "wasm32")))] mod tests { use crate::parser::read_house_number::read_house_number_with_regex; From e0d860b7335282747481d25b8d8d15f1d1f129ae Mon Sep 17 00:00:00 2001 From: Yuuki Toriyama Date: Sat, 13 Jan 2024 17:24:47 +0900 Subject: [PATCH 6/6] =?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`wasm=5Ftests`?= =?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 `read_house_number_with_js_sys_regexp()`に対するテストコードを追加 --- src/parser/read_house_number.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/parser/read_house_number.rs b/src/parser/read_house_number.rs index 8b12b2b2..b9d1960a 100644 --- a/src/parser/read_house_number.rs +++ b/src/parser/read_house_number.rs @@ -47,3 +47,22 @@ mod tests { assert_eq!(rest, "2"); } } + +#[cfg(all(test, target_arch = "wasm32"))] +mod wasm_tests { + use crate::parser::read_house_number::read_house_number_with_js_sys_regexp; + use wasm_bindgen_test::{wasm_bindgen_test, wasm_bindgen_test_configure}; + + wasm_bindgen_test_configure!(run_in_browser); + + #[wasm_bindgen_test] + fn read_house_number_with_js_sys_regexp_success() { + let (rest, house_number) = read_house_number_with_js_sys_regexp("1").unwrap(); + assert_eq!(house_number, "1番"); + assert_eq!(rest, ""); + + let (rest, house_number) = read_house_number_with_js_sys_regexp("3-2").unwrap(); + assert_eq!(house_number, "3番"); + assert_eq!(rest, "2"); + } +}