Skip to content

Commit a2bcfed

Browse files
committed
FEAT: allow conversion from object! to map!
related to: Oldes/Rebol-issues#579
1 parent e868dba commit a2bcfed

File tree

2 files changed

+79
-0
lines changed

2 files changed

+79
-0
lines changed

src/core/t-map.c

+4
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,7 @@
540540
case A_TO:
541541
// make map! [word val word val]
542542
if (IS_BLOCK(arg) || IS_PAREN(arg) || IS_MAP(arg)) {
543+
map_from_block:
543544
if (MT_Map(D_RET, arg, 0)) return R_RET;
544545
Trap_Arg(arg);
545546
// } else if (IS_NONE(arg)) {
@@ -548,6 +549,9 @@
548549
} else if (IS_NUMBER(arg)) {
549550
if (action == A_TO) Trap_Arg(arg);
550551
n = Int32s(arg, 0);
552+
} else if (IS_OBJECT(arg)) {
553+
Set_Block(arg, Make_Object_Block(VAL_OBJ_FRAME(arg), 3));
554+
goto map_from_block;
551555
} else
552556
Trap_Make(REB_MAP, Of_Type(arg));
553557
// positive only

src/tests/units/make-test.r3

+75
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,81 @@ Rebol [
465465
--assert path? try [to path! quote #[typeset! [#[datatype! integer! ]#[datatype! percent! ]]] ] ; typeset!
466466
===end-group===
467467

468+
===start-group=== "make/to map"
469+
;@@ https://github.com/Oldes/Rebol-issues/issues/2451
470+
--test-- "make map! .."
471+
--assert error? try [make map! quote #[unset!] ] ; unset!
472+
--assert error? try [make map! quote #[none] ] ; none!
473+
--assert error? try [make map! quote #[true] ] ; logic!
474+
--assert map? try [make map! quote 1 ] ; integer!
475+
--assert map? try [make map! quote 0 ] ; integer!
476+
--assert map? try [make map! quote 4 ] ; integer!
477+
--assert map? try [make map! quote 4.0 ] ; decimal!
478+
--assert error? try [make map! quote 4.0000000000000001% ] ; percent!
479+
--assert error? try [make map! quote $4 ] ; money!
480+
--assert error? try [make map! quote #"a" ] ; char!
481+
--assert error? try [make map! quote 2x2 ] ; pair!
482+
--assert error? try [make map! quote 1.1.1 ] ; tuple!
483+
--assert error? try [make map! quote 10:00 ] ; time!
484+
--assert error? try [make map! quote 2000-01-01 ] ; date!
485+
--assert error? try [make map! quote #{00} ] ; binary!
486+
--assert error? try [make map! quote #{312032} ] ; binary!
487+
--assert error? try [make map! quote "" ] ; string!
488+
--assert error? try [make map! quote "1 2" ] ; string!
489+
--assert error? try [make map! quote %file ] ; file!
490+
--assert error? try [make map! quote u@email ] ; email!
491+
--assert error? try [make map! quote #[ref! "ref"] ] ; ref!
492+
--assert error? try [make map! quote http://aa ] ; url!
493+
--assert error? try [make map! quote <tag> ] ; tag!
494+
--assert map? try [make map! quote [1 2] ] ; block!
495+
--assert error? try [make map! quote (1 2) ] ; paren!
496+
--assert error? try [make map! quote a/b ] ; path!
497+
--assert error? try [make map! quote a/b: ] ; set-path!
498+
--assert error? try [make map! quote :a/b ] ; get-path!
499+
--assert error? try [make map! quote /ref ] ; refinement!
500+
--assert error? try [make map! quote #FF ] ; issue!
501+
--assert error? try [make map! quote #[bitset! #{FF}] ] ; bitset!
502+
--assert error? try [make map! quote #[image! 1x1 #{FFFFFF}] ] ; image!
503+
--assert error? try [make map! quote #[vector! integer! 32 2 [0 0]] ] ; vector!
504+
--assert map? try [make map! quote #[object! [a: 1]] ] ; object!
505+
--assert error? try [make map! quote #[typeset! [#[datatype! integer! ]#[datatype! percent! ]]] ] ; typeset!
506+
--test-- "to map! .."
507+
--assert error? try [to map! quote #[unset!] ] ; unset!
508+
--assert error? try [to map! quote #[none] ] ; none!
509+
--assert error? try [to map! quote #[true] ] ; logic!
510+
--assert error? try [to map! quote 1 ] ; integer!
511+
--assert error? try [to map! quote 0 ] ; integer!
512+
--assert error? try [to map! quote 4 ] ; integer!
513+
--assert error? try [to map! quote 4.0 ] ; decimal!
514+
--assert error? try [to map! quote 4.0000000000000001% ] ; percent!
515+
--assert error? try [to map! quote $4 ] ; money!
516+
--assert error? try [to map! quote #"a" ] ; char!
517+
--assert error? try [to map! quote 2x2 ] ; pair!
518+
--assert error? try [to map! quote 1.1.1 ] ; tuple!
519+
--assert error? try [to map! quote 10:00 ] ; time!
520+
--assert error? try [to map! quote 2000-01-01 ] ; date!
521+
--assert error? try [to map! quote #{00} ] ; binary!
522+
--assert error? try [to map! quote #{312032} ] ; binary!
523+
--assert error? try [to map! quote "" ] ; string!
524+
--assert error? try [to map! quote "1 2" ] ; string!
525+
--assert error? try [to map! quote %file ] ; file!
526+
--assert error? try [to map! quote u@email ] ; email!
527+
--assert error? try [to map! quote #[ref! "ref"] ] ; ref!
528+
--assert error? try [to map! quote http://aa ] ; url!
529+
--assert error? try [to map! quote <tag> ] ; tag!
530+
--assert map? try [to map! quote [1 2] ] ; block!
531+
--assert error? try [to map! quote (1 2) ] ; paren!
532+
--assert error? try [to map! quote a/b ] ; path!
533+
--assert error? try [to map! quote a/b: ] ; set-path!
534+
--assert error? try [to map! quote :a/b ] ; get-path!
535+
--assert error? try [to map! quote /ref ] ; refinement!
536+
--assert error? try [to map! quote #FF ] ; issue!
537+
--assert error? try [to map! quote #[bitset! #{FF}] ] ; bitset!
538+
--assert error? try [to map! quote #[image! 1x1 #{FFFFFF}] ] ; image!
539+
--assert error? try [to map! quote #[vector! integer! 32 2 [0 0]] ] ; vector!
540+
--assert map? try [to map! quote #[object! [a: 1]] ] ; object!
541+
--assert error? try [to map! quote #[typeset! [#[datatype! integer! ]#[datatype! percent! ]]] ] ; typeset!
542+
===end-group===
468543

469544
===start-group=== "make special"
470545
--test-- "make types from none!"

0 commit comments

Comments
 (0)