test2.nim 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. discard """
  2. output: '''foo
  3. js 3.14
  4. 7
  5. 1
  6. -21550
  7. -21550'''
  8. """
  9. # This file tests the JavaScript generator
  10. doAssert getCurrentException() == nil
  11. doAssert getCurrentExceptionMsg() == ""
  12. # #335
  13. proc foo() =
  14. var bar = "foo"
  15. proc baz() =
  16. echo bar
  17. baz()
  18. foo()
  19. # #376
  20. when not defined(js):
  21. proc foo(val: float): string = "no js " & $val
  22. else:
  23. proc foo(val: float): string = "js " & $val
  24. echo foo(3.14)
  25. # #2495
  26. type C = concept x
  27. proc test(x: C, T: typedesc): T =
  28. cast[T](x)
  29. echo 7.test(int8)
  30. # #4222
  31. const someConst = [ "1"]
  32. proc procThatRefersToConst() # Forward decl
  33. procThatRefersToConst() # Call bar before it is defined
  34. proc procThatRefersToConst() =
  35. var i = 0 # Use a var index, otherwise nim will constfold foo[0]
  36. echo someConst[i] # JS exception here: foo is still not initialized (undefined)
  37. # bug #6753
  38. let x = -1861876800
  39. const y = 86400
  40. echo (x - (y - 1)) div y # Now gives `-21550`
  41. proc foo09() =
  42. let x = -1861876800
  43. const y = 86400
  44. echo (x - (y - 1)) div y # Still gives `-21551`
  45. foo09()