# SPDX-License-Identifier: LGPL-2.1-only # Copyright 2022 Jookia <contact@jookia.org> from hypothesis import given from hypothesis.strategies import ( composite, lists, ) from src import tokenize from src import parse from tests import test_tokenize # Draws random tokens and a list without whitespace in them @composite def draw_tokens_whitespace(draw): input = draw(lists(test_tokenize.draw_token_random())) tokens = [] for t in input: if t.type not in [tokenize.TokenType.SPACE, tokenize.TokenType.NEWLINE]: tokens.append(t) return (input, tokens) # Tests is remove_whitespace works correctly # We expect the following behaviour: # - No tokens are modified # - Tokens of type SPACE or NEWLINE are removed from the output @given(draw_tokens_whitespace()) def test_parse_remove_whitespace(test_data): (input, tokens) = test_data assert parse.remove_whitespace(input) == tokens # Tests the parser wrapper works correctly # We expect the following behaviour: # - Whitespace tokens are removed @given(lists(test_tokenize.draw_token_random())) def test_parse_fuzz(tokens): stripped = parse.remove_whitespace(tokens) parsed = parse.parse(tokens) assert stripped == parsed