mirror of
https://github.com/jashkenas/coffeescript.git
synced 2022-11-09 12:23:24 -05:00
Refactor test.html to be part of the docs output, with the tests embedded inside it; update test.html styles; move UTF-8 comment test out of test.html and into test/comments.coffee where it belongs
This commit is contained in:
parent
6d29086519
commit
06b3180223
4 changed files with 134 additions and 118 deletions
29
Cakefile
29
Cakefile
|
@ -183,6 +183,25 @@ task 'doc:site', 'watch and continually rebuild the documentation for the websit
|
||||||
</b>
|
</b>
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
testsInScriptBlocks = ->
|
||||||
|
output = ''
|
||||||
|
for filename in fs.readdirSync 'test'
|
||||||
|
if filename.indexOf('.coffee') isnt -1
|
||||||
|
type = 'coffeescript'
|
||||||
|
else if filename.indexOf('.litcoffee') isnt -1
|
||||||
|
type = 'literate-coffeescript'
|
||||||
|
else
|
||||||
|
continue
|
||||||
|
|
||||||
|
# Set the type to text/x-coffeescript or text/x-literate-coffeescript
|
||||||
|
# to prevent the browser compiler from automatically running the script
|
||||||
|
output += """
|
||||||
|
<script type="text/x-#{type}" class="test" id="#{filename.split('.')[0]}">
|
||||||
|
#{fs.readFileSync "test/#{filename}", 'utf-8'}
|
||||||
|
</script>\n
|
||||||
|
"""
|
||||||
|
output
|
||||||
|
|
||||||
# Task
|
# Task
|
||||||
examplesSourceFolder = 'documentation/examples'
|
examplesSourceFolder = 'documentation/examples'
|
||||||
examplesOutputFolder = "docs/v#{majorVersion}/examples"
|
examplesOutputFolder = "docs/v#{majorVersion}/examples"
|
||||||
|
@ -200,10 +219,20 @@ task 'doc:site', 'watch and continually rebuild the documentation for the websit
|
||||||
fs.writeFileSync "docs/v#{majorVersion}/index.html", output
|
fs.writeFileSync "docs/v#{majorVersion}/index.html", output
|
||||||
log 'compiled', green, "#{indexFile} → docs/v#{majorVersion}/index.html"
|
log 'compiled', green, "#{indexFile} → docs/v#{majorVersion}/index.html"
|
||||||
|
|
||||||
|
testFile = 'documentation/test.html'
|
||||||
|
do renderTest = ->
|
||||||
|
render = _.template fs.readFileSync(testFile, 'utf-8')
|
||||||
|
output = render
|
||||||
|
tests: testsInScriptBlocks()
|
||||||
|
majorVersion: majorVersion
|
||||||
|
fs.writeFileSync "docs/v#{majorVersion}/test.html", output
|
||||||
|
log 'compiled', green, "#{testFile} → docs/v#{majorVersion}/test.html"
|
||||||
|
|
||||||
fs.watch examplesSourceFolder, interval: 200, ->
|
fs.watch examplesSourceFolder, interval: 200, ->
|
||||||
renderExamples()
|
renderExamples()
|
||||||
renderIndex()
|
renderIndex()
|
||||||
fs.watch indexFile, interval: 200, renderIndex
|
fs.watch indexFile, interval: 200, renderIndex
|
||||||
|
fs.watch testFile, interval: 200, renderTest
|
||||||
log 'watching...' , green
|
log 'watching...' , green
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
v1
|
|
|
@ -3,119 +3,103 @@
|
||||||
<head>
|
<head>
|
||||||
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
|
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
|
||||||
<title>CoffeeScript Test Suite</title>
|
<title>CoffeeScript Test Suite</title>
|
||||||
<script src="../docs/current/browser-compiler/coffee-script.js"></script>
|
<script src="browser-compiler/coffee-script.js"></script>
|
||||||
<style>
|
<style>
|
||||||
|
body, pre {
|
||||||
|
font-family: Consolas, Menlo, Monaco, monospace;
|
||||||
|
}
|
||||||
body {
|
body {
|
||||||
margin: 30px;
|
margin: 1em;
|
||||||
font-family: Menlo, Monaco, monospace;
|
|
||||||
}
|
}
|
||||||
h1 {
|
h1 {
|
||||||
font-size: 20px;
|
font-size: 1.3em;
|
||||||
}
|
}
|
||||||
#stdout {
|
div {
|
||||||
|
margin: 0.6em;
|
||||||
|
}
|
||||||
|
.good {
|
||||||
|
color: #22b24c
|
||||||
|
}
|
||||||
|
.bad {
|
||||||
|
color: #eb6864
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<h1>CoffeeScript Test Suite</h1>
|
<h1>CoffeeScript Test Suite</h1>
|
||||||
<pre id="stdout"></pre>
|
|
||||||
|
|
||||||
<script type="text/coffeescript">
|
<pre id="stdout"></pre>
|
||||||
|
|
||||||
stdout = document.getElementById 'stdout'
|
<script type="text/coffeescript">
|
||||||
start = new Date
|
stdout = document.getElementById 'stdout'
|
||||||
success = total = done = failed = 0
|
start = new Date
|
||||||
|
success = total = done = failed = 0
|
||||||
|
|
||||||
say = (msg) ->
|
say = (msg, emphasis) ->
|
||||||
div = document.createElement 'div'
|
div = document.createElement 'div'
|
||||||
div.appendChild document.createTextNode msg
|
if emphasis?
|
||||||
stdout.appendChild div
|
div.className = if emphasis then 'good' else 'bad'
|
||||||
msg
|
div.appendChild document.createTextNode msg
|
||||||
|
stdout.appendChild div
|
||||||
|
msg
|
||||||
|
|
||||||
@test = (desc, fn) ->
|
@test = (desc, fn) ->
|
||||||
fn()
|
fn()
|
||||||
|
|
||||||
@ok = (good, msg) ->
|
@ok = (good, msg) ->
|
||||||
++total
|
++total
|
||||||
if good then ++success else throw Error say msg
|
if good then ++success else throw Error say msg, no
|
||||||
|
|
||||||
@eq = (x, y, msg) -> ok x is y, msg ? x + ' !== ' + y
|
@eq = (x, y, msg) -> ok x is y, msg ? x + ' isnt ' + y
|
||||||
|
|
||||||
arrayEqual = (a, b) ->
|
arrayEqual = (a, b) ->
|
||||||
if a is b
|
if a is b
|
||||||
# 0 isnt -0
|
# 0 isnt -0
|
||||||
a isnt 0 or 1/a is 1/b
|
a isnt 0 or 1/a is 1/b
|
||||||
else if a instanceof Array and b instanceof Array
|
else if a instanceof Array and b instanceof Array
|
||||||
return no unless a.length is b.length
|
return no unless a.length is b.length
|
||||||
return no for el, idx in a when not arrayEq el, b[idx]
|
return no for el, idx in a when not arrayEq el, b[idx]
|
||||||
yes
|
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
|
else
|
||||||
# NaN is NaN
|
ok yes
|
||||||
a isnt a and b isnt b
|
return
|
||||||
|
ok no
|
||||||
|
|
||||||
@doesNotThrow = (fn) ->
|
|
||||||
fn()
|
|
||||||
ok true
|
|
||||||
|
|
||||||
@arrayEq = (a, b, msg) -> ok arrayEqual(a,b), msg
|
# Run the tests
|
||||||
|
for test in document.getElementsByClassName 'test'
|
||||||
|
say '\u2714 ' + test.id
|
||||||
|
try
|
||||||
|
CoffeeScript.run test.innerHTML
|
||||||
|
catch exception
|
||||||
|
console.error exception
|
||||||
|
|
||||||
@throws = (fun, err, msg) ->
|
# Finish up
|
||||||
try
|
yay = success is total and not failed
|
||||||
fun()
|
sec = (new Date - start) / 1000
|
||||||
catch e
|
msg = "passed #{success} tests in #{ sec.toFixed 2 } seconds"
|
||||||
if err
|
msg = "failed #{ total - success } tests and #{msg}" unless yay
|
||||||
eq e, err
|
say msg, yay
|
||||||
else
|
</script>
|
||||||
ok yes
|
|
||||||
return
|
|
||||||
ok no
|
|
||||||
|
|
||||||
run = (name) ->
|
<%= tests %>
|
||||||
CoffeeScript.load "#{name}.coffee", ->
|
|
||||||
say '\u2714 ' + name
|
|
||||||
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 = [
|
|
||||||
'arrays'
|
|
||||||
'assignment'
|
|
||||||
'booleans'
|
|
||||||
'classes'
|
|
||||||
'cluster'
|
|
||||||
'comments'
|
|
||||||
'compilation'
|
|
||||||
'comprehensions'
|
|
||||||
'control_flow'
|
|
||||||
'exception_handling'
|
|
||||||
'formatting'
|
|
||||||
'function_invocation'
|
|
||||||
'functions'
|
|
||||||
'helpers'
|
|
||||||
'importing'
|
|
||||||
'interpolation'
|
|
||||||
'javascript_literals'
|
|
||||||
'modules'
|
|
||||||
'numbers'
|
|
||||||
'objects'
|
|
||||||
'operators'
|
|
||||||
'option_parser'
|
|
||||||
'ranges'
|
|
||||||
'regexps'
|
|
||||||
'scope'
|
|
||||||
'slicing_and_splicing'
|
|
||||||
'soaks'
|
|
||||||
'strings'
|
|
||||||
]
|
|
||||||
# allow utf-8 chars in comments
|
|
||||||
# 智に働けば角が立つ、情に掉させば流される。
|
|
||||||
</script>
|
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -293,25 +293,25 @@ test "#3132: Format jsdoc-style block-comment nicely", ->
|
||||||
input = """
|
input = """
|
||||||
###*
|
###*
|
||||||
# Multiline for jsdoc-"@doctags"
|
# Multiline for jsdoc-"@doctags"
|
||||||
#
|
#
|
||||||
# @type {Function}
|
# @type {Function}
|
||||||
###
|
###
|
||||||
fn = () -> 1
|
fn = () -> 1
|
||||||
"""
|
"""
|
||||||
|
|
||||||
result = """
|
result = """
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Multiline for jsdoc-"@doctags"
|
* Multiline for jsdoc-"@doctags"
|
||||||
*
|
*
|
||||||
* @type {Function}
|
* @type {Function}
|
||||||
*/
|
*/
|
||||||
var fn;
|
var fn;
|
||||||
|
|
||||||
fn = function() {
|
fn = function() {
|
||||||
return 1;
|
return 1;
|
||||||
};
|
};
|
||||||
|
|
||||||
"""
|
"""
|
||||||
eq CoffeeScript.compile(input, bare: on), result
|
eq CoffeeScript.compile(input, bare: on), result
|
||||||
|
|
||||||
|
@ -321,25 +321,25 @@ test "#3132: Format hand-made (raw) jsdoc-style block-comment nicely", ->
|
||||||
input = """
|
input = """
|
||||||
###*
|
###*
|
||||||
* Multiline for jsdoc-"@doctags"
|
* Multiline for jsdoc-"@doctags"
|
||||||
*
|
*
|
||||||
* @type {Function}
|
* @type {Function}
|
||||||
###
|
###
|
||||||
fn = () -> 1
|
fn = () -> 1
|
||||||
"""
|
"""
|
||||||
|
|
||||||
result = """
|
result = """
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Multiline for jsdoc-"@doctags"
|
* Multiline for jsdoc-"@doctags"
|
||||||
*
|
*
|
||||||
* @type {Function}
|
* @type {Function}
|
||||||
*/
|
*/
|
||||||
var fn;
|
var fn;
|
||||||
|
|
||||||
fn = function() {
|
fn = function() {
|
||||||
return 1;
|
return 1;
|
||||||
};
|
};
|
||||||
|
|
||||||
"""
|
"""
|
||||||
eq CoffeeScript.compile(input, bare: on), result
|
eq CoffeeScript.compile(input, bare: on), result
|
||||||
|
|
||||||
|
@ -349,54 +349,54 @@ test "#3132: Place block-comments nicely", ->
|
||||||
input = """
|
input = """
|
||||||
###*
|
###*
|
||||||
# A dummy class definition
|
# A dummy class definition
|
||||||
#
|
#
|
||||||
# @class
|
# @class
|
||||||
###
|
###
|
||||||
class DummyClass
|
class DummyClass
|
||||||
|
|
||||||
###*
|
###*
|
||||||
# @constructor
|
# @constructor
|
||||||
###
|
###
|
||||||
constructor: ->
|
constructor: ->
|
||||||
|
|
||||||
###*
|
###*
|
||||||
# Singleton reference
|
# Singleton reference
|
||||||
#
|
#
|
||||||
# @type {DummyClass}
|
# @type {DummyClass}
|
||||||
###
|
###
|
||||||
@instance = new DummyClass()
|
@instance = new DummyClass()
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
result = """
|
result = """
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A dummy class definition
|
* A dummy class definition
|
||||||
*
|
*
|
||||||
* @class
|
* @class
|
||||||
*/
|
*/
|
||||||
var DummyClass;
|
var DummyClass;
|
||||||
|
|
||||||
DummyClass = (function() {
|
DummyClass = (function() {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
function DummyClass() {}
|
function DummyClass() {}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Singleton reference
|
* Singleton reference
|
||||||
*
|
*
|
||||||
* @type {DummyClass}
|
* @type {DummyClass}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
DummyClass.instance = new DummyClass();
|
DummyClass.instance = new DummyClass();
|
||||||
|
|
||||||
return DummyClass;
|
return DummyClass;
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
|
||||||
"""
|
"""
|
||||||
eq CoffeeScript.compile(input, bare: on), result
|
eq CoffeeScript.compile(input, bare: on), result
|
||||||
|
|
||||||
|
@ -427,3 +427,7 @@ test "#3761: Multiline comment at end of an object", ->
|
||||||
###
|
###
|
||||||
|
|
||||||
ok anObject.x is 3
|
ok anObject.x is 3
|
||||||
|
|
||||||
|
test "#4375: UTF-8 characters in comments", ->
|
||||||
|
# 智に働けば角が立つ、情に掉させば流される。
|
||||||
|
ok yes
|
||||||
|
|
Loading…
Reference in a new issue