Skip to content

Commit

Permalink
FIX: MOLD/FORM on zero percent value
Browse files Browse the repository at this point in the history
  • Loading branch information
Oldes committed Jan 20, 2020
1 parent 2b1f174 commit 181f5f8
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/core/f-math.c
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@
/* handle sign */
if (sgn) *cp++ = '-';

if (trim == DEC_MOLD_PERCENT) e += 2;
if (trim == DEC_MOLD_PERCENT && (digits_obtained > 1 || sig[0] != '0')) e += 2;

if ((e > decimal_digits) || (e <= -6)) {
/* e-format */
Expand Down
1 change: 1 addition & 0 deletions src/tests/run-tests.r3
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ dt [ ;- delta time
wrap load %units/map-test.r3
wrap load %units/integer-test.r3
wrap load %units/decimal-test.r3
wrap load %units/percent-test.r3
wrap load %units/money-test.r3
wrap load %units/power-test.r3
wrap load %units/mezz-crypt-test.r3
Expand Down
41 changes: 41 additions & 0 deletions src/tests/units/percent-test.r3
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
Rebol [
Title: "Rebol3 percent test script"
Author: "Oldes, Peter W A Wood"
File: %decimal-test.r3
Tabs: 4
Needs: [%../quick-test-module.r3]
]


~~~start-file~~~ "percent"

===start-group=== "form/mold"
--test-- "form"
--assert "0%" = form 0%
--assert "1%" = form 1%
--assert "10%" = form 10%
--assert "0.1%" = form 0.1%
--assert "100%" = form 100%

--assert "-0%" = form -0%
--assert "-1%" = form -1%
--assert "-10%" = form -10%
--assert "-0.1%" = form -0.1%
--assert "-100%" = form -100%

--test-- "mold"
--assert "0%" = mold 0%
--assert "1%" = mold 1%
--assert "10%" = mold 10%
--assert "0.1%" = mold 0.1%
--assert "100%" = mold 100%

--assert "-0%" = mold -0%
--assert "-1%" = mold -1%
--assert "-10%" = mold -10%
--assert "-0.1%" = mold -0.1%
--assert "-100%" = mold -100%
===end-group===


~~~end-file~~~

0 comments on commit 181f5f8

Please sign in to comment.