| 416 | |
| 417 | |
| 418 | class TestCommentTextIsNeverYaml: |
| 419 | @pytest.mark.parametrize("brk", ["\n", "\r", "\r\n", "\x85", "\u2028", "\u2029"]) |
| 420 | def test_end_of_line_comments_reject_every_line_break(self, brk): |
| 421 | with pytest.raises(BoxValueError, match="single line"): |
| 422 | Box(a=1).set_comment("a", f"x{brk}injected: 1") |
| 423 | |
| 424 | @pytest.mark.parametrize("brk", ["\n", "\r", "\r\n", "\x85", "\u2028", "\u2029"]) |
| 425 | @pytest.mark.parametrize("key, position", [("a", "before"), (None, "start"), (None, "end")]) |
| 426 | def test_multi_line_comments_stay_comments(self, brk, key, position): |
| 427 | bx = Box(a=1) |
| 428 | bx.set_comment(key, f"one{brk}injected: 1", position=position) |
| 429 | out = bx.to_yaml() |
| 430 | assert Box.from_yaml(out).to_dict() == {"a": 1}, out |
| 431 | assert "# injected: 1" in out |
| 432 | |
| 433 | @pytest.mark.parametrize("char", ["\x00", "\x08", "\x0b", "\x0c", "\x1b", "\x7f"]) |
| 434 | def test_control_characters_are_rejected(self, char): |
| 435 | with pytest.raises(BoxValueError, match="control characters"): |
| 436 | Box(a=1).set_comment("a", f"x{char}y", position="before") |
| 437 | |
| 438 | def test_tabs_are_fine(self): |
| 439 | bx = Box(a=1) |
| 440 | bx.set_comment("a", "x\ty") |
| 441 | assert Box.from_yaml(bx.to_yaml()).get_comment("a") == {"eol": "x\ty"} |
| 442 | |
| 443 | |
| 444 | @pytest.mark.parametrize("count", [0, -1, -3]) |
nothing calls this directly
no outgoing calls
no test coverage detected