ttypedarray.nim 889 B

12345678910111213141516171819202122
  1. import std/private/jsutils
  2. proc main()=
  3. template fn(a): untyped = jsConstructorName(a)
  4. doAssert fn(array[2, int8].default) == "Int8Array"
  5. doAssert fn(array[2, uint8].default) == "Uint8Array"
  6. doAssert fn(array[2, byte].default) == "Uint8Array"
  7. # doAssert fn(array[2, char].default) == "Uint8Array" # xxx fails; bug?
  8. doAssert fn(array[2, uint64].default) == "Array"
  9. # pending https://github.com/nim-lang/RFCs/issues/187 maybe use `BigUint64Array`
  10. doAssert fn([1'u8]) == "Uint8Array"
  11. doAssert fn([1'u16]) == "Uint16Array"
  12. doAssert fn([byte(1)]) == "Uint8Array"
  13. doAssert fn([1.0'f32]) == "Float32Array"
  14. doAssert fn(array[2, float32].default) == "Float32Array"
  15. doAssert fn(array[2, float].default) == "Float64Array"
  16. doAssert fn(array[2, float64].default) == "Float64Array"
  17. doAssert fn([1.0]) == "Float64Array"
  18. doAssert fn([1.0'f64]) == "Float64Array"
  19. main()