Skip to content

Commit 266b20f

Browse files
committed
FEAT: allow conversion to word! from any string datatype (if don't have invalid chars)
resolves: Oldes/Rebol-issues#2492
1 parent d694614 commit 266b20f

File tree

2 files changed

+83
-1
lines changed

2 files changed

+83
-1
lines changed

src/core/t-word.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@
9898
return R_ARG2;
9999
}
100100
else {
101-
if (IS_STRING(arg) || IS_REF(arg) || IS_TAG(arg)) {
101+
if (ANY_STR(arg)) {
102102
REBYTE *bp;
103103
REBCNT len;
104104
// Set sym. Rest is set below.

src/tests/units/make-test.r3

+82
Original file line numberDiff line numberDiff line change
@@ -819,6 +819,88 @@ Rebol [
819819
--assert error? try [to event! quote #[typeset! [#[datatype! integer! ]#[datatype! percent! ]]] ] ; typeset!
820820
===end-group===
821821

822+
823+
===start-group=== "make/to word"
824+
;@@ https://github.com/Oldes/Rebol-issues/issues/2492
825+
--test-- "make word! ..."
826+
--assert error? try [make word! quote #[unset!] ] ; unset!
827+
--assert error? try [make word! quote #[none] ] ; none!
828+
--assert 'true = try [make word! quote #[true] ] ; logic!
829+
--assert error? try [make word! quote 1 ] ; integer!
830+
--assert error? try [make word! quote 0 ] ; integer!
831+
--assert error? try [make word! quote 4 ] ; integer!
832+
--assert error? try [make word! quote 4.0 ] ; decimal!
833+
--assert error? try [make word! quote 4% ] ; percent!
834+
--assert error? try [make word! quote $4 ] ; money!
835+
--assert 'a = try [make word! quote #"a" ] ; char!
836+
--assert error? try [make word! quote 2x2 ] ; pair!
837+
--assert error? try [make word! quote 1.1.1 ] ; tuple!
838+
--assert error? try [make word! quote 10:00 ] ; time!
839+
--assert error? try [make word! quote 2000-01-01 ] ; date!
840+
--assert error? try [make word! quote #{00} ] ; binary!
841+
--assert error? try [make word! quote #{312032} ] ; binary!
842+
--assert error? try [make word! quote "" ] ; string!
843+
--assert error? try [make word! quote "1 2" ] ; string!
844+
--assert 'file = try [make word! quote %file ] ; file!
845+
--assert error? try [make word! quote u@email ] ; email!
846+
--assert 'foo = try [make word! to email! "foo" ] ; email!
847+
--assert 'ref = try [make word! quote #[ref! "ref"] ] ; ref!
848+
--assert error? try [make word! quote http://aa ] ; url!
849+
--assert 'foo = try [make word! to url! "foo" ] ; url
850+
--assert 'tag = try [make word! quote <tag> ] ; tag!
851+
--assert error? try [make word! quote [1 2] ] ; block!
852+
--assert error? try [make word! quote (1 2) ] ; paren!
853+
--assert error? try [make word! quote a/b ] ; path!
854+
--assert error? try [make word! quote a/b: ] ; set-path!
855+
--assert error? try [make word! quote :a/b ] ; get-path!
856+
--assert 'ref = try [make word! quote /ref ] ; refinement!
857+
--assert 'FF = try [make word! quote #FF ] ; issue!
858+
--assert error? try [make word! quote #[bitset! #{FF}] ] ; bitset!
859+
--assert error? try [make word! quote #[image! 1x1 #{FFFFFF}] ] ; image!
860+
--assert error? try [make word! quote #[vector! integer! 32 2 [0 0]] ] ; vector!
861+
--assert error? try [make word! quote #[object! [a: 1]] ] ; object!
862+
--assert error? try [make word! quote #[typeset! [#[datatype! integer! ]#[datatype! percent! ]]] ] ; typeset!
863+
--test-- "to word! ..."
864+
--assert error? try [to word! quote #[unset!] ] ; unset!
865+
--assert error? try [to word! quote #[none] ] ; none!
866+
--assert 'true = try [to word! quote #[true] ] ; logic!
867+
--assert error? try [to word! quote 1 ] ; integer!
868+
--assert error? try [to word! quote 0 ] ; integer!
869+
--assert error? try [to word! quote 4 ] ; integer!
870+
--assert error? try [to word! quote 4.0 ] ; decimal!
871+
--assert error? try [to word! quote 4.0000000000000001% ] ; percent!
872+
--assert error? try [to word! quote $4 ] ; money!
873+
--assert 'a = try [to word! quote #"a" ] ; char!
874+
--assert error? try [to word! quote 2x2 ] ; pair!
875+
--assert error? try [to word! quote 1.1.1 ] ; tuple!
876+
--assert error? try [to word! quote 10:00 ] ; time!
877+
--assert error? try [to word! quote 2000-01-01 ] ; date!
878+
--assert error? try [to word! quote #{00} ] ; binary!
879+
--assert error? try [to word! quote #{312032} ] ; binary!
880+
--assert error? try [to word! quote "" ] ; string!
881+
--assert error? try [to word! quote "1 2" ] ; string!
882+
--assert 'file = try [to word! quote %file ] ; file!
883+
--assert error? try [to word! quote u@email ] ; email!
884+
--assert 'foo = try [to word! to email! "foo" ] ; email!
885+
--assert 'ref = try [to word! quote #[ref! "ref"] ] ; ref!
886+
--assert error? try [to word! quote http://aa ] ; url!
887+
--assert 'foo = try [to word! to url! "foo" ] ; url
888+
--assert 'tag = try [to word! quote <tag> ] ; tag!
889+
--assert error? try [to word! quote [1 2] ] ; block!
890+
--assert error? try [to word! quote (1 2) ] ; paren!
891+
--assert error? try [to word! quote a/b ] ; path!
892+
--assert error? try [to word! quote a/b: ] ; set-path!
893+
--assert error? try [to word! quote :a/b ] ; get-path!
894+
--assert 'ref = try [to word! quote /ref ] ; refinement!
895+
--assert 'FF = try [to word! quote #FF ] ; issue!
896+
--assert error? try [to word! quote #[bitset! #{FF}] ] ; bitset!
897+
--assert error? try [to word! quote #[image! 1x1 #{FFFFFF}] ] ; image!
898+
--assert error? try [to word! quote #[vector! integer! 32 2 [0 0]] ] ; vector!
899+
--assert error? try [to word! quote #[object! [a: 1]] ] ; object!
900+
--assert error? try [to word! quote #[typeset! [#[datatype! integer! ]#[datatype! percent! ]]] ] ; typeset!
901+
===end-group===
902+
903+
822904
===start-group=== "make special"
823905
--test-- "make types from none!"
824906
;@@ https://github.com/Oldes/Rebol-issues/issues/1018

0 commit comments

Comments
 (0)