☰

# testproject

Theme:

- Index

Search:
Group by:

# Basic usage

## Encoding data

Apart from strings you can also encode lists of integers or characters:

## Decoding data

This is the top level module.

Example:

    import testproject
    import subdir / subdir_b / utils
    doAssert bar(3, 4) == 7
    foo(enumValueA, enumValueB)
    # bug #11078
    for x in "xx": discard

top2

Example:

    import testproject
    discard "in top2"

top2 after

Example:

    import testproject
    discard "in top3"

top3 after

# Imports

subdir/subdir_b/utils

# Types

    A {.inject.} = enum
      aA

  The enum A.

    AnotherObject = object
      case x*: bool
      of true:
        y*: proc (x: string)
      of false:

    B {.inject.} = enum
      bB

  The enum B.

    Foo = enum
      enumValueA2

    FooBuzz {....deprecated: "FooBuzz msg".} = int

  Deprecated: FooBuzz msg

    MyObject = object
      someString*: string        ## This is a string
      annotated* {.somePragma.}: string ## This is an annotated string

    Shapes = enum
      Circle,                   ## A circle
      Triangle,                 ## A three-sided shape
      Rectangle                  ## A four-sided shape

  Some shapes.

    T19396 = object
      a*: int

    Xxx = object
      field*: int
      field3*: int               ## Doc comment2

# Vars

    aVariable: array[1, int]

    someVariable: bool

  This should be visible.

# Consts

    C_A = 0x7FF0000000000000'f64

    C_B = 0o377'i8

    C_C = 0o277'i8

    C_D = 0o177777'i16

# Procs

    proc addfBug14485() {....raises: [], tags: [], forbids: [].}

  Some proc

  Example:

      discard "foo() = " & $[1]
      #[
      0: let's also add some broken html to make sure this won't break in future
      1: </span>
      2: </span>
      3: </span
      4: </script>
      5: </script
      6: </script
      7: end of broken html
      ]#

    proc anything() {....raises: [], tags: [], forbids: [].}

  There is no block quote after blank lines at the beginning.

    proc asyncFun1(): Future[int] {....stackTrace: false,
                                    raises: [Exception, ValueError],
                                    tags: [RootEffect], forbids: [].}

  ok1

    proc asyncFun2(): owned(Future[void]) {....stackTrace: false, raises: [Exception],
                                            tags: [RootEffect], forbids: [].}

    proc asyncFun3(): owned(Future[void]) {....stackTrace: false, raises: [Exception],
                                            tags: [RootEffect], forbids: [].}

  Example:

      discard

  ok1

    proc bar(f: FooBuzz) {....raises: [], tags: [], forbids: [].}

    proc bar[T](a, b: T): T

    proc baz() {....raises: [], tags: [], forbids: [].}

    proc baz[T](a, b: T): T {....deprecated.}

  Deprecated
  This is deprecated without message.

    proc buzz[T](a, b: T): T {....deprecated: "since v0.20".}

  Deprecated: since v0.20
  This is deprecated with a message.

    proc c_nonexistent(frmt: cstring): cint {.importc: "nonexistent",
        header: "<stdio.h>", varargs, discardable, ...raises: [], tags: [], forbids: [].}

    proc c_printf(frmt: cstring): cint {.importc: "printf", header: "<stdio.h>",
                                         varargs, discardable, ...raises: [], tags: [],
                                         forbids: [].}

  the c printf. etc.

    proc fromUtils3() {....raises: [], tags: [], forbids: [].}

  came form utils but should be shown where `fromUtilsGen` is called

  Example:

      discard """should be shown as examples for fromUtils3
             in module calling fromUtilsGen"""

    proc isValid[T](x: T): bool

    proc low[T: Ordinal | enum | range](x: T): T {.magic: "Low", noSideEffect,
        ...raises: [], tags: [], forbids: [].}

  Returns the lowest possible value of an ordinal value `x`. As a special semantic rule, `x` may also be a type identifier.

  See also:

  - low2(T)

      low(2) # => -9223372036854775808

    proc low2[T: Ordinal | enum | range](x: T): T {.magic: "Low", noSideEffect,
        ...raises: [], tags: [], forbids: [].}

  Returns the lowest possible value of an ordinal value `x`. As a special semantic rule, `x` may also be a type identifier.

  See also:

  - low(T)

      low2(2) # => -9223372036854775808

  Example:

      discard "in low2"

    proc p1() {....raises: [], tags: [], forbids: [].}

  cp1

  Example:

      doAssert 1 == 1 # regular comments work here

  c4

  Example:

      # c5 regular comments before 1st token work
      # regular comment
      #[
      nested regular comment
      ]#
      doAssert 2 == 2 # c8
      ## this is a non-nested doc comment

      ##[
      this is a nested doc comment
      ]##
      discard "c9"
      # also work after

    func someFunc() {....raises: [], tags: [], forbids: [].}

  My someFunc. Stuff in `quotes` here. Some link

    proc tripleStrLitTest() {....raises: [], tags: [], forbids: [].}

  Example: cmd: --hint:XDeclaredButNotUsed:off

      ## mullitline string litterals are tricky as their indentation can span
      ## below that of the runnableExamples
      let s1a = """
      should appear at indent 0
        at indent 2
      at indent 0
      """
      # make sure this works too
      let s1b = """start at same line
        at indent 2
      at indent 0
      """ # comment after
      let s2 = """sandwich """
      let s3 = """"""
      when false:
        let s5 = """
              in s5 """

      let s3b = ["""
      %!? #[...] # inside a multiline ...
      """, "foo"]

      ## make sure handles trailing spaces
      let s4 = """
      """

      let s5 = """ x
      """
      let s6 = """ ""
      """
      let s7 = """"""""""
      let s8 = ["""""""""", """
        """ ]
      discard
      # should be in

    proc z1(): Foo {....raises: [], tags: [], forbids: [].}

  cz1

    proc z2() {....raises: [], tags: [], forbids: [].}

  cz2

  Example:

      discard "in cz2"

    proc z3() {....raises: [], tags: [], forbids: [].}

  cz3

    proc z4() {....raises: [], tags: [], forbids: [].}

  cz4

    proc z5(): int {....raises: [], tags: [], forbids: [].}

  cz5

    proc z6(): int {....raises: [], tags: [], forbids: [].}

  cz6

    proc z7(): int {....raises: [], tags: [], forbids: [].}

  cz7

    proc z8(): int {....raises: [], tags: [], forbids: [].}

  cz8

    proc z9() {....raises: [], tags: [], forbids: [].}

  Example:

      doAssert 1 + 1 == 2

    proc z10() {....raises: [], tags: [], forbids: [].}

  Example: cmd: -d:foobar

      discard 1

  cz10

    proc z11() {....raises: [], tags: [], forbids: [].}

  Example:

      discard 1

    proc z12(): int {....raises: [], tags: [], forbids: [].}

  Example:

      discard 1

    proc z13() {....raises: [], tags: [], forbids: [].}

  cz13

  Example:

      discard

    proc z17() {....raises: [], tags: [], forbids: [].}

  cz17 rest

  Example:

      discard 1

  rest

# Methods

    method method1(self: Moo) {.base, ...raises: [], tags: [], forbids: [].}

  foo1

    method method2(self: Moo): int {.base, ...raises: [], tags: [], forbids: [].}

  foo2

    method method3(self: Moo): int {.base, ...raises: [], tags: [], forbids: [].}

  foo3

# Iterators

    iterator fromUtils1(): int {....raises: [], tags: [], forbids: [].}

  Example:

      # ok1
      assert 1 == 1
      # ok2

    iterator iter1(n: int): int {....raises: [], tags: [], forbids: [].}

  foo1

    iterator iter2(n: int): int {....raises: [], tags: [], forbids: [].}

  foo2

  Example:

      discard # bar

# Macros

    macro bar(): untyped

    macro z16()

  Example:

      discard 1

  cz16 after

  Example:

      doAssert 2 == 1 + 1

    macro z18(): int

  cz18

# Templates

    template foo(a, b: SomeType)

  This does nothing

    template fromUtils2()

  ok3

  Example:

      discard """should be shown as examples for fromUtils2
             in module calling fromUtilsGen"""

    template myfn()

  Example:

      import std/strutils
      ## issue #8871 preserve formatting
      ## line doc comment
      # bar
      doAssert "'foo" == "'foo"
      ##[
      foo
      bar
      ]##

      doAssert: not "foo".startsWith "ba"
      block:
        discard 0xff # elu par cette crapule
      # should be in

  should be still in

    template somePragma() {.pragma.}

  Just some annotation

    template testNimDocTrailingExample()

  Example:

      discard 2

    template z6t(): int

  cz6t

    template z14()

  cz14

  Example:

      discard

    template z15()

  cz15

  Example:

      discard

  Example:

      discard 3

  Example:

      discard 4

  ok5 ok5b

  Example:

      assert true

  Example:

      discard 1

  in or out?