diff --git a/tests/parse/test_value.py b/tests/parse/test_value.py index 1edda58..f05b936 100644 --- a/tests/parse/test_value.py +++ b/tests/parse/test_value.py @@ -3,11 +3,12 @@ import enum -from hypothesis import assume +from hypothesis import assume, given from hypothesis.strategies import composite, just, one_of 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_keyword, draw_token_unknown, @@ -75,7 +76,7 @@ return ([token], ParserMockAction.PARSE_REFERENCE) -# Draws tokens for a valid value +# Draws tokens and valid value for a valid value @composite def draw_token_value_valid(draw): strategies = [ @@ -89,19 +90,21 @@ # We expect the following behaviour: # - parse_value parses a Bool if it sees True or False # - parse_value parses a Text if it sees StartText -# template_parse_valid provides general parsing properties -@template_parse_valid(ParserValueMockValid().parse_value, draw_token_value_literal()) -def test_parse_value_literal(): - pass +# template_test_valid provides general parsing properties +@given(draw_token_value_literal()) +def test_parse_value_literal(literal): + (tokens, expected) = literal + template_test_valid(ParserValueMockValid().parse_value, tokens, expected) # Tests parsing a reference value # We expect the following behaviour: # - parse_value parses a Reference if it sees an unknown value -# template_parse_valid provides general parsing properties -@template_parse_valid(ParserValueMockValid().parse_value, draw_token_value_reference()) -def test_parse_value_reference(): - pass +# template_test_valid provides general parsing properties +@given(draw_token_value_reference()) +def test_parse_value_reference(reference): + (tokens, expected) = reference + template_test_valid(ParserValueMockValid().parse_value, tokens, expected) # Tests parsing a keyword as a value fails @@ -109,33 +112,36 @@ # - Error if a keyword is encountered # - Have ParseError.RESERVED_NAME as the exception code # - Have ParseTask.PARSE_VALUE as the context's parse task -@template_parse_invalid(Parser().parse_value) -def test_parse_value_invalid_name(draw, parent_context): - token = draw(draw_token_keyword()) +@given(draw_token_keyword()) +def test_parse_value_invalid_name(token): assume(token.value != "StartText") + parent_context = static_parse_context() context = ParseContext(ParseTask.PARSE_VALUE, token, parent_context) error = ParseErrorException(ParseError.RESERVED_NAME, token, None, context) - return ([token], error) + template_test_invalid(Parser().parse_value, parent_context, [token], error) # Tests parsing empty value # We expect the following behaviour: # - Have ParseError.NO_TOKEN as the exception code # - Have ParseTask.PARSE_VALUE as the context's parse task -@template_parse_invalid(Parser().parse_value) -def test_parse_value_invalid_empty(draw, parent_context): +def test_parse_value_invalid_empty(): + parent_context = static_parse_context() context = ParseContext(ParseTask.PARSE_VALUE, None, parent_context) error = ParseErrorException(ParseError.NO_TOKEN, None, None, context) - return ([], error) + template_test_invalid(Parser().parse_value, parent_context, [], error) # Tests parse_value error propagation # We expect the following behaviour: # - Errors from parsing are propagated and have the correct context # - Have ParseTask.PARSE_VALUE as the context's parse task -@template_parse_invalid(ParserValueMockError().parse_value) -def test_parse_value_error_propagation(draw, parent_context): - (tokens, action) = draw(draw_token_value_valid()) +@given(draw_token_value_valid()) +def test_parse_value_error_propagation(valid_data): + (tokens, action) = valid_data + parent_context = static_parse_context() context = ParseContext(ParseTask.PARSE_VALUE, tokens[0], parent_context) error = ParseErrorException(action, None, None, context) - return (tokens, error) + template_test_invalid( + ParserValueMockError().parse_value, parent_context, tokens, error + )