diff --git a/tests/parse/test_reference.py b/tests/parse/test_reference.py index f7d13d0..ec3d1eb 100644 --- a/tests/parse/test_reference.py +++ b/tests/parse/test_reference.py @@ -1,11 +1,13 @@ # SPDX-License-Identifier: LGPL-2.1-only # Copyright 2022 Jookia +from hypothesis import given from hypothesis.strategies import composite from src.ast_types import Reference from src.parse import ParseContext, ParseError, ParseErrorException, ParseTask, Parser -from tests.parse.templates import template_parse_valid, template_parse_invalid +from tests.parse.templates import template_test_valid, template_test_invalid +from tests.parse.test_error import static_parse_context from tests.test_token import draw_token_known, draw_token_unknown @@ -19,10 +21,11 @@ # Tests parse_reference works correctly # We expect the following behaviour: # - The resulting reference has the token's value -# template_parse_valid provides general parsing properties -@template_parse_valid(Parser().parse_reference, draw_token_reference_valid()) -def test_parse_reference_valid(): - pass +# template_test_valid provides general parsing properties +@given(draw_token_reference_valid()) +def test_parse_reference_valid(valid_data): + (tokens, expected) = valid_data + template_test_valid(Parser().parse_reference, tokens, expected) # Tests parsing a reference with a reserved name errors @@ -30,12 +33,12 @@ # - Error if a keyword or literal is encountered # - Have ParseError.RESERVED_NAME as the exception code # - Have ParseTask.PARSE_REFERENCE as the context's parse task -@template_parse_invalid(Parser().parse_reference) -def test_parse_reference_invalid_name(draw, parent_context): - token = draw(draw_token_known()) +@given(draw_token_known()) +def test_parse_reference_invalid_name(token): + parent_context = static_parse_context() context = ParseContext(ParseTask.PARSE_REFERENCE, token, parent_context) error = ParseErrorException(ParseError.RESERVED_NAME, token, None, context) - return ([token], error) + template_test_invalid(Parser().parse_reference, parent_context, [token], error) # Tests parsing of empty references @@ -43,8 +46,8 @@ # - Error if there isn't a token # - Have ParseError.NO_TOKEN as the exception code # - Have ParseTask.PARSE_REFERENCE as the context's parse task -@template_parse_invalid(Parser().parse_reference) -def test_parse_reference_invalid_empty(draw, parent_context): +def test_parse_reference_invalid_empty(): + parent_context = static_parse_context() context = ParseContext(ParseTask.PARSE_REFERENCE, None, parent_context) error = ParseErrorException(ParseError.NO_TOKEN, None, None, context) - return ([], error) + template_test_invalid(Parser().parse_reference, parent_context, [], error)