/test/test.html

http://github.com/jashkenas/coffee-script · HTML · 120 lines · 105 code · 15 blank · 0 comment · 0 complexity · 1a7c8bf3f99260d6f5acbfacfd43e92d MD5 · raw file

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
  5. <title>CoffeeScript Test Suite</title>
  6. <script src="../extras/coffee-script.js"></script>
  7. <style>
  8. body {
  9. margin: 30px;
  10. font-family: Menlo, Monaco, monospace;
  11. }
  12. h1 {
  13. font-size: 20px;
  14. }
  15. #stdout {
  16. }
  17. </style>
  18. </head>
  19. <body>
  20. <h1>CoffeeScript Test Suite</h1>
  21. <pre id="stdout"></pre>
  22. <script type="text/coffeescript">
  23. stdout = document.getElementById 'stdout'
  24. start = new Date
  25. success = total = done = failed = 0
  26. say = (msg) ->
  27. div = document.createElement 'div'
  28. div.appendChild document.createTextNode msg
  29. stdout.appendChild div
  30. msg
  31. @test = (desc, fn) ->
  32. fn()
  33. @ok = (good, msg) ->
  34. ++total
  35. if good then ++success else throw Error say msg
  36. @eq = (x, y, msg) -> ok x is y, msg ? x + ' !== ' + y
  37. arrayEqual = (a, b) ->
  38. if a is b
  39. # 0 isnt -0
  40. a isnt 0 or 1/a is 1/b
  41. else if a instanceof Array and b instanceof Array
  42. return no unless a.length is b.length
  43. return no for el, idx in a when not arrayEq el, b[idx]
  44. yes
  45. else
  46. # NaN is NaN
  47. a isnt a and b isnt b
  48. @doesNotThrow = (fn) ->
  49. fn()
  50. ok true
  51. @arrayEq = (a, b, msg) -> ok arrayEqual(a,b), msg
  52. @throws = (fun, err, msg) ->
  53. try
  54. fun()
  55. catch e
  56. if err
  57. eq e, err
  58. else
  59. ok yes
  60. return
  61. ok no
  62. run = (name) ->
  63. CoffeeScript.load "#{name}.coffee", ->
  64. say '\u2714 ' + name
  65. fin() if ++done is names.length
  66. fin = ->
  67. yay = success is total and not failed
  68. sec = (new Date - start) / 1000
  69. msg = "passed #{success} tests in #{ sec.toFixed 2 } seconds"
  70. msg = "failed #{ total - success } tests and #{msg}" unless yay
  71. say msg, yay
  72. run name for name in names = [
  73. 'arrays'
  74. 'assignment'
  75. 'booleans'
  76. 'classes'
  77. 'cluster'
  78. 'comments'
  79. 'compilation'
  80. 'comprehensions'
  81. 'control_flow'
  82. 'exception_handling'
  83. 'formatting'
  84. 'function_invocation'
  85. 'functions'
  86. 'helpers'
  87. 'importing'
  88. 'interpolation'
  89. 'javascript_literals'
  90. 'numbers'
  91. 'objects'
  92. 'operators'
  93. 'option_parser'
  94. 'ranges'
  95. 'regexps'
  96. 'scope'
  97. 'slicing_and_splicing'
  98. 'soaks'
  99. 'strings'
  100. ]
  101. # allow utf-8 chars in comments
  102. # 智に働けば角が立つ情に掉させば流される
  103. </script>
  104. </body>
  105. </html>