Skip to content

Commit eabf0de

Browse files
committed
test: assert text clipping payloads directly
1 parent e3f27a2 commit eabf0de

2 files changed

Lines changed: 32 additions & 11 deletions

File tree

tests/test_cli.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -839,10 +839,17 @@ def test_should_emit_structured_json_for_declared_width_text_clipping(self):
839839
assert finding["bbox"]["width"] > 50
840840
assert finding["bbox"]["x"] + finding["bbox"]["width"] <= 400
841841
assert finding["related_layers"] == ["layer:1"]
842-
assert finding["measured"]["text_bbox"] == finding["bbox"]
843-
assert finding["measured"]["clipped_by"] == "max_width"
844-
assert finding["measured"]["max_width"] == 50
845-
assert finding["measured"]["overflow_width"] == finding["bbox"]["width"] - 50
842+
assert finding["measured"] == {
843+
"text_bbox": finding["bbox"],
844+
"wrapped_line_count": 2,
845+
"max_width": 50,
846+
"text_width": finding["bbox"]["width"],
847+
"text_height": finding["bbox"]["height"],
848+
"canvas_width": 400,
849+
"canvas_height": 300,
850+
"clipped_by": "max_width",
851+
"overflow_width": finding["bbox"]["width"] - 50,
852+
}
846853

847854
def test_should_emit_structured_json_for_missing_glyph(self, monkeypatch):
848855
"""lint --format json includes structured missing-glyph diagnostics"""

tests/test_diagnostics.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -507,10 +507,17 @@ def test_should_warn_when_wrapped_text_exceeds_declared_width(self):
507507
assert finding.bbox.x == 10
508508
assert finding.bbox.width > 50
509509
assert finding.bbox.x + finding.bbox.width <= 400
510-
assert finding.measured["text_bbox"] == finding.bbox.model_dump()
511-
assert finding.measured["clipped_by"] == "max_width"
512-
assert finding.measured["max_width"] == 50
513-
assert finding.measured["overflow_width"] == finding.bbox.width - 50
510+
assert finding.measured == {
511+
"text_bbox": finding.bbox.model_dump(),
512+
"wrapped_line_count": 2,
513+
"max_width": 50,
514+
"text_width": finding.bbox.width,
515+
"text_height": finding.bbox.height,
516+
"canvas_width": 400,
517+
"canvas_height": 300,
518+
"clipped_by": "max_width",
519+
"overflow_width": finding.bbox.width - 50,
520+
}
514521

515522
def test_should_warn_when_overflowing_word_also_extends_past_canvas_vertically(self):
516523
"""Text overflow does not suppress vertical text-clipped canvas diagnostics"""
@@ -535,10 +542,17 @@ def test_should_warn_when_overflowing_word_also_extends_past_canvas_vertically(s
535542
# then
536543
assert [d.code for d in diagnostics] == ["text-overflow", "text-clipped", "off-canvas"]
537544
finding = diagnostics[1]
538-
assert finding.measured["clipped_by"] == "canvas"
539545
assert finding.bbox is not None
540-
assert finding.measured["overflow"] == {
541-
"bottom": finding.bbox.y + finding.bbox.height - 300
546+
assert finding.measured == {
547+
"text_bbox": finding.bbox.model_dump(),
548+
"wrapped_line_count": 2,
549+
"max_width": 50,
550+
"text_width": finding.bbox.width,
551+
"text_height": finding.bbox.height,
552+
"canvas_width": 400,
553+
"canvas_height": 300,
554+
"clipped_by": "canvas",
555+
"overflow": {"bottom": finding.bbox.y + finding.bbox.height - 300},
542556
}
543557

544558
def test_should_warn_when_default_font_renders_missing_glyph(self, monkeypatch):

0 commit comments

Comments
 (0)