-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
15dcb04
commit f84e47e
Showing
4 changed files
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from .utils.assert_string import assert_string | ||
from .utils.Classes.RegEx import RegEx | ||
|
||
|
||
def is_half_width(input: str) -> bool: | ||
input = assert_string(input) | ||
|
||
half_width_pattern = RegEx(r'[\u0020-\u007E\uFF61-\uFF9F\uFFA0-\uFFDC\uFFE8-\uFFEE0-9a-zA-Z]') | ||
|
||
return half_width_pattern.match(input) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import unittest | ||
from pyvalidator.is_half_width import is_half_width | ||
from . import print_test_ok | ||
|
||
class TestIsHalfWidth(unittest.TestCase): | ||
|
||
def test_valid_half_width(self): | ||
for i in [ | ||
'!"#$%&()<>/+=-_? ~^|.,@`{}[]', | ||
'l-btn_02--active', | ||
'abc123い', | ||
'カタカナ゙ᆲ←', | ||
'!"#$%&()<>/+=-_? ~^|.,@`{}[]' | ||
]: | ||
self.assertTrue(is_half_width(i)) | ||
print_test_ok() | ||
|
||
def test_invalid_half_width(self): | ||
for i in [ | ||
'3ー0 a@com' | ||
'あいうえお', | ||
'0011', | ||
'Ğood=Parts' | ||
]: | ||
self.assertFalse(is_half_width(i)) | ||
print_test_ok() | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |