Skip to content

Commit f8ecb52

Browse files
authored
Catch composable syntax err for options and defaults (#678)
* catch syntax error for options and defaults * work both ways * format
1 parent b160568 commit f8ecb52

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

snooty/parser.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -900,6 +900,18 @@ def handle_composable(self, node: n.ComposableDirective) -> None:
900900
"composable-tutorial", "option_ids", "at least one", node.start[0]
901901
)
902902
)
903+
return
904+
905+
if len(default_ids) != len(option_ids):
906+
self.diagnostics.append(
907+
InvalidChildCount(
908+
"composable-tutorial",
909+
"defaults",
910+
str(len(option_ids)),
911+
node.start[0],
912+
)
913+
)
914+
return
903915

904916
# get the expected composable options from the spec
905917
spec_composables = specparser.Spec.get(

snooty/test_postprocess.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
GuideAlreadyHasChapter,
1919
InvalidChapter,
2020
InvalidChild,
21+
InvalidChildCount,
2122
InvalidContextError,
2223
InvalidIAEntry,
2324
InvalidIALinkedData,
@@ -4272,6 +4273,52 @@ def test_composable_tutorial_errors() -> None:
42724273
MissingChild,
42734274
]
42744275

4276+
# below test has mismatch of options and default ids (defaults has more ids than options)
4277+
with make_test(
4278+
{
4279+
Path(
4280+
"source/index.txt"
4281+
): """
4282+
.. composable-tutorial::
4283+
:options: interface, language, cluster-topology, cloud-provider
4284+
:defaults: driver, None, repl
4285+
4286+
.. selected-content::
4287+
:selections: driver, None, repl
4288+
"""
4289+
}
4290+
) as result:
4291+
diagnostics = result.diagnostics[FileId("index.txt")]
4292+
assert len(diagnostics) >= 1
4293+
invalidChildError = next(
4294+
(d for d in diagnostics if isinstance(d, InvalidChildCount)), None
4295+
)
4296+
assert invalidChildError
4297+
assert "defaults" in invalidChildError.message
4298+
4299+
# below test has mismatch of options and default ids (defaults has less ids than options)
4300+
with make_test(
4301+
{
4302+
Path(
4303+
"source/index.txt"
4304+
): """
4305+
.. composable-tutorial::
4306+
:options: interface, language, cluster-topology
4307+
:defaults: driver, None, repl, gcp
4308+
4309+
.. selected-content::
4310+
:selections: driver, None, repl, gcp
4311+
"""
4312+
}
4313+
) as result:
4314+
diagnostics = result.diagnostics[FileId("index.txt")]
4315+
assert len(diagnostics) >= 1
4316+
invalidChildError = next(
4317+
(d for d in diagnostics if isinstance(d, InvalidChildCount)), None
4318+
)
4319+
assert invalidChildError
4320+
assert "defaults" in invalidChildError.message
4321+
42754322

42764323
def test_composable_headings() -> None:
42774324
with make_test(

0 commit comments

Comments
 (0)