|
21 | 21 |
|
22 | 22 | import in2lambda |
23 | 23 | import in2lambda.draft |
| 24 | +import in2lambda.spec |
24 | 25 | from in2lambda.main import cli |
25 | 26 | from in2lambda.source import SourceError |
26 | 27 |
|
@@ -386,6 +387,42 @@ def test_a_spec_calling_a_predicate_nothing_holds_is_refused( |
386 | 387 | assert (tmp_path / "source.draft.json").read_bytes() == written |
387 | 388 |
|
388 | 389 |
|
| 390 | +def test_a_comma_inside_a_quoted_pattern_is_part_of_the_pattern() -> None: |
| 391 | + """A regex alternating over labels holds commas, which are not the after separator.""" |
| 392 | + spec = in2lambda.spec.load( |
| 393 | + "ignore: Para text~'^(Sheet|Note),|^Marks'\n" |
| 394 | + "question: Para\n" |
| 395 | + "layout: PartsOneSol\n" |
| 396 | + ) |
| 397 | + |
| 398 | + assert spec.ignore[0].constraints[0].wanted.pattern == "^(Sheet|Note),|^Marks" |
| 399 | + |
| 400 | + |
| 401 | +def test_two_selectors_written_on_one_line_are_refused_with_the_list_to_write() -> None: |
| 402 | + """A comma outside quotes reads as an after clause, which two block types are not.""" |
| 403 | + with pytest.raises(in2lambda.spec.BadSpec) as refusal: |
| 404 | + in2lambda.spec.load( |
| 405 | + "ignore: Header, Table\nquestion: Para\nlayout: PartsOneSol\n" |
| 406 | + ) |
| 407 | + |
| 408 | + assert "names two selectors on one line" in str(refusal.value) |
| 409 | + assert "- Header" in str(refusal.value) |
| 410 | + assert "- Table" in str(refusal.value) |
| 411 | + |
| 412 | + |
| 413 | +def test_a_comma_outside_quotes_still_separates_an_after_clause() -> None: |
| 414 | + """The documented ``after SELECTOR, rest`` form, which the quotes must not break.""" |
| 415 | + spec = in2lambda.spec.load( |
| 416 | + "question: Para\n" |
| 417 | + "solution: after Header text=Solutions, Para\n" |
| 418 | + "layout: PartsOneSol\n" |
| 419 | + ) |
| 420 | + |
| 421 | + assert spec.solution[0].after.type == "Header" |
| 422 | + assert spec.solution[0].after.constraints[0].wanted == "Solutions" |
| 423 | + assert spec.solution[0].type == "Para" |
| 424 | + |
| 425 | + |
389 | 426 | def test_a_spec_that_is_not_there_is_refused_rather_than_left_to_the_file_system( |
390 | 427 | tmp_path: Path, monkeypatch |
391 | 428 | ) -> None: |
|
0 commit comments