Skip to content

Commit f2276d2

Browse files
committed
fix(parsing): adding check for acceptance test heading
1 parent 0cb870e commit f2276d2

2 files changed

Lines changed: 55 additions & 0 deletions

File tree

plain_file.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,11 @@ def parse_plain_source( # noqa: C901
473473

474474
specification_heading = token.children[0].children[0].children[0].content
475475

476+
if specification_heading == plain_spec.ACCEPTANCE_TEST_HEADING:
477+
raise PlainSyntaxError(
478+
f"Plain syntax error: Syntax error at line {token.line_number}: {plain_spec.ACCEPTANCE_TEST_HEADING} heading should be nested under specific functional spec."
479+
)
480+
476481
if specification_heading not in plain_spec.ALLOWED_SPECIFICATION_HEADINGS:
477482
raise PlainSyntaxError(
478483
f"Plain syntax error: Syntax error at line {token.line_number}: Invalid specification heading (`{specification_heading}`). Allowed headings: {', '.join(plain_spec.ALLOWED_SPECIFICATION_HEADINGS)}"

tests/test_plainfileparser.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,56 @@ def test_acceptance_tests_block_include_with_trailing_newline_keeps_structure_an
376376
plain_file.plain_file_parser("block_level_include.plain", [get_test_data_path("data/templates")])
377377

378378

379+
def test_acceptance_tests_top_level_rejected():
380+
plain_source = """
381+
***acceptance tests***
382+
383+
- Test something.
384+
"""
385+
with pytest.raises(
386+
PlainSyntaxError,
387+
match=re.escape(
388+
"Syntax error at line 1: acceptance tests heading should be nested under specific functional spec."
389+
),
390+
):
391+
plain_file.parse_plain_source(plain_source, {}, [], [], [])
392+
393+
394+
def test_acceptance_tests_top_level_after_other_headings_rejected():
395+
plain_source = """***definitions***
396+
397+
- :concept: is a concept.
398+
399+
***acceptance tests***
400+
401+
- Test something.
402+
"""
403+
with pytest.raises(
404+
PlainSyntaxError,
405+
match=re.escape(
406+
"Syntax error at line 5: acceptance tests heading should be nested under specific functional spec."
407+
),
408+
):
409+
plain_file.parse_plain_source(plain_source, {}, [], [], [])
410+
411+
412+
def test_acceptance_tests_nested_under_functional_spec_allowed():
413+
plain_source = """***definitions***
414+
415+
- :concept: is a concept.
416+
417+
***functional specs***
418+
419+
- Display "hello, world"
420+
421+
***acceptance tests***
422+
423+
- Test the :concept:.
424+
"""
425+
result = plain_file.parse_plain_source(plain_source, {}, [], [], [])
426+
assert plain_spec.FUNCTIONAL_REQUIREMENTS in result.plain_source
427+
428+
379429
def test_concept_validation_definitions(get_test_data_path):
380430
plain_file.plain_file_parser(
381431
"concept_validation_definition.plain",

0 commit comments

Comments
 (0)