-
-
Notifications
You must be signed in to change notification settings - Fork 2
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
1578870
commit 4372d0a
Showing
2 changed files
with
35 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import re | ||
from typing import Sequence, Union | ||
|
||
|
||
class HEX: | ||
@staticmethod | ||
def check(color: Union[str, Sequence[str], None]) -> bool: | ||
if color is None: | ||
return False | ||
|
||
assert type(color) == str | ||
regex = r"^#(?:[0-9a-fA-F]{3}){1,2}$" | ||
match = re.match(regex, color) | ||
|
||
return match is not None |
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,20 @@ | ||
from termspark.helpers.hex import HEX | ||
|
||
|
||
class TestHEX: | ||
def test_check(self): | ||
assert HEX.check("#000000") | ||
assert HEX.check("#ffffff") | ||
assert HEX.check("#FFFFFF") | ||
assert HEX.check("#2472c8") | ||
assert HEX.check("#2472C8") | ||
assert HEX.check("#000") | ||
assert HEX.check("#fff") | ||
assert HEX.check("#FFF") | ||
assert HEX.check("#ffg") == False | ||
assert HEX.check("#FFG") == False | ||
assert HEX.check("#FFFFFFF") == False | ||
assert HEX.check("#FF") == False | ||
assert HEX.check("#") == False | ||
assert HEX.check(None) == False | ||
assert HEX.check("") == False |