@@ -30,6 +30,55 @@ void main() {
3030 \t bar"
3131 error''' ), throwsA (isNot (tabError)));
3232 });
33+
34+ Matcher yamlError (String message, int line, int column) =>
35+ isA <YamlException >()
36+ .having ((e) => e.message, 'message' , message)
37+ .having ((e) => e.span! .start.line, 'line' , line)
38+ .having ((e) => e.span! .start.column, 'column' , column)
39+ .having ((e) => e.span! .length, 'span length' , 0 );
40+
41+ test ('a list entry in a block mapping' , () {
42+ expect (
43+ () => loadYaml ('linter:\n '
44+ ' rules:\n '
45+ ' close_sinks: false\n '
46+ ' - empty_statements\n ' ),
47+ throwsA (yamlError (
48+ 'Expected a key while parsing a block mapping. '
49+ 'You cannot mix list and key-value syntax in the same '
50+ 'collection.' ,
51+ 3 ,
52+ 4 )));
53+ });
54+
55+ test ('a mapping entry in a block sequence' , () {
56+ expect (
57+ () => loadYaml ('linter:\n '
58+ ' rules:\n '
59+ ' - empty_statements\n '
60+ ' close_sinks: false\n ' ),
61+ throwsA (yamlError (
62+ "While parsing a block collection, expected '-'. "
63+ 'You cannot mix list and key-value syntax in the same '
64+ 'collection.' ,
65+ 3 ,
66+ 15 )));
67+ });
68+
69+ test ('a block scalar where a mapping key is expected' , () {
70+ expect (
71+ () => loadYaml ('a: 1\n |\n b\n ' ),
72+ throwsA (yamlError (
73+ 'Expected a key while parsing a block mapping.' , 1 , 0 )));
74+ });
75+
76+ test ('a block scalar where a list entry is expected' , () {
77+ expect (
78+ () => loadYaml ('- a\n |\n b\n ' ),
79+ throwsA (yamlError (
80+ "While parsing a block collection, expected '-'." , 1 , 0 )));
81+ });
3382 });
3483
3584 group ('refuses' , () {
0 commit comments