diff --git a/tests/test_parse.py b/tests/test_parse.py index 36c17a6..d89a185 100644 --- a/tests/test_parse.py +++ b/tests/test_parse.py @@ -87,6 +87,14 @@ self.location, ) + def __eq__(self, other): + return ( + self.value == other.value + and self.location.file == other.location.file + and self.location.line == other.location.line + and self.location.column == other.location.column + ) + # A soup of sample tokens class SampleSoup: @@ -252,20 +260,16 @@ @given(draw_token_soup()) def test_lexer_soup(soup): tokens = safe_tokenize(soup.code, "") + assert len(tokens) <= len(soup.tokens) in_pos = 0 out_pos = 0 - assert len(tokens) <= len(soup.tokens) - while out_pos < len(tokens): - if not soup.tokens[in_pos].type: - in_pos += 1 - else: - assert tokens[out_pos].type == soup.tokens[in_pos].type - assert tokens[out_pos].value == soup.tokens[in_pos].value - assert tokens[out_pos].location.file == soup.tokens[in_pos].location.file - assert tokens[out_pos].location.line == soup.tokens[in_pos].location.line - assert tokens[out_pos].location.column == soup.tokens[in_pos].location.column - in_pos += 1 + while in_pos < len(soup.tokens): + if soup.tokens[in_pos].type: + assert tokens[out_pos] == soup.tokens[in_pos] out_pos += 1 + in_pos += 1 + assert in_pos == len(soup.tokens) + assert out_pos == len(tokens) # General fuzz test, make sure the parser doesn't fall apart and spew