fix #17159 items(cstring) works in VM (#17160)

* fix #17159 items(cstring) works in VM

* improve test coverage tests/stdlib/tcstring.nim; add helpers: whenRuntimeJs, whenVMorJs

* document items(cstring)

* address comments
This commit is contained in:
Timothee Cour 2021-02-24 05:01:06 -08:00 • committed by GitHub
commit 11a7fa68f6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 155 additions and 43 deletions

View file

@ -42,3 +42,27 @@ template enableRemoteNetworking*: bool =
## process calls, e.g. `testament all` calls itself, which in turns invokes
## a `nim` invocation (possibly via additional intermediate processes).
getEnv("NIM_TESTAMENT_REMOTE_NETWORKING") == "1"
template whenRuntimeJs*(bodyIf, bodyElse) =
##[
Behaves as `when defined(js) and not nimvm` (which isn't legal yet).
pending improvements to `nimvm`, this sugar helps; use as follows:
whenRuntimeJs:
doAssert defined(js)
when nimvm: doAssert false
else: discard
do:
discard
]##
when nimvm: bodyElse
else:
when defined(js): bodyIf
else: bodyElse
template whenVMorJs*(bodyIf, bodyElse) =
## Behaves as: `when defined(js) or nimvm`
when nimvm: bodyIf
else:
when defined(js): bodyIf
else: bodyElse