@@ -36,7 +36,7 @@ def test_unknown_section():
3636 with pytest .raises (
3737 Exception ,
3838 match = re .escape (
39- "Syntax error at line 3 : Invalid specification heading (`Unknown Section:`). Allowed headings: definitions, implementation reqs, test reqs, functional specs, acceptance tests"
39+ "Syntax error at line 4 : Invalid specification heading (`Unknown Section:`). Allowed headings: definitions, implementation reqs, test reqs, functional specs, acceptance tests"
4040 ),
4141 ):
4242 plain_file .parse_plain_source (plain_source , {}, [], [], [])
@@ -50,7 +50,7 @@ def test_duplicate_section():
5050"""
5151 with pytest .raises (
5252 Exception ,
53- match = re .escape ("Syntax error at line 3 : Duplicate specification heading (`definitions`)" ),
53+ match = re .escape ("Syntax error at line 4 : Duplicate specification heading (`definitions`)" ),
5454 ):
5555 plain_file .parse_plain_source (plain_source , {}, [], [], [])
5656
@@ -64,11 +64,48 @@ def test_invalid_top_level_element():
6464"""
6565 with pytest .raises (
6666 Exception ,
67- match = re .escape ("Syntax error at line 2 : Invalid source structure (`code block`)" ),
67+ match = re .escape ("Syntax error at line 3 : Invalid source structure (`code block`)" ),
6868 ):
6969 plain_file .parse_plain_source (plain_source , {}, [], [], [])
7070
7171
72+ def test_syntax_error_line_number_accounts_for_frontmatter ():
73+ plain_source = """---
74+ description: 'Plain file with frontmatter'
75+ ---
76+
77+ ***definitions***
78+
79+ ***Unknown Section:***
80+ """
81+ with pytest .raises (
82+ Exception ,
83+ match = re .escape ("Syntax error at line 7: Invalid specification heading (`Unknown Section:`)" ),
84+ ):
85+ plain_file .parse_plain_source (plain_source , {}, [], [], [])
86+
87+
88+ def test_syntax_error_line_number_with_windows_line_endings ():
89+ plain_source = (
90+ "---\r \n "
91+ "description: 'Plain file with frontmatter'\r \n "
92+ "---\r \n "
93+ "\r \n "
94+ "***definitions***\r \n "
95+ "\r \n "
96+ "***Unknown Section:***\r \n "
97+ )
98+ with pytest .raises (
99+ Exception ,
100+ match = re .escape ("Syntax error at line 7: Invalid specification heading (`Unknown Section:`)" ),
101+ ):
102+ plain_file .parse_plain_source (plain_source , {}, [], [], [])
103+
104+
105+ def test_normalize_line_endings_does_not_duplicate_newlines ():
106+ assert plain_file .normalize_line_endings ("a\r \n b\r c\n d" ) == "a\n b\n c\n d"
107+
108+
72109def test_plain_file_parser_with_comments (get_test_data_path ):
73110 _ , plain_sections , _ = plain_file .plain_file_parser (
74111 "plain_file_parser_with_comments.plain" ,
@@ -423,7 +460,7 @@ def test_acceptance_tests_top_level_rejected():
423460 with pytest .raises (
424461 PlainSyntaxError ,
425462 match = re .escape (
426- "Syntax error at line 1 : acceptance tests heading should be nested under specific functional spec."
463+ "Syntax error at line 2 : acceptance tests heading should be nested under specific functional spec."
427464 ),
428465 ):
429466 plain_file .parse_plain_source (plain_source , {}, [], [], [])
0 commit comments