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

119 lines
2.3 KiB
HTML
Raw Normal View History

2010-10-11 18:22:01 -04:00
<!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
2011-05-01 08:28:00 -04:00
say = (msg) ->
2010-10-11 18:22:01 -04:00
div = document.createElement 'div'
div.appendChild document.createTextNode msg
stdout.appendChild div
msg
@test = (desc, fn) ->
2010-12-12 21:41:04 -05:00
fn()
@ok = (good, msg) ->
2010-10-11 18:22:01 -04:00
++total
if good then ++success else throw Error say msg
@eq = (x, y, msg) -> ok x is y, msg ? x + ' !== ' + y
2010-10-11 18:22:01 -04:00
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) ->
2010-12-22 20:10:21 -05:00
fn()
ok true
@arrayEq = (a, b, msg) -> ok arrayEqual(a,b), msg
@throws = (fun, err, msg) ->
2010-12-24 14:02:10 -05:00
try
fun()
catch e
if err
eq e, err
else
ok yes
return
ok no
2010-10-11 18:22:01 -04:00
run = (name) ->
2011-05-01 08:28:00 -04:00
CoffeeScript.load "#{name}.coffee", ->
say '\u2714 ' + name
2010-10-11 18:22:01 -04:00
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 = [
2011-05-01 08:28:00 -04:00
'arrays'
2010-10-11 18:22:01 -04:00
'assignment'
2011-05-01 08:28:00 -04:00
'booleans'
'classes'
'cluster'
2010-10-11 18:22:01 -04:00
'comments'
'compilation'
'comprehensions'
'control_flow'
2010-12-12 21:41:04 -05:00
'exception_handling'
'formatting'
'function_invocation'
2011-05-01 08:28:00 -04:00
'functions'
'helpers'
'importing'
'interpolation'
'javascript_literals'
2011-05-01 08:28:00 -04:00
'numbers'
'objects'
2010-12-12 21:41:04 -05:00
'operators'
'option_parser'
2011-05-01 08:28:00 -04:00
'ranges'
'regexps'
'scope'
'slicing_and_splicing'
'soaks'
2011-05-01 08:28:00 -04:00
'strings'
2010-10-11 18:22:01 -04:00
]
</script>
</body>
</html>