# SPDX-License-Identifier: LGPL-2.1-only # Copyright 2022 Jookia <contact@jookia.org> 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.test_token import draw_token_random # Draws tokens to make a reference @composite def draw_token_reference_valid(draw): token = draw(draw_token_random()) return ([token], Reference(token.value)) # 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 # Tests parsing of empty references # We expect the following behaviour: # - Error if there isn't a token @template_parse_invalid(Parser().parse_reference) def test_parse_reference_invalid_empty(draw, parent_context): context = ParseContext(ParseTask.PARSE_REFERENCE, None, parent_context) error = ParseErrorException(ParseError.NO_TOKEN, None, None, context) return ([], error)