diff --git a/tests/parse/test_bool.py b/tests/parse/test_bool.py index d34dec7..75dac9d 100644 --- a/tests/parse/test_bool.py +++ b/tests/parse/test_bool.py @@ -19,6 +19,14 @@ return ([token], result) +# Draws tokens to not make a valid boolean +@composite +def draw_syntax_not_bool(draw): + token = draw(draw_syntax_random()) + assume(not (token.type == SyntaxType.TOKEN and token.value in ["True", "False"])) + return token + + # Tests parse_bool works correctly # We expect the following behaviour: # - The resulting boolean is True if the first token is True @@ -36,8 +44,7 @@ # - Error if the token is not True or False @template_parse_invalid(Parser().parse_bool) def test_parse_bool_invalid_incorrect(draw, parent_context): - token = draw(draw_syntax_random()) - assume(not (token.type == SyntaxType.TOKEN and token.value in ["True", "False"])) + token = draw(draw_syntax_not_bool()) context = ParseContext(ParseTask.PARSE_BOOL, token, parent_context) if token.type == SyntaxType.TOKEN: error = ParseErrorException(ParseError.NOT_BOOL, token, None, context) diff --git a/tests/parse/test_note.py b/tests/parse/test_note.py index f3ed803..9fb720a 100644 --- a/tests/parse/test_note.py +++ b/tests/parse/test_note.py @@ -35,6 +35,14 @@ return token +# Draws a random syntax that isn't a StartNote token +@composite +def draw_syntax_not_startnote(draw): + token = draw(draw_syntax_random()) + assume(not (token.type == SyntaxType.TOKEN and token.value == "StartNote")) + return token + + # Draws tokens to make a valid note @composite def draw_syntax_note_valid(draw): @@ -61,8 +69,7 @@ @template_parse_invalid(NoteSkipper().skip_note) def test_parse_note_invalid_incorrect(draw, parent_context): (tokens, _) = draw(draw_syntax_note_valid()) - token = draw(draw_syntax_random()) - assume(not (token.type == SyntaxType.TOKEN and token.value == "StartNote")) + token = draw(draw_syntax_not_startnote()) new_tokens = [token] + tokens[1:0] context = ParseContext(ParseTask.PARSE_NOTE, new_tokens[0], parent_context) if token.type == SyntaxType.TOKEN: diff --git a/tests/parse/test_text.py b/tests/parse/test_text.py index f81109a..1149048 100644 --- a/tests/parse/test_text.py +++ b/tests/parse/test_text.py @@ -35,6 +35,22 @@ return token +# Draws a random syntax that isn't StartText token +@composite +def draw_syntax_not_starttext(draw): + token = draw(draw_syntax_random()) + assume(not (token.type == SyntaxType.TOKEN and token.value == "StartText")) + return token + + +# Draws a random syntax that isn't a token +@composite +def draw_syntax_not_token(draw): + token = draw(draw_syntax_random()) + assume(token.type != SyntaxType.TOKEN) + return token + + # Draws tokens to make a valid text string and its value @composite def draw_syntax_text_valid(draw): @@ -69,8 +85,7 @@ @template_parse_invalid(Parser().parse_text) def test_parse_text_invalid_incorrect(draw, parent_context): (tokens, _) = draw(draw_syntax_text_valid()) - token = draw(draw_syntax_random()) - assume(not (token.type == SyntaxType.TOKEN and token.value == "StartText")) + token = draw(draw_syntax_not_starttext()) new_tokens = [token] + tokens[1:0] context = ParseContext(ParseTask.PARSE_TEXT, new_tokens[0], parent_context) if token.type == SyntaxType.TOKEN: @@ -97,8 +112,7 @@ @template_parse_invalid(Parser().parse_text) def test_parse_text_invalid_invalidcontent(draw, parent_context): (tokens, _) = draw(draw_syntax_text_valid()) - token = draw(draw_syntax_random()) - assume(token.type != SyntaxType.TOKEN) + token = draw(draw_syntax_not_token()) new_tokens = insert_random_within(draw, tokens, token) context = ParseContext(ParseTask.PARSE_TEXT, new_tokens[0], parent_context) error = ParseErrorException(ParseError.NOT_TOKEN, token, None, context)