1
0
Fork 0
mirror of https://github.com/jashkenas/coffeescript.git synced 2022-11-09 12:23:24 -05:00
jashkenas--coffeescript/test/test.html
Michael Ficarra af4748d92b Fixing browser test suite for new filenames after reorganization.
Also added `global ?= window` where necessary. Firefox seems to be
complaining about an unexpected lambda still, though.
2011-01-03 04:37:29 -05:00

128 lines
2.6 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title>CoffeeScript Test Suite</title>
<script src="../extras/coffee-script.js"></script>
<style>
body {
margin: 30px;
font-family: Menlo, Monaco, monospace;
}
h1 {
font-size: 20px;
}
#stdout {
}
</style>
</head>
<body>
<h1>CoffeeScript Test Suite</h1>
<pre id="stdout"></pre>
<script type="text/coffeescript">
stdout = document.getElementById 'stdout'
start = new Date
success = total = done = failed = 0
say = (msg, yay) ->
div = document.createElement 'div'
div.appendChild document.createTextNode msg
div.style.color = if yay then 'green' else 'red'
stdout.appendChild div
msg
@test = (desc, fn) ->
fn()
@ok = (good, msg) ->
++total
if good then ++success else throw Error say msg
@eq = (x, y, msg) -> ok x is y, msg ? x + ' !== ' + y
arrayEqual = (a, b) ->
if a is b
# 0 isnt -0
a isnt 0 or 1/a is 1/b
else if a instanceof Array and b instanceof Array
return no unless a.length is b.length
return no for el, idx in a when not arrayEq el, b[idx]
yes
else
# NaN is NaN
a isnt a and b isnt b
@doesNotThrow = (fn) ->
fn()
ok true
@arrayEq = (a, b, msg) -> ok arrayEqual(a,b), msg
@throws = (fun, err, msg) ->
try
fun()
catch e
if err
eq e, err
else
ok yes
return
ok no
CoffeeScript.run = (code, cb) ->
try Function(CoffeeScript.compile code, wrap: no)()
catch e then cb(); throw e
cb yes
run = (name) ->
CoffeeScript.load "#{name}.coffee", (yay) ->
say "#{ if yay then '\u2714' else '\u3000' } #{name}", yay
++failed unless yay
fin() if ++done is names.length
fin = ->
yay = success is total and not failed
sec = (new Date - start) / 1000
msg = "passed #{success} tests in #{ sec.toFixed 2 } seconds"
msg = "failed #{ total - success } tests and #{msg}" unless yay
say msg, yay
run name for name in names = [
'array_literals'
'assignment'
'boolean_literals'
'cake'
'classes'
'command'
'comments'
'compilation'
'comprehensions'
'control_flow'
'exception_handling'
'formatting'
'function_invocation'
'function_literals'
'helpers'
'importing'
'interpolation'
'javascript_literals'
'number_literals'
'object_literals'
'operators'
'option_parser'
'range_literals'
'regular_expression_literals'
'repl'
'scope'
'slicing_and_splicing'
'soaks'
'string_literals'
]
</script>
</body>
</html>