tmagics.nim 912 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. discard """
  2. output: '''
  3. true
  4. true
  5. false
  6. true
  7. true
  8. false
  9. true
  10. '''
  11. joinable: false
  12. """
  13. block tlowhigh:
  14. type myEnum = enum e1, e2, e3, e4, e5
  15. var a: array[myEnum, int]
  16. for i in low(a) .. high(a):
  17. a[i] = 0
  18. proc sum(a: openarray[int]): int =
  19. result = 0
  20. for i in low(a)..high(a):
  21. inc(result, a[i])
  22. doAssert sum([1, 2, 3, 4]) == 10
  23. block t8693:
  24. type Foo = int | float
  25. proc bar(t1, t2: typedesc): bool =
  26. echo (t1 is t2)
  27. (t2 is t1)
  28. proc bar[T](x: T, t2: typedesc): bool =
  29. echo (T is t2)
  30. (t2 is T)
  31. doAssert bar(int, Foo) == false
  32. doAssert bar(4, Foo) == false
  33. doAssert bar(any, int)
  34. doAssert bar(int, any) == false
  35. doAssert bar(Foo, Foo)
  36. doAssert bar(any, Foo)
  37. doAssert bar(Foo, any) == false
  38. block t9442:
  39. var v1: ref char
  40. var v2: string
  41. var v3: seq[char]
  42. GC_ref(v1)
  43. GC_unref(v1)
  44. GC_ref(v2)
  45. GC_unref(v2)
  46. GC_ref(v3)
  47. GC_unref(v3)