tunsignedconv.nim 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. # Tests unsigned literals and implicit conversion between uints and ints
  2. var h8:uint8 = 128
  3. var h16:uint16 = 32768
  4. var h32:uint32 = 2147483648'u32
  5. var h64:uint64 = 9223372036854775808'u64
  6. var foobar:uint64 = 9223372036854775813'u64 # Issue 728
  7. var v8:uint8 = 10
  8. var v16:uint16 = 10
  9. var v32:uint32 = 10
  10. var v64:uint64 = 10
  11. # u8 + literal produces u8:
  12. var a8: uint8 = v8 + 10
  13. var a16: uint16 = v16 + 10
  14. when false:
  15. var d8 = v8 + 10'i8
  16. var d16 = v8 + 10'i16
  17. var d32 = v8 + 10'i32
  18. when false:
  19. # these don't work yet because unsigned.nim is stupid. XXX We need to fix this.
  20. var f8 = v16 + 10'u8
  21. var f16 = v16 + 10'u16
  22. var f32 = v16 + 10'u32
  23. var g8 = v32 + 10'u8
  24. var g16 = v32 + 10'u16
  25. var g32 = v32 + 10'u32
  26. var ar: array[0..20, int]
  27. var n8 = ar[v8]
  28. var n16 = ar[v16]
  29. var n32 = ar[v32]
  30. var n64 = ar[v64]
  31. block t4176:
  32. var yyy: uint8 = 0
  33. yyy = yyy - 127
  34. doAssert type(yyy) is uint8
  35. # bug #13661
  36. proc fun(): uint = cast[uint](-1)
  37. const x0 = fun()
  38. doAssert typeof(x0) is uint
  39. discard $x0
  40. # bug #13671
  41. const x1 = cast[uint](-1)
  42. discard $(x1,)
  43. # bug #13698
  44. let n: csize = 1 # xxx should that be csize_t or is that essential here?
  45. doAssert $n.int32 == "1"