From 00528cbc3c82ba33e8b9b551d5d86b1b6382c34a Mon Sep 17 00:00:00 2001 From: flywind <43030857+xflywind@users.noreply.github.com> Date: Thu, 9 Jul 2020 07:51:18 +0800 Subject: [PATCH] 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 * minor * add testcase Co-authored-by: Juan Carlos --- tests/constr/tconexpr.nim | 43 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 tests/constr/tconexpr.nim diff --git a/tests/constr/tconexpr.nim b/tests/constr/tconexpr.nim new file mode 100644 index 0000000000..cca6dd84f6 --- /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