merging in the browser test suite.
This commit is contained in:
parent
f682bf642f
commit
2642fde0f8
File diff suppressed because one or more lines are too long
66
test.html
66
test.html
|
@ -1,66 +0,0 @@
|
|||
<!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>
|
|
@ -0,0 +1,96 @@
|
|||
<!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
|
||||
|
||||
this.ok = (good, msg) ->
|
||||
++total
|
||||
if good then ++success else throw Error say msg
|
||||
|
||||
this.eq = (x, y, msg) -> ok x is y, msg ? x + ' !== ' + y
|
||||
|
||||
this.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_#{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 = [
|
||||
'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'
|
||||
]
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
|
@ -113,7 +113,7 @@ persons = {
|
|||
|
||||
join1 = "#{key}: #{name}" for key, { name } of persons
|
||||
|
||||
deepEqual join1, ["George: Bob", "Bob: Alice", "Christopher: Stan"]
|
||||
eq join1.join(' / '), "George: Bob / Bob: Alice / Christopher: Stan"
|
||||
|
||||
persons = [
|
||||
{ name: "Bob", parent: { name: "George" } },
|
||||
|
@ -123,12 +123,12 @@ persons = [
|
|||
|
||||
join2 = "#{parent}: #{name}" for { name, parent: { name: parent } } in persons
|
||||
|
||||
deepEqual join1, join2
|
||||
eq join1.join(' '), join2.join(' ')
|
||||
|
||||
persons = [['Bob', ['George']], ['Alice', ['Bob']], ['Stan', ['Christopher']]]
|
||||
join3 = "#{parent}: #{name}" for [name, [parent]] in persons
|
||||
|
||||
deepEqual join2, join3
|
||||
eq join2.join(' '), join3.join(' ')
|
||||
|
||||
|
||||
# Pattern matching doesn't clash with implicit block objects.
|
||||
|
|
|
@ -9,7 +9,7 @@ result = a.concat(b).join(' ')
|
|||
ok result is "7 8 9 2 3"
|
||||
|
||||
a = [0, 1, 2, 3, 4, 5, 6, 7]
|
||||
deepEqual a[2...6], [2, 3, 4, 5]
|
||||
eq a[2...6].join(' '), '2 3 4 5'
|
||||
|
||||
|
||||
# Ranges.
|
||||
|
|
Loading…
Reference in New Issue