diff --git a/tests/parse/test_bool.py b/tests/parse/test_bool.py index 47aadda..dd5d4ca 100644 --- a/tests/parse/test_bool.py +++ b/tests/parse/test_bool.py @@ -2,7 +2,7 @@ # Copyright 2022 Jookia from hypothesis import assume -from hypothesis.strategies import booleans, composite +from hypothesis.strategies import composite from src.parse import ParseContext, ParseError, ParseErrorException, ParseTask, Parser from src.syntax import Syntax, SyntaxType @@ -33,24 +33,27 @@ # Generate an invalid boolean # We expect the following behaviour: -# - Error if there isn't a token # - Error if the token is not a SyntaxType.TOKEN # - Error if the token is not True or False @template_parse_invalid(Parser().parse_bool) -def test_parse_bool_invalid(draw): +def test_parse_bool_invalid_incorrect(draw): parent_context = draw(draw_parse_context()) - if draw(booleans()): - token = draw(draw_syntax_random()) - assume( - not (token.type == SyntaxType.TOKEN and token.value in ["True", "False"]) - ) - context = ParseContext(ParseTask.PARSE_BOOL, token, parent_context) - if token.type == SyntaxType.TOKEN: - error = ParseErrorException(ParseError.NOT_BOOL, token, None, context) - else: - error = ParseErrorException(ParseError.NOT_TOKEN, token, None, context) - return ([token], error, parent_context) + token = draw(draw_syntax_random()) + assume(not (token.type == SyntaxType.TOKEN and token.value in ["True", "False"])) + context = ParseContext(ParseTask.PARSE_BOOL, token, parent_context) + if token.type == SyntaxType.TOKEN: + error = ParseErrorException(ParseError.NOT_BOOL, token, None, context) else: - context = ParseContext(ParseTask.PARSE_BOOL, None, parent_context) - error = ParseErrorException(ParseError.NO_TOKEN, None, None, context) - return ([], error, parent_context) + error = ParseErrorException(ParseError.NOT_TOKEN, token, None, context) + return ([token], error, parent_context) + + +# Generate no boolean +# We expect the following behaviour: +# - Error if there isn't a token +@template_parse_invalid(Parser().parse_bool) +def test_parse_bool_invalid_empty(draw): + parent_context = draw(draw_parse_context()) + context = ParseContext(ParseTask.PARSE_BOOL, None, parent_context) + error = ParseErrorException(ParseError.NO_TOKEN, None, None, context) + return ([], error, parent_context) diff --git a/tests/parse/test_note.py b/tests/parse/test_note.py index 221d828..cb888d4 100644 --- a/tests/parse/test_note.py +++ b/tests/parse/test_note.py @@ -3,7 +3,6 @@ from hypothesis import assume from hypothesis.strategies import ( - booleans, composite, lists, ) @@ -58,29 +57,32 @@ # Generate note without StartNote # We expect the following behaviour: -# - Error if there is no StartNote node at all # - Error if StartNote is not a SyntaxType.TOKEN # - Error if StartNote's token value is not "StartNote" @template_parse_invalid(NoteSkipper().skip_note) -def test_parse_note_invalid_nostartnote(draw): +def test_parse_note_invalid_incorrect(draw): (tokens, _) = draw(draw_syntax_note_valid()) parent_context = draw(draw_parse_context()) - if draw(booleans()): - token = draw(draw_syntax_random()) - assume(not (token.type == SyntaxType.TOKEN and token.value == "StartNote")) - new_tokens = [token] + tokens[1:0] - context = ParseContext(ParseTask.PARSE_NOTE, new_tokens[0], parent_context) - if token.type == SyntaxType.TOKEN: - error = ParseErrorException( - ParseError.WRONG_TOKEN, token, "StartNote", context - ) - else: - error = ParseErrorException(ParseError.NOT_TOKEN, token, None, context) - return (new_tokens, error, parent_context) + token = draw(draw_syntax_random()) + assume(not (token.type == SyntaxType.TOKEN and token.value == "StartNote")) + new_tokens = [token] + tokens[1:0] + context = ParseContext(ParseTask.PARSE_NOTE, new_tokens[0], parent_context) + if token.type == SyntaxType.TOKEN: + error = ParseErrorException(ParseError.WRONG_TOKEN, token, "StartNote", context) else: - context = ParseContext(ParseTask.PARSE_NOTE, None, parent_context) - error = ParseErrorException(ParseError.NO_TOKEN, None, None, context) - return ([], error, parent_context) + error = ParseErrorException(ParseError.NOT_TOKEN, token, None, context) + return (new_tokens, error, parent_context) + + +# Generate no note +# We expect the following behaviour: +# - Error if there is no StartNote node at all +@template_parse_invalid(NoteSkipper().skip_note) +def test_parse_note_invalid_empty(draw): + parent_context = draw(draw_parse_context()) + context = ParseContext(ParseTask.PARSE_NOTE, None, parent_context) + error = ParseErrorException(ParseError.NO_TOKEN, None, None, context) + return ([], error, parent_context) # Generate note with a StartNote token in it diff --git a/tests/parse/test_text.py b/tests/parse/test_text.py index f18d760..0f1178d 100644 --- a/tests/parse/test_text.py +++ b/tests/parse/test_text.py @@ -3,7 +3,6 @@ from hypothesis import assume from hypothesis.strategies import ( - booleans, composite, lists, ) @@ -66,29 +65,33 @@ # Generate text without StartText # We expect the following behaviour: -# - Error if there is no StartText node at all # - Error if StartText is not a SyntaxType.TOKEN # - Error if StartText's token value is not "StartText" @template_parse_invalid(Parser().parse_text) -def test_parse_text_invalid_nostarttext(draw): +def test_parse_text_invalid_incorrect(draw): (tokens, _) = draw(draw_syntax_text_valid()) parent_context = draw(draw_parse_context()) - if draw(booleans()): - token = draw(draw_syntax_random()) - assume(not (token.type == SyntaxType.TOKEN and token.value == "StartText")) - new_tokens = [token] + tokens[1:0] - context = ParseContext(ParseTask.PARSE_TEXT, new_tokens[0], parent_context) - if token.type == SyntaxType.TOKEN: - error = ParseErrorException( - ParseError.WRONG_TOKEN, token, "StartText", context - ) - else: - error = ParseErrorException(ParseError.NOT_TOKEN, token, None, context) - return (new_tokens, error, parent_context) + token = draw(draw_syntax_random()) + assume(not (token.type == SyntaxType.TOKEN and token.value == "StartText")) + new_tokens = [token] + tokens[1:0] + context = ParseContext(ParseTask.PARSE_TEXT, new_tokens[0], parent_context) + if token.type == SyntaxType.TOKEN: + error = ParseErrorException(ParseError.WRONG_TOKEN, token, "StartText", context) else: - context = ParseContext(ParseTask.PARSE_TEXT, None, parent_context) - error = ParseErrorException(ParseError.NO_TOKEN, None, None, context) - return ([], error, parent_context) + error = ParseErrorException(ParseError.NOT_TOKEN, token, None, context) + return (new_tokens, error, parent_context) + + +# Generate no text +# We expect the following behaviour: +# - Error if there is no StartText node at all +@template_parse_invalid(Parser().parse_text) +def test_parse_text_invalid_empty(draw): + (tokens, _) = draw(draw_syntax_text_valid()) + parent_context = draw(draw_parse_context()) + context = ParseContext(ParseTask.PARSE_TEXT, None, parent_context) + error = ParseErrorException(ParseError.NO_TOKEN, None, None, context) + return ([], error, parent_context) # Generate text with invalid content tokens