Skip to content

Commit

Permalink
Merge pull request #29 from placeTW/react_tests
Browse files Browse the repository at this point in the history
Regex tests
  • Loading branch information
chanomkaimuk authored Aug 13, 2023
2 parents a06f17d + f3adb9b commit 8b9926f
Show file tree
Hide file tree
Showing 4 changed files with 133 additions and 40 deletions.
33 changes: 3 additions & 30 deletions commands/react_baltics/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,10 @@

KEYWORDS = (
# Lithuanian
"Taivanas",
"Taivane",
"Taivano",
"Taivanui",
"Taivanietis",
"Taivanietė",
"Taivaniečiai",
r"Taivanieči(?:ų|u)",
"Taivaniečiui",
"Taivaniečiams",
"Taivanietiškas",
"Taivana",
r"Taivan(?:as|a|e|o|ui|ie(?:tiškas|tis|tė|či(?:ų|u|ai|ui|ams)))",
# Latvian
"Taivāna",
"Taivānā",
"Taivānas",
"Taivānai",
"Taivānu",
"Taivānietis",
"Taivāniete",
"Taivānisks",
"Taivāniešu",
"Taivānietim",
"Taivānietei",
"Taivāniešiem",
"Taivānieti",
"Taivāniete",
"Taivānieši",
"Taivānietes",
"Taivānieši",
# Estonian
r"Taivān(?:a|ā|as|u|isks|ie(?:tis|te|šu|tim|tei|šiem|ti|te|ši|tes|ši))",
# ! Estonian (STILL MISSING)
)


Expand Down
15 changes: 5 additions & 10 deletions commands/reacttw/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,12 @@
"KEELUNG",
"HSINCHU",
"CHIAYI",
"台灣",
"臺灣",
"臺北",
"台北",
r"(台|臺)灣",
"(台|臺)北",
"新北",
"桃園",
"臺中",
"台中",
"臺南",
"台南",
r"(台|臺)中",
r"(台|臺)南",
"高雄",
"新竹",
"苗栗",
Expand All @@ -61,8 +57,7 @@
"屏東",
"宜蘭",
"花蓮",
"臺東",
"台東",
r"(台|臺)東",
"澎湖",
"金門",
"連江",
Expand Down
54 changes: 54 additions & 0 deletions tests/test_react/test_react_baltics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
from commands.react_baltics.consts import BALTIC_REGEX
import pytest


@pytest.mark.parametrize(
"test_str",
(
# Lithuanian
"Taivanas",
"Taivane",
"Taivano",
"Taivanui",
"Taivanietis",
"Taivanietė",
"Taivaniečiai",
"Taivaniečiu",
"Taivaniečių",
"Taivaniečiui",
"Taivaniečiams",
"Taivanietiškas",
"Taivana",
# Latvian
"Taivāna",
"Taivānā",
"Taivānas",
"Taivānai",
"Taivānu",
"Taivānietis",
"Taivāniete",
"Taivānisks",
"Taivāniešu",
"Taivānietim",
"Taivānietei",
"Taivāniešiem",
"Taivānieti",
"Taivāniete",
"Taivānieši",
"Taivānietes",
"Taivānieši",
# ! Estonian (STILL MISSING)
),
)
def test_react_baltics_regex_yes_match(test_str: str):
"""Tests that these strings return TRUE."""
# * isolated string
assert BALTIC_REGEX.search(test_str)
# * surrounded by spaces
assert BALTIC_REGEX.search(f" {test_str} ")
# * surrounded by text
assert BALTIC_REGEX.search(f"a{test_str}b")
# * to lowercase
assert BALTIC_REGEX.search(test_str.lower())
# * to title case
assert BALTIC_REGEX.search(test_str.title())
71 changes: 71 additions & 0 deletions tests/test_react/test_react_tw.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
from commands.reacttw.consts import TW_REGEX
import pytest


@pytest.mark.parametrize(
"test_str",
(
"TAIWAN",
"FORMOSA",
"TAIPEI",
"TAOYUAN",
"TAICHUNG",
"TAINAN",
"KAOHSIUNG",
"MIAOLI",
"CHANGHUA",
"NANTOU",
"YUNLIN",
"PINGTUNG",
"YILAN",
"HUALIEN",
"TAITUNG",
"PENGHU",
"KINMEN",
"LIENCHIANG",
"KEELUNG",
"HSINCHU",
"CHIAYI",
"台灣",
"臺灣",
"臺北",
"台北",
"新北",
"桃園",
"臺中",
"台中",
"臺南",
"台南",
"高雄",
"新竹",
"苗栗",
"彰化",
"南投",
"雲林",
"嘉義",
"屏東",
"宜蘭",
"花蓮",
"臺東",
"台東",
"澎湖",
"金門",
"連江",
"基隆",
"新竹",
"嘉義",
"美麗島",
),
)
def test_react_tw_regex_yes_match(test_str: str):
"""Tests that these strings return TRUE."""
# * isolated string
assert TW_REGEX.search(test_str)
# * surrounded by spaces
assert TW_REGEX.search(f" {test_str} ")
# * surrounded by text
assert TW_REGEX.search(f"a{test_str}b")
# * to lowercase
assert TW_REGEX.search(test_str.lower())
# * to title case
assert TW_REGEX.search(test_str.title())

0 comments on commit 8b9926f

Please sign in to comment.