diff --git a/src/Normalizer.php b/src/Normalizer.php index 586a5e6..7c40222 100644 --- a/src/Normalizer.php +++ b/src/Normalizer.php @@ -818,7 +818,7 @@ public function toArray() $at = null; $shortAddress = null; - if (preg_match('/(?(^\d{5}|^\d{3})?)(?\D{2}[縣市])?(?\D+[鄉鎮市區])?(?\D+[村里])?(?.+[鄰])?(?\D+[路街大道])?(?.+[段])?(?.+[巷])?(?.+[弄])?(?.+[號])?(?.+[樓Ff])?(?[之-].+)?/u', $address, $matches) !== 0) { + if (preg_match('/(?(^\d{5}|^\d{3})?)(?\D{2}[縣市])?(?(\D{1,3}[^鄉鎮市區新](鄉|鎮|市|區)|\D{1,3}(鄉|鎮|市|區)))?(?\D+[村里])?(?.+[鄰])?(?\D+[路街大道])?(?.+[段])?(?.+[巷])?(?.+[弄])?(?.+[號])?(?.+[樓Ff])?(?[之-].+)?/u', $address, $matches) !== 0) { $zipcode = $this->arrayGet($matches, 'zipcode'); $county = $this->arrayGet($matches, 'county'); $district = $this->arrayGet($matches, 'district'); diff --git a/tests/NormalizerTest.php b/tests/NormalizerTest.php index 6717b66..ce202f6 100644 --- a/tests/NormalizerTest.php +++ b/tests/NormalizerTest.php @@ -63,4 +63,76 @@ public function test_normailize_taitung() 'at' => null, ]); } + + public function test_normailize_taipei_datong_district_civic_blvd() + { + $normalizer = new Normalizer('台北市大同區市民大道一段209號5樓'); + $this->assertSame($normalizer->toArray(), [ + 'county' => '臺北市', + 'district' => '大同區', + 'town' => '', + 'lin' => '', + 'road' => '市民大道', + 'sec' => '一段', + 'len' => '', + 'non' => '', + 'no' => '209號', + 'floor' => '5樓', + 'at' => null, + ]); + } + + public function test_normailize_district_only_two_words() + { + $normalizer = new Normalizer('新竹市東區西大路323號8樓'); + $this->assertSame($normalizer->toArray(), [ + 'county' => '新竹市', + 'district' => '東區', + 'town' => '', + 'lin' => '', + 'road' => '西大路', + 'sec' => '', + 'len' => '', + 'non' => '', + 'no' => '323號', + 'floor' => '8樓', + 'at' => null, + ]); + } + + public function test_normailize_kaohsiung_qianzhen() + { + $normalizer = new Normalizer('高雄市前鎮區中華五路789號'); + $this->assertSame($normalizer->toArray(), [ + 'county' => '高雄市', + 'district' => '前鎮區', + 'town' => '', + 'lin' => '', + 'road' => '中華五路', + 'sec' => '', + 'len' => '', + 'non' => '', + 'no' => '789號', + 'floor' => null, + 'at' => null, + ]); + } + + public function test_normailize_kinmen() + { + $normalizer = new Normalizer('金門縣金湖鎮新市里太湖路二段198號6樓'); + $this->assertSame($normalizer->toArray(), [ + 'county' => '金門縣', + 'district' => '金湖鎮', + 'town' => '新市里', + 'lin' => '', + 'road' => '太湖路', + 'sec' => '二段', + 'len' => '', + 'non' => '', + 'no' => '198號', + 'floor' => '6樓', + 'at' => null, + ]); + } } diff --git a/tests/TwzipcodeTest.php b/tests/TwzipcodeTest.php index 9c56be5..7daf6fe 100644 --- a/tests/TwzipcodeTest.php +++ b/tests/TwzipcodeTest.php @@ -57,4 +57,20 @@ public function test_taitung() $this->assertSame($twzipcode->getAddress(true), '臺東縣臺東市中正路100號'); $this->assertSame($twzipcode->getShortAddress(true), '中正路100號'); } + + public function test_taipei_datong_district_civic_blvd() + { + $twzipcode = new Twzipcode('台北市大同區市民大道一段209號5樓'); + $this->assertSame($twzipcode->getZipcode(), '103'); + $this->assertSame($twzipcode->getCounty(), '臺北市'); + $this->assertSame($twzipcode->getDistrict(), '大同區'); + $this->assertSame($twzipcode->getAddress(), '臺北市大同區市民大道一段209號5樓'); + $this->assertSame($twzipcode->getShortAddress(), '市民大道一段209號5樓'); + + $this->assertSame($twzipcode->getZipcode(true), '103'); + $this->assertSame($twzipcode->getCounty(true), '臺北市'); + $this->assertSame($twzipcode->getDistrict(true), '大同區'); + $this->assertSame($twzipcode->getAddress(true), '臺北市大同區市民大道一段209號5樓'); + $this->assertSame($twzipcode->getShortAddress(true), '市民大道一段209號5樓'); + } }