Skip to content

Commit 5ec25a4

Browse files
committed
FIX: MOLD/FLAT on MAP values does not remove line breaks
fixes: metaeducation/rebol-issues#2401
1 parent 5a4f0f0 commit 5ec25a4

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

src/core/s-mold.c

+8-2
Original file line numberDiff line numberDiff line change
@@ -841,6 +841,7 @@ STOID Mold_Map(REBVAL *value, REB_MOLD *mold, REBFLG molded)
841841
{
842842
REBSER *mapser = VAL_SERIES(value);
843843
REBVAL *val;
844+
REBOOL indented = !GET_MOPT(mold, MOPT_INDENT);
844845

845846
// Prevent endless mold loop:
846847
if (Find_Same_Block(MOLD_LOOP, value) > 0) {
@@ -858,15 +859,20 @@ STOID Mold_Map(REBVAL *value, REB_MOLD *mold, REBFLG molded)
858859
mold->indent++;
859860
for (val = BLK_HEAD(mapser); NOT_END(val) && NOT_END(val+1); val += 2) {
860861
if (!IS_NONE(val+1)) {
861-
if (molded) New_Indented_Line(mold);
862+
if (molded) {
863+
if(indented)
864+
New_Indented_Line(mold);
865+
else if (val > BLK_HEAD(mapser))
866+
Append_Byte(mold->series, ' ');
867+
}
862868
Emit(mold, "V V", val, val+1);
863869
if (!molded) Append_Byte(mold->series, '\n');
864870
}
865871
}
866872
mold->indent--;
867873

868874
if (molded) {
869-
New_Indented_Line(mold);
875+
if(indented) New_Indented_Line(mold);
870876
Append_Byte(mold->series, ']');
871877
}
872878

src/tests/units/mold-test.r3

+25
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,31 @@ Rebol [
269269

270270
===end-group===
271271

272+
===start-group=== "mold map!"
273+
--test-- "mold map!"
274+
m: make map! [
275+
a: 1
276+
b: 2
277+
c: [
278+
3 4
279+
]
280+
]
281+
282+
--assert (mold m) = {make map! [
283+
a: 1
284+
b: 2
285+
c: [
286+
3 4
287+
]
288+
]}
289+
290+
--test-- "mold/flat map!"
291+
;@@ https://github.com/rebol/rebol-issues/issues/2401
292+
293+
--assert "make map! [a: 1 b: 2 c: [3 4]]" = mold/flat m
294+
295+
===end-group===
296+
272297
===start-group=== "mold binary!"
273298
bb: system/options/binary-base ;store original value
274299
bin: #{FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF}

0 commit comments

Comments
 (0)