Skip to content

Commit

Permalink
FIX: MOLD/FLAT on MAP values does not remove line breaks
Browse files Browse the repository at this point in the history
  • Loading branch information
Oldes committed Feb 10, 2020
1 parent 5a4f0f0 commit 5ec25a4
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/core/s-mold.c
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,7 @@ STOID Mold_Map(REBVAL *value, REB_MOLD *mold, REBFLG molded)
{
REBSER *mapser = VAL_SERIES(value);
REBVAL *val;
REBOOL indented = !GET_MOPT(mold, MOPT_INDENT);

// Prevent endless mold loop:
if (Find_Same_Block(MOLD_LOOP, value) > 0) {
Expand All @@ -858,15 +859,20 @@ STOID Mold_Map(REBVAL *value, REB_MOLD *mold, REBFLG molded)
mold->indent++;
for (val = BLK_HEAD(mapser); NOT_END(val) && NOT_END(val+1); val += 2) {
if (!IS_NONE(val+1)) {
if (molded) New_Indented_Line(mold);
if (molded) {
if(indented)
New_Indented_Line(mold);
else if (val > BLK_HEAD(mapser))
Append_Byte(mold->series, ' ');
}
Emit(mold, "V V", val, val+1);
if (!molded) Append_Byte(mold->series, '\n');
}
}
mold->indent--;

if (molded) {
New_Indented_Line(mold);
if(indented) New_Indented_Line(mold);
Append_Byte(mold->series, ']');
}

Expand Down
25 changes: 25 additions & 0 deletions src/tests/units/mold-test.r3
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,31 @@ Rebol [

===end-group===

===start-group=== "mold map!"
--test-- "mold map!"
m: make map! [
a: 1
b: 2
c: [
3 4
]
]

--assert (mold m) = {make map! [
a: 1
b: 2
c: [
3 4
]
]}

--test-- "mold/flat map!"
;@@ https://github.com/rebol/rebol-issues/issues/2401

--assert "make map! [a: 1 b: 2 c: [3 4]]" = mold/flat m

===end-group===

===start-group=== "mold binary!"
bb: system/options/binary-base ;store original value
bin: #{FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF}
Expand Down

0 comments on commit 5ec25a4

Please sign in to comment.