@@ -1343,6 +1343,63 @@ Rebol [
1343
1343
===end-group===
1344
1344
1345
1345
1346
+ ===start-group=== "REWORD"
1347
+ --test-- "reword"
1348
+ ;@@ https://github.com/Oldes/Rebol-issues/issues/1990
1349
+
1350
+ --assert (reword/escape "ba" [a 1 b 2 ] none)
1351
+ == "21" ; /escape none like /escape ""
1352
+
1353
+ --assert (reword "$a$A$a" [a 1 A 2 ])
1354
+ == "222" ; case-insensitive, last value wins
1355
+ --assert (reword/case "$a$A$a" [a 1 A 2 ])
1356
+ == "121" ; case-sensitive, even with words
1357
+
1358
+ --assert (reword/escape "<bang>" [bang "!" ] ["<" ">" ])
1359
+ == "!" ; Leading and trailing delimiters considered
1360
+ --assert (reword/escape "<bang>bang>" [bang "!" ] ["<" ">" ])
1361
+ == "!bang>" ; One-pass, continues after the replacement
1362
+ --assert (reword/escape "!bang;bang;" [bang "!" ] ["!" ])
1363
+ == "!;bang;" ; No trailing delimiter specified
1364
+
1365
+ --assert (reword "$a" ["a" ["A" "B" "C" ]])
1366
+ == "C" ; evaluate a block value as code by default
1367
+ --assert (reword/only "$a" ["a" ["A" "B" "C" ]])
1368
+ == "ABC" ; Just insert a block value with /only
1369
+
1370
+ --assert (reword "$a$b$+" [a 1 + 1 b 2 + 2 ])
1371
+ == "24$+" ; Value expressions evaluated, keys treated as literals
1372
+ --assert (reword/only "$a$b$+" [a 1 + 1 b 2 + 2 ])
1373
+ == "122" ; With /only, treated as raw values, + keyword defined twice in this case
1374
+ --assert (reword "$a ($b)" ["a" does ["AAA" ] "b" ()])
1375
+ == "AAA ($b)" ; Evaluates function builders and parens too. Note that b was undefined because () evaluates to unset
1376
+ --assert (reword/only "$a ($b)" reduce ["a" does ["AAA" ] "b" ["B" "B" "B" ]])
1377
+ == "AAA (BBB)" ; With /only of explicitly reduced spec, functions still called even though blocks are just inserted
1378
+
1379
+ --assert (reword "$a" [a: 1 ])
1380
+ == "1" ; It should be easy to switch from block to object specs
1381
+ --assert (reword "$a" context [a: 1 ])
1382
+ == "1" ; ... like this, so we should special-case set-words
1383
+ --assert (reword "$a" ['a 1 ])
1384
+ == "1" ; It should be easy to explicitly reduce the same spec
1385
+ --assert (reword "$a" reduce ['a 1 ])
1386
+ == "1" ; ... like this, so we should special-case lit-words
1387
+ --assert (reword/escape "a :a /a #a" [a 1 :a 2 /a 3 #a 4 ] none)
1388
+ == "1 2 3 4" ; But otherwise let word types be distinct
1389
+
1390
+ --assert (reword to-binary "$a$A$a" [a 1 A 2 ])
1391
+ == #{ 010201 } ; binaries supported, note the case-sensitivity, same key rules, values inserted by binary rules
1392
+ --assert (tail? reword/into to-binary "$a$A$a" [a 1 A 2 ] #{} )
1393
+ == true ; /into option behaves the same
1394
+ --assert (head reword/into "$a$A$a" [a 1 A 2 ] #{} )
1395
+ == #{ 020202 } ; string templates can insert into binaries, note the case-insensitivity
1396
+ --assert (head reword/case/into "$a$A$a" [a 1 A 2 ] #{} )
1397
+ == #{ 010201 } ; ... and this time it's case-sensitive
1398
+ --assert (head reword/into to-binary "b$a$A$ac" [a 1 A 2 ] "" )
1399
+ == "b121c" ; Binary templates can insert into strings, using string insert rules, still case-sensitive
1400
+
1401
+ ===end-group===
1402
+
1346
1403
;-- VECTOR related tests moved to %vector-test.r3
1347
1404
1348
1405
~~~end-file~~~
0 commit comments