Skip to content

Commit

Permalink
FEAT: allow creation of path! from any value
Browse files Browse the repository at this point in the history
  • Loading branch information
Oldes committed Mar 26, 2021
1 parent 61d6ff9 commit 5ed41d3
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/core/t-block.c
Original file line number Diff line number Diff line change
Expand Up @@ -330,9 +330,9 @@ static void No_Nones_Or_Logic(REBVAL *arg) {
return;
}

} else if (type == REB_BLOCK || type == REB_PAREN) {
} else if (ANY_BLOCK_TYPE(type)) {
// to block!/paren! typset!
if (IS_TYPESET(arg)) {
if (IS_TYPESET(arg) && (type == REB_BLOCK || type == REB_PAREN)) {
Set_Block(value, Typeset_To_Block(arg));
return;
}
Expand Down
77 changes: 77 additions & 0 deletions src/tests/units/make-test.r3
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,83 @@ Rebol [

===end-group===

===start-group=== "make/to path"
;@@ https://github.com/Oldes/Rebol-issues/issues/2451
--test-- "make path! .."
--assert error? try [make path! quote #[unset!] ] ; unset!
--assert error? try [make path! quote #[none] ] ; none!
--assert error? try [make path! quote #[true] ] ; logic!
--assert path? try [make path! quote 1 ] ; integer!
--assert path? try [make path! quote 0 ] ; integer!
--assert path? try [make path! quote 4 ] ; integer!
--assert path? try [make path! quote 4.0 ] ; decimal!
--assert error? try [make path! quote 4% ] ; percent!
--assert error? try [make path! quote $4 ] ; money!
--assert error? try [make path! quote #"a" ] ; char!
--assert path? try [make path! quote 2x2 ] ; pair!
--assert error? try [make path! quote 1.1.1 ] ; tuple!
--assert error? try [make path! quote 10:00 ] ; time!
--assert error? try [make path! quote 2000-01-01 ] ; date!
--assert path? try [make path! quote #{00} ] ; binary!
--assert path? try [make path! quote #{312032} ] ; binary!
--assert path? try [make path! quote "" ] ; string!
--assert path? try [make path! quote "1 2" ] ; string!
--assert error? try [make path! quote %file ] ; file!
--assert error? try [make path! quote u@email ] ; email!
--assert error? try [make path! quote #[ref! "ref"] ] ; ref!
--assert error? try [make path! quote http://aa ] ; url!
--assert error? try [make path! quote <tag> ] ; tag!
--assert path? try [make path! quote [1 2] ] ; block!
--assert path? try [make path! quote (1 2) ] ; paren!
--assert path? try [make path! quote a/b ] ; path!
--assert path? try [make path! quote a/b: ] ; set-path!
--assert path? try [make path! quote :a/b ] ; get-path!
--assert error? try [make path! quote /ref ] ; refinement!
--assert error? try [make path! quote #FF ] ; issue!
--assert error? try [make path! quote #[bitset! #{FF}] ] ; bitset!
--assert error? try [make path! quote #[image! 1x1 #{FFFFFF}] ] ; image!
--assert path? try [make path! quote #[vector! integer! 32 2 [0 0]] ] ; vector!
--assert path? try [make path! quote #[object! [a: 1]] ] ; object!
--assert error? try [make path! quote #[typeset! [#[datatype! integer! ]#[datatype! percent! ]]] ] ; typeset!

--test-- "to path! .."
--assert path? try [to path! quote #[unset!] ] ; unset!
--assert path? try [to path! quote #[none] ] ; none!
--assert path? try [to path! quote #[true] ] ; logic!
--assert path? try [to path! quote 1 ] ; integer!
--assert path? try [to path! quote 0 ] ; integer!
--assert path? try [to path! quote 4 ] ; integer!
--assert path? try [to path! quote 4.0 ] ; decimal!
--assert path? try [to path! quote 4% ] ; percent!
--assert path? try [to path! quote $4 ] ; money!
--assert path? try [to path! quote #"a" ] ; char!
--assert path? try [to path! quote 2x2 ] ; pair!
--assert path? try [to path! quote 1.1.1 ] ; tuple!
--assert path? try [to path! quote 10:00 ] ; time!
--assert path? try [to path! quote 2000-01-01 ] ; date!
--assert path? try [to path! quote #{00} ] ; binary!
--assert path? try [to path! quote #{312032} ] ; binary!
--assert path? try [to path! quote "" ] ; string!
--assert path? try [to path! quote "1 2" ] ; string!
--assert path? try [to path! quote %file ] ; file!
--assert path? try [to path! quote u@email ] ; email!
--assert path? try [to path! quote #[ref! "ref"] ] ; ref!
--assert path? try [to path! quote http://aa ] ; url!
--assert path? try [to path! quote <tag> ] ; tag!
--assert path? try [to path! quote [1 2] ] ; block!
--assert path? try [to path! quote (1 2) ] ; paren!
--assert path? try [to path! quote a/b ] ; path!
--assert path? try [to path! quote a/b: ] ; set-path!
--assert path? try [to path! quote :a/b ] ; get-path!
--assert path? try [to path! quote /ref ] ; refinement!
--assert path? try [to path! quote #FF ] ; issue!
--assert path? try [to path! quote #[bitset! #{FF}] ] ; bitset!
--assert path? try [to path! quote #[image! 1x1 #{FFFFFF}] ] ; image!
--assert path? try [to path! quote #[vector! integer! 32 2 [0 0]] ] ; vector!
--assert path? try [to path! quote #[object! [a: 1]] ] ; object!
--assert path? try [to path! quote #[typeset! [#[datatype! integer! ]#[datatype! percent! ]]] ] ; typeset!
===end-group===


===start-group=== "make special"
--test-- "make types from none!"
Expand Down

0 comments on commit 5ed41d3

Please sign in to comment.