1
0
Fork 0
mirror of https://github.com/jashkenas/coffeescript.git synced 2022-11-09 12:23:24 -05:00

added test.html that runs most of test/*.coffee in browsers

This commit is contained in:
satyr 2010-10-12 02:04:51 +09:00
parent a4b6b2464c
commit 5ed69a5a58
4 changed files with 76 additions and 18 deletions

66
test.html Normal file
View file

@ -0,0 +1,66 @@
<!DOCTYPE html>
<title>CoffeeScript Test Suite</title>
<pre id="stdout"></pre>
<script src="extras/coffee-script.js"></script>
<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
self.ok = (good, msg) ->
++total
if good then ++success else throw Error say msg
self.eq = (x, y, msg) -> ok x is y, msg ? x + ' !== ' + y
self.deepEqual = (x, y, msg) -> eq JSON.stringify(x), JSON.stringify(y), msg
self.throws = (fun, err, msg) ->
try fun(); throw new String 'No Error'
catch e then eq e, err
CoffeeScript.run = (code, cb) ->
try Function(CoffeeScript.compile code, wrap: no)()
catch e then cb(); throw e
cb yes
run = (name) ->
CoffeeScript.load "test/test_#{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) / 1e3
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 = '''
arguments
assignment
blocks
break
chaining
classes
comments
compilation
compound_assignment
comprehensions
existence
expressions
functions
helpers
heredocs
if
literals
operations
pattern_matching
regexps
returns
splats
string_interpolation
switch
try_catch
while
'''.split '\n'
</script>

View file

@ -1,19 +1,11 @@
# Ensure that carriage returns don't break compilation on Windows.
js = CoffeeScript.compile("one\r\ntwo", {wrap: off})
eq CoffeeScript.compile('one\r\ntwo', wrap: off), 'one;\ntwo;'
ok js is "one;\ntwo;"
# `globals: on` removes `var`s
eq CoffeeScript.compile('x = y', wrap: off, globals: on), 'x = y;'
global.resultArray = []
CoffeeScript.run("resultArray.push i for i of global", {wrap: off, globals: on, fileName: 'tests'})
ok 'setInterval' in global.resultArray
ok 'passed' is CoffeeScript.eval '"passed"', wrap: off, globals: on, fileName: 'tests'
ok 'passed' is CoffeeScript.eval '"passed"', wrap: off, fileName: 'test'
#750
try
CoffeeScript.nodes 'f(->'
ok no
catch e
eq e.message, 'unclosed CALL_START on line 1'
try ok not CoffeeScript.nodes 'f(->'
catch e then eq e.message, 'unclosed CALL_START on line 1'

View file

@ -60,7 +60,7 @@ eq value?.toString().toLowerCase(), undefined
value = 10
eq value?.toString().toLowerCase(), '10'
eq process.exit.nothing?.property() or 101, 101
eq 0.nothing?.property() or 101, 101
counter = 0
func = ->

View file

@ -22,16 +22,16 @@ obj = {
name: 'Fred'
bound: ->
(=> ok(this.name is 'Fred'))()
(=> eq this, obj)()
unbound: ->
(-> ok(!this.name?))()
(-> ok this isnt obj)()
nested: ->
(=>
(=>
(=>
ok this.name is 'Fred'
eq this, obj
)()
)()
)()