fix: SText.updateMeasuredBounds() must mutate internal bounds, not defensive copy
All checks were successful
CI / build-and-test (pull_request) Successful in 16s

Closes #27
This commit is contained in:
2026-03-27 23:56:42 +01:00
parent 1cabbd0224
commit a8b908ca1d
2 changed files with 37 additions and 1 deletions

View File

@@ -57,7 +57,7 @@ public class SText extends AbstractShape {
} }
public void updateMeasuredBounds(int width, int height) { public void updateMeasuredBounds(int width, int height) {
getBounds().setSize(Math.max(width, 0), Math.max(height, 0)); bounds.setSize(Math.max(width, 0), Math.max(height, 0));
} }
@Override @Override

View File

@@ -44,4 +44,40 @@ class STextTest {
SText text = SText.create(0, 0, null); SText text = SText.create(0, 0, null);
assertEquals(SText.PLACEHOLDER_TEXT, text.getText()); assertEquals(SText.PLACEHOLDER_TEXT, text.getText());
} }
@Test
void testUpdateMeasuredBoundsActuallyUpdatesBounds() {
SText text = SText.create(10, 20, "Hello");
text.updateMeasuredBounds(200, 30);
Rectangle bounds = text.getBounds();
assertEquals(200, bounds.width, "updateMeasuredBounds must update width");
assertEquals(30, bounds.height, "updateMeasuredBounds must update height");
}
@Test
void testUpdateMeasuredBoundsDoesNotChangePosition() {
SText text = SText.create(10, 20, "Hello");
text.updateMeasuredBounds(200, 30);
Rectangle bounds = text.getBounds();
assertEquals(10, bounds.x, "updateMeasuredBounds must not change x");
assertEquals(20, bounds.y, "updateMeasuredBounds must not change y");
}
@Test
void testUpdateMeasuredBoundsNegativeClampedToZero() {
SText text = SText.create(0, 0, "Hello");
text.updateMeasuredBounds(-5, -10);
Rectangle bounds = text.getBounds();
assertEquals(0, bounds.width, "negative width must be clamped to 0");
assertEquals(0, bounds.height, "negative height must be clamped to 0");
}
@Test
void testUpdateMeasuredBoundsZeroIsAllowed() {
SText text = SText.create(0, 0, "Hello");
text.updateMeasuredBounds(0, 0);
Rectangle bounds = text.getBounds();
assertEquals(0, bounds.width);
assertEquals(0, bounds.height);
}
} }