summary refs log tree commit diff stats
path: root/tests/constr/tconexpr.nim
diff options
context:
space:
mode:
authorflywind <43030857+xflywind@users.noreply.github.com>2020-07-09 07:51:18 +0800
committerGitHub <noreply@github.com>2020-07-09 01:51:18 +0200
commit00528cbc3c82ba33e8b9b551d5d86b1b6382c34a (patch)
treed027010ddc2acfa97b0c9af5228f4a195d2eb3c0 /tests/constr/tconexpr.nim
parent3db6d9ea0c96782955923be4a24f49c1b2cc06fc (diff)
downloadNim-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.nim43
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
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344