tconsttable.nim 658 B

1234567891011121314151617181920212223242526272829303132333435
  1. discard """
  2. output: '''is
  3. finally
  4. nice!'''
  5. """
  6. import tables
  7. const
  8. foo = {"ah": "finally", "this": "is", "possible.": "nice!"}.toTable()
  9. # protect against overly smart compiler:
  10. var x = "this"
  11. echo foo[x]
  12. x = "ah"
  13. echo foo[x]
  14. x = "possible."
  15. echo foo[x]
  16. block: # bug #19840
  17. const testBytes = [byte 0xD8, 0x08, 0xDF, 0x45, 0x00, 0x3D, 0x00, 0x52, 0x00, 0x61]
  18. var tempStr = "__________________"
  19. tempStr.prepareMutation
  20. copyMem(addr tempStr[0], addr testBytes[0], testBytes.len)
  21. block: # bug #22389
  22. func foo(): ptr UncheckedArray[byte] =
  23. const bar = [77.byte]
  24. cast[ptr UncheckedArray[byte]](addr bar[0])
  25. doAssert foo()[0] == 77