Skip to content

Commit

Permalink
Make identifier case insensitive
Browse files Browse the repository at this point in the history
Ref. #520
  • Loading branch information
treiher committed Dec 7, 2020
1 parent 1ef3242 commit 04e38dd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
9 changes: 7 additions & 2 deletions rflx/identifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ def __init__(

def __eq__(self, other: object) -> bool:
if isinstance(other, self.__class__):
return self.parts == other.parts
if len(self.parts) != len(other.parts):
return False
for s, o in zip(self.parts, other.parts):
if s.lower() != o.lower():
return False
return True
return NotImplemented

def __lt__(self, other: object) -> bool:
Expand All @@ -36,7 +41,7 @@ def __lt__(self, other: object) -> bool:
return NotImplemented

def __hash__(self) -> int:
return hash(tuple(self.parts))
return hash(tuple(map(str.lower, self.parts)))

def __repr__(self) -> str:
return f'ID("{self}")'
Expand Down
8 changes: 8 additions & 0 deletions tests/unit/identifier_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ def test_id_invalid_colon() -> None:
ID("A::B:C::D")


def test_id_eq() -> None:
assert ID("A") == ID("a")


def test_id_hash() -> None:
assert hash(ID("A")) == hash(ID("a"))


def test_id_str() -> None:
assert str(ID("A::B::C")) == "A::B::C"

Expand Down

0 comments on commit 04e38dd

Please sign in to comment.