Skip to content

Commit

Permalink
町名が間違っている場合、クラッシュさせないようにした
Browse files Browse the repository at this point in the history
  • Loading branch information
YuukiToriyama committed Nov 23, 2023
1 parent 87e8abc commit 56c7a99
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ pub async fn parse<T: Api>(api: T, input: &str) -> ParsedAddress {
.await
.unwrap();
// 町名を特定
let (rest, town_name) = read_town(rest, city).unwrap();
let (rest, town_name) = match read_town(rest, city) {
None => return ParsedAddress::new(prefecture_name, city_name, "", rest),
Some(result) => result,
};

ParsedAddress::new(prefecture_name, city_name, town_name, rest)
}
Expand Down Expand Up @@ -79,6 +82,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]
Expand Down

0 comments on commit 56c7a99

Please sign in to comment.