diff options
author | Timothee Cour <timothee.cour2@gmail.com> | 2019-07-22 07:22:57 -0700 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2019-07-22 16:22:57 +0200 |
commit | 8c93c692b95da7b19a88cc0d56a8cdd20e3ae576 (patch) | |
tree | beb483894fa86518ab65f95b2c8c8536d37234b5 /lib | |
parent | 30f2cec67164e3e774a4dd5948828a5c6a439532 (diff) | |
download | Nim-8c93c692b95da7b19a88cc0d56a8cdd20e3ae576.tar.gz |
run runnableExamples in the module scope (#11732) [feature]
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pure/uri.nim | 4 | ||||
-rw-r--r-- | lib/system.nim | 10 |
2 files changed, 8 insertions, 6 deletions
diff --git a/lib/pure/uri.nim b/lib/pure/uri.nim index c0c78d735..088786f25 100644 --- a/lib/pure/uri.nim +++ b/lib/pure/uri.nim @@ -198,8 +198,8 @@ proc initUri*(): Uri = ## **See also:** ## * `Uri type <#Uri>`_ for available fields in the URI type runnableExamples: - var uri: Uri - assert initUri() == uri + var uri2: Uri + assert initUri() == uri2 result = Uri(scheme: "", username: "", password: "", hostname: "", port: "", path: "", query: "", anchor: "") diff --git a/lib/system.nim b/lib/system.nim index a588a85b9..28eb1a1ef 100644 --- a/lib/system.nim +++ b/lib/system.nim @@ -128,7 +128,7 @@ when defined(nimHasRunnableExamples): ## a ``runnableExamples`` section is ignored. ## - The documentation generator is aware of these examples and considers them ## part of the ``##`` doc comment. As the last step of documentation - ## generation the examples are put into an ``$file_example.nim`` file, + ## generation each runnableExample is put in its own file ``$file_examples$i.nim``, ## compiled and tested. The collected examples are ## put into their own module to ensure the examples do not refer to ## non-exported symbols. @@ -136,12 +136,14 @@ when defined(nimHasRunnableExamples): ## Usage: ## ## .. code-block:: Nim - ## proc double(x: int): int = + ## proc double*(x: int): int = ## ## This proc doubles a number. ## runnableExamples: + ## ## at module scope ## assert double(5) == 10 - ## assert double(21) == 42 - ## + ## block: ## at block scope + ## defer: echo "done" + ## ## result = 2 * x else: template runnableExamples*(body: untyped) = |