From 87e8abc88995e46009ef3ba600f00e92d63f36ff Mon Sep 17 00:00:00 2001 From: Yuuki Toriyama Date: Thu, 23 Nov 2023 19:46:19 +0900 Subject: [PATCH] =?UTF-8?q?=E5=B8=82=E7=94=BA=E6=9D=91=E5=90=8D=E3=81=8C?= =?UTF-8?q?=E9=96=93=E9=81=95=E3=81=A3=E3=81=A6=E3=81=84=E3=82=8B=E5=A0=B4?= =?UTF-8?q?=E5=90=88=E3=80=81=E3=82=AF=E3=83=A9=E3=83=83=E3=82=B7=E3=83=A5?= =?UTF-8?q?=E3=81=95=E3=81=9B=E3=81=AA=E3=81=84=E3=82=88=E3=81=86=E3=81=AB?= =?UTF-8?q?=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/parser.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/parser.rs b/src/parser.rs index 7951b0ff..f7a80dd8 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -17,7 +17,10 @@ pub async fn parse(api: T, input: &str) -> ParsedAddress { // その都道府県の市町村名リストを取得 let prefecture = api.get_prefecture_master(prefecture_name).await.unwrap(); // 市町村名を特定 - let (rest, city_name) = read_city(rest, prefecture).unwrap(); + let (rest, city_name) = match read_city(rest, prefecture) { + None => return ParsedAddress::new(prefecture_name, "", "", rest), + Some(result) => result, + }; // その市町村の町名リストを取得 let city = api .get_city_master(prefecture_name, city_name) @@ -66,6 +69,16 @@ mod parser_tests { assert_eq!(address.rest, "神奈側県平塚市桜ケ丘100-1".to_string()); } + #[tokio::test] + async fn parse_mocked_fail_市町村名が間違っている場合() { + let api = ApiMock { should_fail: false }; + let address = parse(api, "神奈川県平束市桜ケ丘100-1").await; + assert_eq!(address.prefecture, "神奈川県".to_string()); + assert_eq!(address.city, "".to_string()); + assert_eq!(address.town, "".to_string()); + assert_eq!(address.rest, "平束市桜ケ丘100-1".to_string()); + } + wasm_bindgen_test_configure!(run_in_browser); #[wasm_bindgen_test]