Skip to content

Commit

Permalink
FEAT: empty? to accept typesets
Browse files Browse the repository at this point in the history
It was already accepting bitsets, so why not to support typesets too. Added a few `typeset!` unit tests (not complete)
  • Loading branch information
Oldes committed Dec 4, 2019
1 parent 6632c61 commit f101d9f
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/boot/actions.r
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ head?: action [

tail?: action [
{Returns TRUE if series is at or past its end; or empty for other types.}
series [series! gob! port! bitset! map!]
series [series! gob! port! bitset! typeset! map!]
]

past?: action [
Expand Down
4 changes: 4 additions & 0 deletions src/core/t-typeset.c
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,10 @@
VAL_TYPESET(val) = ~VAL_TYPESET(val);
return R_ARG1;

case A_TAILQ:
// Necessary to make EMPTY? work:
return (VAL_TYPESET(val) == 0) ? R_TRUE : R_FALSE;

default:
Trap_Action(REB_TYPESET, action);
}
Expand Down
2 changes: 1 addition & 1 deletion src/mezz/mezz-series.r
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ REBOL [
empty?: make :tail? [
[
{Returns TRUE if empty or NONE, or for series if index is at or beyond its tail.}
series [series! object! gob! port! bitset! map! none!]
series [series! object! gob! port! bitset! typeset! map! none!]
]
]

Expand Down
1 change: 1 addition & 0 deletions src/tests/run-tests.r3
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ dt [ ;- delta time
wrap load %units/image-test.r3
wrap load %units/file-test.r3
wrap load %units/func-test.r3
wrap load %units/typeset-test.r3

recycle/torture
recycle
Expand Down
42 changes: 42 additions & 0 deletions src/tests/units/typeset-test.r3
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
Rebol [
Title: "Rebol3 typeset! test script"
Author: "Oldes, Peter W A Wood"
File: %typeset-test.r3
Tabs: 4
Needs: [%../quick-test-module.r3]
]

~~~start-file~~~ "typeset"

===start-group=== "typeset!"
--test-- "make typeset!"
--assert typeset? types: make typeset! [block! map! object!]
--test-- "find in typeset"
--assert find types block!
--assert find types map!
--assert find types object!
--assert not find types string!

--test-- "union of typesets"
types2: union types make typeset! [string!]
--assert typeset? types2
--assert find types2 string!

--test-- "complement of typesets"
not-types: complement types
--assert typeset? not-types
--assert find not-types integer!

--test-- "difference of typesets"
types3: difference types make typeset! [object!]
--assert typeset? types3
--assert not find types3 object!

--test-- "empty typeset test"
;@@ requested: https://github.com/red/REP/issues/55
--assert empty? make typeset! []
--assert not empty? types

===end-group===

~~~end-file~~~

0 comments on commit f101d9f

Please sign in to comment.