diff options
author | flywind <43030857+xflywind@users.noreply.github.com> | 2020-07-09 07:51:18 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-09 01:51:18 +0200 |
commit | 00528cbc3c82ba33e8b9b551d5d86b1b6382c34a (patch) | |
tree | d027010ddc2acfa97b0c9af5228f4a195d2eb3c0 /tests/constr/tconexpr.nim | |
parent | 3db6d9ea0c96782955923be4a24f49c1b2cc06fc (diff) | |
download | Nim-00528cbc3c82ba33e8b9b551d5d86b1b6382c34a.tar.gz |
Add testcase for #10465 (#14943)
* add debug format string * remove try except * add changelog * add docs and more tests * Update lib/pure/strformat.nim Co-authored-by: Juan Carlos <juancarlospaco@gmail.com> * minor * add testcase Co-authored-by: Juan Carlos <juancarlospaco@gmail.com>
Diffstat (limited to 'tests/constr/tconexpr.nim')
-rw-r--r-- | tests/constr/tconexpr.nim | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/tests/constr/tconexpr.nim b/tests/constr/tconexpr.nim new file mode 100644 index 000000000..cca6dd84f --- /dev/null +++ b/tests/constr/tconexpr.nim @@ -0,0 +1,43 @@ +discard """ + nimout: ''' +Fibonacci sequence: 0, 1, 1, 2, 3 +Sequence continues: 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610 +''' +""" + + +import strformat + +var fib_n {.compileTime.}: int +var fib_prev {.compileTime.}: int +var fib_prev_prev {.compileTime.}: int + +proc next_fib(): int {.compileTime.} = + let fib = if fib_n < 2: + fib_n + else: + fib_prev_prev + fib_prev + inc(fib_n) + fib_prev_prev = fib_prev + fib_prev = fib + fib + +const f0 = next_fib() +const f1 = next_fib() +const f2 = next_fib() +const f3 = next_fib() +const f4 = next_fib() + +static: + echo fmt"Fibonacci sequence: {f0}, {f1}, {f2}, {f3}, {f4}" + +const fib_continues = block: + var result = fmt"Sequence continues: " + for i in 0..10: + if i > 0: + add(result, ", ") + add(result, $next_fib()) + result + +static: + echo fib_continues \ No newline at end of file |