diff --git a/Cakefile b/Cakefile index 8f763d0c7d..d276c4e942 100644 --- a/Cakefile +++ b/Cakefile @@ -45,60 +45,6 @@ run = (args, cb) -> log = (message, color, explanation) -> console.log color + message + reset + ' ' + (explanation or '') -codeFor = -> - counter = 0 - hljs = require 'highlight.js' - hljs.configure classPrefix: '' - (file, executable = false, showLoad = true) -> - counter++ - return unless fs.existsSync "docs/v#{majorVersion}/examples/#{file}.js" - cs = fs.readFileSync "documentation/examples/#{file}.coffee", 'utf-8' - js = fs.readFileSync "docs/v#{majorVersion}/examples/#{file}.js", 'utf-8' - js = js.replace /^\/\/ generated.*?\n/i, '' - - cshtml = "
#{hljs.highlight('coffeescript', cs).value}
" - # Temporary fix until highlight.js adds support for newer CoffeeScript keywords - # Added in https://github.com/isagalaev/highlight.js/pull/1357, awaiting release - if file in ['generator_iteration', 'generators', 'modules'] - cshtml = cshtml.replace /(yield|import|export|from|as|default) /g, '$1 ' - jshtml = "
#{hljs.highlight('javascript', js).value}
" - append = if executable is yes then '' else "alert(#{executable});" - if executable and executable isnt yes - cs.replace /(\S)\s*\Z/m, "$1\n\nalert #{executable}" - run = if executable is true then 'run' else "run: #{executable}" - name = "example#{counter}" - script = "" - load = if showLoad then "
load
" else '' - button = if executable then "
#{run}
" else '' - "
#{cshtml}#{jshtml}#{script}#{load}#{button}
" - -monthNames = [ - 'January' - 'February' - 'March' - 'April' - 'May' - 'June' - 'July' - 'August' - 'September' - 'October' - 'November' - 'December' -] - -formatDate = (date) -> - date.replace /^(\d\d\d\d)-(\d\d)-(\d\d)$/, (match, $1, $2, $3) -> - "#{monthNames[$2 - 1]} #{+$3}, #{$1}" - -releaseHeader = (date, version, prevVersion) -> """ -
- - #{prevVersion and "#{version}" or version} - - -""" - option '-p', '--prefix [DIR]', 'set the installation prefix for `cake install`' task 'install', 'install CoffeeScript into /usr/local (or --prefix)', (options) -> @@ -137,7 +83,7 @@ task 'build:full', 'rebuild the source twice, and run the tests', -> task 'build:parser', 'rebuild the Jison parser (run build first)', -> - helpers.extend global, require('util') + helpers.extend global, require 'util' require 'jison' parser = require('./lib/coffee-script/grammar').parser fs.writeFileSync 'lib/coffee-script/parser.js', parser.generate() @@ -182,13 +128,93 @@ task 'build:browser', 'rebuild the merged script for inclusion in the browser', task 'doc:site', 'watch and continually rebuild the documentation for the website', -> + # Helpers + codeFor = -> + counter = 0 + hljs = require 'highlight.js' + hljs.configure classPrefix: '' + (file, executable = false, showLoad = true) -> + counter++ + return unless fs.existsSync "docs/v#{majorVersion}/examples/#{file}.js" + cs = fs.readFileSync "documentation/examples/#{file}.coffee", 'utf-8' + js = fs.readFileSync "docs/v#{majorVersion}/examples/#{file}.js", 'utf-8' + js = js.replace /^\/\/ generated.*?\n/i, '' + + cshtml = "
#{hljs.highlight('coffeescript', cs).value}
" + # Temporary fix until highlight.js adds support for newer CoffeeScript keywords + # Added in https://github.com/isagalaev/highlight.js/pull/1357, awaiting release + if file in ['generator_iteration', 'generators', 'modules'] + cshtml = cshtml.replace /(yield|import|export|from|as|default) /g, '$1 ' + jshtml = "
#{hljs.highlight('javascript', js).value}
" + append = if executable is yes then '' else "alert(#{executable});" + if executable and executable isnt yes + cs.replace /(\S)\s*\Z/m, "$1\n\nalert #{executable}" + run = if executable is true then 'run' else "run: #{executable}" + name = "example#{counter}" + script = "" + load = if showLoad then "
load
" else '' + button = if executable then "
#{run}
" else '' + "
#{cshtml}#{jshtml}#{script}#{load}#{button}
" + + monthNames = [ + 'January' + 'February' + 'March' + 'April' + 'May' + 'June' + 'July' + 'August' + 'September' + 'October' + 'November' + 'December' + ] + + formatDate = (date) -> + date.replace /^(\d\d\d\d)-(\d\d)-(\d\d)$/, (match, $1, $2, $3) -> + "#{monthNames[$2 - 1]} #{+$3}, #{$1}" + + releaseHeader = (date, version, prevVersion) -> """ +
+ + #{prevVersion and "#{version}" or version} + + + """ + + testHelpers = fs.readFileSync('test/support/helpers.coffee', 'utf-8').replace /exports\./g, '@' + + testsInScriptBlocks = -> + output = '' + excludedTestFiles = ['error_messages.coffee'] + for filename in fs.readdirSync 'test' + continue if filename in excludedTestFiles + + 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 += """ + \n + """ + output + + # Task examplesSourceFolder = 'documentation/examples' examplesOutputFolder = "docs/v#{majorVersion}/examples" fs.mkdirSync examplesOutputFolder unless fs.existsSync examplesOutputFolder do renderExamples = -> execSync "bin/coffee -bc -o #{examplesOutputFolder} #{examplesSourceFolder}/*.coffee" - indexFile = 'documentation/index.html.js' + indexFile = 'documentation/index.html' do renderIndex = -> render = _.template fs.readFileSync(indexFile, 'utf-8') output = render @@ -198,10 +224,22 @@ task 'doc:site', 'watch and continually rebuild the documentation for the websit fs.writeFileSync "docs/v#{majorVersion}/index.html", output log 'compiled', green, "#{indexFile} → docs/v#{majorVersion}/index.html" + testFile = 'documentation/test.html' + do renderTest = -> + render = _.template fs.readFileSync(testFile, 'utf-8') + output = render + testHelpers: testHelpers + 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, -> renderExamples() renderIndex() fs.watch indexFile, interval: 200, renderIndex + fs.watch testFile, interval: 200, renderTest + fs.watch 'test', interval: 200, renderTest log 'watching...' , green @@ -258,23 +296,7 @@ runTests = (CoffeeScript) -> description: description if description? source: fn.toString() if fn.toString? - # See http://wiki.ecmascript.org/doku.php?id=harmony:egal - egal = (a, b) -> - if a is b - a isnt 0 or 1/a is 1/b - else - a isnt a and b isnt b - - # A recursive functional equivalence helper; uses egal for testing equivalence. - arrayEgal = (a, b) -> - if egal a, b then yes - 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 arrayEgal el, b[idx] - yes - - global.eq = (a, b, msg) -> ok egal(a, b), msg ? "Expected #{a} to equal #{b}" - global.arrayEq = (a, b, msg) -> ok arrayEgal(a,b), msg ? "Expected #{a} to deep equal #{b}" + helpers.extend global, require './test/support/helpers' # When all the tests have run, collect and print errors. # If a stacktrace is available, output the compiled function source. diff --git a/docs/current b/docs/current deleted file mode 120000 index 28c218c44b..0000000000 --- a/docs/current +++ /dev/null @@ -1 +0,0 @@ -v1 \ No newline at end of file diff --git a/documentation/index.html.js b/documentation/index.html similarity index 100% rename from documentation/index.html.js rename to documentation/index.html diff --git a/documentation/test.html b/documentation/test.html new file mode 100644 index 0000000000..96cd0a8c92 --- /dev/null +++ b/documentation/test.html @@ -0,0 +1,114 @@ + + + + + CoffeeScript Test Suite + + + + + + +

CoffeeScript Test Suite

+ +

+
+
+
+<%= tests %>
+
+
+
diff --git a/test/comments.coffee b/test/comments.coffee
index 83b41774d6..563cd47524 100644
--- a/test/comments.coffee
+++ b/test/comments.coffee
@@ -293,25 +293,25 @@ test "#3132: Format jsdoc-style block-comment nicely", ->
   input = """
   ###*
   # Multiline for jsdoc-"@doctags"
-  # 
+  #
   # @type {Function}
   ###
   fn = () -> 1
   """
 
   result = """
-  
+
   /**
    * Multiline for jsdoc-"@doctags"
-   * 
+   *
    * @type {Function}
    */
   var fn;
-  
+
   fn = function() {
     return 1;
   };
-  
+
   """
   eq CoffeeScript.compile(input, bare: on), result
 
@@ -321,25 +321,25 @@ test "#3132: Format hand-made (raw) jsdoc-style block-comment nicely", ->
   input = """
   ###*
    * Multiline for jsdoc-"@doctags"
-   * 
+   *
    * @type {Function}
   ###
   fn = () -> 1
   """
 
   result = """
-  
+
   /**
    * Multiline for jsdoc-"@doctags"
-   * 
+   *
    * @type {Function}
    */
   var fn;
-  
+
   fn = function() {
     return 1;
   };
-  
+
   """
   eq CoffeeScript.compile(input, bare: on), result
 
@@ -349,54 +349,54 @@ test "#3132: Place block-comments nicely", ->
   input = """
   ###*
   # A dummy class definition
-  # 
+  #
   # @class
   ###
   class DummyClass
-    
+
     ###*
     # @constructor
     ###
     constructor: ->
-  
+
     ###*
     # Singleton reference
-    # 
+    #
     # @type {DummyClass}
     ###
     @instance = new DummyClass()
-  
+
   """
 
   result = """
-  
+
   /**
    * A dummy class definition
-   * 
+   *
    * @class
    */
   var DummyClass;
-  
+
   DummyClass = (function() {
-  
+
     /**
      * @constructor
      */
     function DummyClass() {}
-  
-  
+
+
     /**
      * Singleton reference
-     * 
+     *
      * @type {DummyClass}
      */
-  
+
     DummyClass.instance = new DummyClass();
-  
+
     return DummyClass;
-  
+
   })();
-  
+
   """
   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
+
+test "#4375: UTF-8 characters in comments", ->
+  # 智に働けば角が立つ、情に掉させば流される。
+  ok yes
diff --git a/test/support/helpers.coffee b/test/support/helpers.coffee
new file mode 100644
index 0000000000..3fc46508af
--- /dev/null
+++ b/test/support/helpers.coffee
@@ -0,0 +1,17 @@
+# See http://wiki.ecmascript.org/doku.php?id=harmony:egal
+egal = (a, b) ->
+  if a is b
+    a isnt 0 or 1/a is 1/b
+  else
+    a isnt a and b isnt b
+
+# A recursive functional equivalence helper; uses egal for testing equivalence.
+arrayEgal = (a, b) ->
+  if egal a, b then yes
+  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 arrayEgal el, b[idx]
+    yes
+
+exports.eq      = (a, b, msg) -> ok egal(a, b), msg or "Expected #{a} to equal #{b}"
+exports.arrayEq = (a, b, msg) -> ok arrayEgal(a,b), msg or "Expected #{a} to deep equal #{b}"
diff --git a/test/test.html b/test/test.html
deleted file mode 100644
index 17b51cfa3e..0000000000
--- a/test/test.html
+++ /dev/null
@@ -1,121 +0,0 @@
-
-
-
-  
-  CoffeeScript Test Suite
-  
-  
-
-
-
-  

CoffeeScript Test Suite

-

-
-  
-
-
-