PageRenderTime 27ms CodeModel.GetById 12ms app.highlight 11ms RepoModel.GetById 1ms app.codeStats 0ms

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