Skip to content

Commit 4dc546e

Browse files
committed
CHANGE: using line breaks in molded struct! values for better readability
1 parent 855adc4 commit 4dc546e

File tree

2 files changed

+42
-34
lines changed

2 files changed

+42
-34
lines changed

src/core/t-struct.c

+7-1
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ static REBFLG get_scalar(REBSTU *stu,
186186
val = Append_Value(ser);
187187
Init_Word(val, field->sym);
188188
SET_TYPE(val, REB_SET_WORD);
189+
VAL_SET_LINE(val);
189190

190191
/* required type */
191192
type_blk = Append_Value(ser);
@@ -257,7 +258,12 @@ static void Get_Struct_Reflect(REBVAL* ret, REBSTU* stu, REBCNT type) {
257258
if (type != SYM_VALUES) {
258259
val = Append_Value(out);
259260
Init_Word(val, field->sym);
260-
SET_TYPE(val, (type==SYM_WORDS?REB_WORD:REB_SET_WORD));
261+
if (type == SYM_WORDS) {
262+
SET_TYPE(val, REB_WORD);
263+
} else {
264+
SET_TYPE(val, REB_SET_WORD);
265+
VAL_SET_LINE(val);
266+
}
261267
}
262268
if (type != SYM_WORDS) {
263269
val = Append_Value(out);

src/tests/units/struct-test.r3

+35-33
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,19 @@ Rebol [
3434
--assert 4 = length? f32
3535
--assert 8 = length? f64
3636
--assert 4 = length? w
37-
--assert (mold i8 ) = "make struct! [a: [int8!] 0]"
38-
--assert (mold i16) = "make struct! [a: [int16!] 0]"
39-
--assert (mold i32) = "make struct! [a: [int32!] 0]"
40-
--assert (mold i64) = "make struct! [a: [int64!] 0]"
41-
--assert (mold u8 ) = "make struct! [a: [uint8!] 0]"
42-
--assert (mold u16) = "make struct! [a: [uint16!] 0]"
43-
--assert (mold u32) = "make struct! [a: [uint32!] 0]"
44-
--assert (mold u64) = "make struct! [a: [uint64!] 0]"
45-
--assert (mold f32) = "make struct! [a: [float!] 0.0]"
46-
--assert (mold f64) = "make struct! [a: [double!] 0.0]"
47-
--assert (mold w) = "make struct! [a: [word!] none]"
37+
;; default mold is using line breaks in the molded struct block
38+
--assert (mold i8) = {make struct! [^/ a: [int8!] 23^/ b: [int8!] 0^/]}
39+
--assert (mold/flat i8 ) = "make struct! [a: [int8!] 0]"
40+
--assert (mold/flat i16) = "make struct! [a: [int16!] 0]"
41+
--assert (mold/flat i32) = "make struct! [a: [int32!] 0]"
42+
--assert (mold/flat i64) = "make struct! [a: [int64!] 0]"
43+
--assert (mold/flat u8 ) = "make struct! [a: [uint8!] 0]"
44+
--assert (mold/flat u16) = "make struct! [a: [uint16!] 0]"
45+
--assert (mold/flat u32) = "make struct! [a: [uint32!] 0]"
46+
--assert (mold/flat u64) = "make struct! [a: [uint64!] 0]"
47+
--assert (mold/flat f32) = "make struct! [a: [float!] 0.0]"
48+
--assert (mold/flat f64) = "make struct! [a: [double!] 0.0]"
49+
--assert (mold/flat w) = "make struct! [a: [word!] none]"
4850

4951

5052
--test-- "Struct single value (dimensional) construction"
@@ -84,17 +86,17 @@ Rebol [
8486
--assert 8 = length? f32x2
8587
--assert 16 = length? f64x2
8688
--assert 8 = length? wx2
87-
--assert (mold i8x2 ) = "make struct! [a: [int8! [2]] [0 0]]"
88-
--assert (mold i16x2) = "make struct! [a: [int16! [2]] [0 0]]"
89-
--assert (mold i32x2) = "make struct! [a: [int32! [2]] [0 0]]"
90-
--assert (mold i64x2) = "make struct! [a: [int64! [2]] [0 0]]"
91-
--assert (mold u8x2 ) = "make struct! [a: [uint8! [2]] [0 0]]"
92-
--assert (mold u16x2) = "make struct! [a: [uint16! [2]] [0 0]]"
93-
--assert (mold u32x2) = "make struct! [a: [uint32! [2]] [0 0]]"
94-
--assert (mold u64x2) = "make struct! [a: [uint64! [2]] [0 0]]"
95-
--assert (mold f32x2) = "make struct! [a: [float! [2]] [0.0 0.0]]"
96-
--assert (mold f64x2) = "make struct! [a: [double! [2]] [0.0 0.0]]"
97-
--assert (mold wx2) = "make struct! [a: [word! [2]] [none none]]"
89+
--assert (mold/flat i8x2 ) = "make struct! [a: [int8! [2]] [0 0]]"
90+
--assert (mold/flat i16x2) = "make struct! [a: [int16! [2]] [0 0]]"
91+
--assert (mold/flat i32x2) = "make struct! [a: [int32! [2]] [0 0]]"
92+
--assert (mold/flat i64x2) = "make struct! [a: [int64! [2]] [0 0]]"
93+
--assert (mold/flat u8x2 ) = "make struct! [a: [uint8! [2]] [0 0]]"
94+
--assert (mold/flat u16x2) = "make struct! [a: [uint16! [2]] [0 0]]"
95+
--assert (mold/flat u32x2) = "make struct! [a: [uint32! [2]] [0 0]]"
96+
--assert (mold/flat u64x2) = "make struct! [a: [uint64! [2]] [0 0]]"
97+
--assert (mold/flat f32x2) = "make struct! [a: [float! [2]] [0.0 0.0]]"
98+
--assert (mold/flat f64x2) = "make struct! [a: [double! [2]] [0.0 0.0]]"
99+
--assert (mold/flat wx2) = "make struct! [a: [word! [2]] [none none]]"
98100

99101
--test-- "Struct construction with initial value"
100102
--assert all [struct? i8: make struct! [a: [int8!] 23 b [int8!]] i8/a = 23 i8/b = 0 ]
@@ -109,17 +111,17 @@ Rebol [
109111
--assert all [struct? f64: make struct! [a: [double!] 23 b [int8!]] f64/a = 23 f64/b = 0 ]
110112
--assert all [struct? w: make struct! [a: [word!] foo b [int8!]] w/a = 'foo w/b = 0 ]
111113

112-
--assert (mold i8 ) = "make struct! [a: [int8!] 23 b: [int8!] 0]"
113-
--assert (mold i16) = "make struct! [a: [int16!] 23 b: [int8!] 0]"
114-
--assert (mold i32) = "make struct! [a: [int32!] 23 b: [int8!] 0]"
115-
--assert (mold i64) = "make struct! [a: [int64!] 23 b: [int8!] 0]"
116-
--assert (mold u8 ) = "make struct! [a: [uint8!] 23 b: [int8!] 0]"
117-
--assert (mold u16) = "make struct! [a: [uint16!] 23 b: [int8!] 0]"
118-
--assert (mold u32) = "make struct! [a: [uint32!] 23 b: [int8!] 0]"
119-
--assert (mold u64) = "make struct! [a: [uint64!] 23 b: [int8!] 0]"
120-
--assert (mold f32) = "make struct! [a: [float!] 23.0 b: [int8!] 0]"
121-
--assert (mold f64) = "make struct! [a: [double!] 23.0 b: [int8!] 0]"
122-
--assert (mold w) = "make struct! [a: [word!] foo b: [int8!] 0]"
114+
--assert (mold/flat i8 ) = "make struct! [a: [int8!] 23 b: [int8!] 0]"
115+
--assert (mold/flat i16) = "make struct! [a: [int16!] 23 b: [int8!] 0]"
116+
--assert (mold/flat i32) = "make struct! [a: [int32!] 23 b: [int8!] 0]"
117+
--assert (mold/flat i64) = "make struct! [a: [int64!] 23 b: [int8!] 0]"
118+
--assert (mold/flat u8 ) = "make struct! [a: [uint8!] 23 b: [int8!] 0]"
119+
--assert (mold/flat u16) = "make struct! [a: [uint16!] 23 b: [int8!] 0]"
120+
--assert (mold/flat u32) = "make struct! [a: [uint32!] 23 b: [int8!] 0]"
121+
--assert (mold/flat u64) = "make struct! [a: [uint64!] 23 b: [int8!] 0]"
122+
--assert (mold/flat f32) = "make struct! [a: [float!] 23.0 b: [int8!] 0]"
123+
--assert (mold/flat f64) = "make struct! [a: [double!] 23.0 b: [int8!] 0]"
124+
--assert (mold/flat w) = "make struct! [a: [word!] foo b: [int8!] 0]"
123125

124126
--test-- "Construction from struct prototype"
125127
proto!: make struct! [a: [uint8!] 1 b: [uint8!] 2]

0 commit comments

Comments
 (0)