diff --git a/packages/counter-style/src/__tests__/CounterStyleRenderer.test.ts b/packages/counter-style/src/__tests__/CounterStyleRenderer.test.ts index 320677e..8f1fa80 100644 --- a/packages/counter-style/src/__tests__/CounterStyleRenderer.test.ts +++ b/packages/counter-style/src/__tests__/CounterStyleRenderer.test.ts @@ -97,6 +97,11 @@ describe('CounterStyleRenderer', () => { ); }); describe('::maxMarkerLenInRange', () => { + it('should return 0 when range is decreasing', () => { + const counter = decimal; + expect(counter.maxMarkerLenInRange(1, 0)).toBe(0); + expect(counter.maxCounterLenInRange(1, 0)).toBe(0); + }); it('should work with numeric styles', () => { const counter = decimal; expect(counter.maxMarkerLenInRange(1, 9)).toBe(1 + DEFAULT_SUFFIX.length); diff --git a/packages/counter-style/src/makeCSRenderer.ts b/packages/counter-style/src/makeCSRenderer.ts index 66bcf6c..90a2f56 100644 --- a/packages/counter-style/src/makeCSRenderer.ts +++ b/packages/counter-style/src/makeCSRenderer.ts @@ -43,6 +43,9 @@ const stylePrototype: Omit = { return Math.max(lenLeft, lenMiddle, lenRight); }, maxCounterLenInRange(this: CounterStyleRendererInt, min, max) { + if (max < min) { + return 0; + } if (min >= 0) { return this.getAbsoluteMaxLenInRange(min, max, false); } @@ -55,6 +58,9 @@ const stylePrototype: Omit = { ); }, maxMarkerLenInRange(this: CounterStyleRendererInt, min, max) { + if (max < min) { + return 0; + } return ( this.maxCounterLenInRange(min, max) + codeunitLength(this.engine.specs.suffix) +