From 7cce83c928f0aedb365921f376b6b6ca2ed95328 Mon Sep 17 00:00:00 2001 From: Michael Mathews Date: Thu, 12 May 2011 07:22:00 +0100 Subject: [PATCH] Added test case for multiple parses to check that parser state is reset each time. Fixed issue with nodeunit and settimeout that caused tests to run in random order, sometimes before the last test completed! --- lib/nodeunit.js | 7 ++++--- node_modules/jsdoc/parser.js | 6 +++--- test/jsdoc_parser_comments.js | 11 +++++++++++ 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/lib/nodeunit.js b/lib/nodeunit.js index df267910..47ffd823 100644 --- a/lib/nodeunit.js +++ b/lib/nodeunit.js @@ -559,10 +559,11 @@ var reporter = {}; //// exported async module functions //// - //// nextTick implementation with browser-compatible fallback //// + //// nextTick implementation with browser and rhino-compatible fallbacks //// async.nextTick = function(fn){ if(typeof process == 'undefined' || !(process.nextTick)){ - setTimeout(fn, 0); + if (typeof window !== 'undefined' && window.setTimeout) setTimeout(fn, 0); + else fn(); } else process.nextTick(fn); }; @@ -1747,7 +1748,7 @@ exports.run = function (modules, options) { ' assertions (' + assertions.duration + 'ms)'; } if (typeof document === 'undefined' && typeof print !== 'undefined') { - return print( html.replace(/
  • /g, '\033[1;032m√ \033[0m').replace(/
  • /g, '\033[1;031mX \033[0m').replace(//g, "\n").replace(/<\/h\d>/g, "\n").replace(/
    /g, "\n ").replace(/<\/(li|div)>/g, "\n").replace(/<[^>]+?>/g, '') ); + return print( html.replace(/
  • /g, '(/) ').replace(/
  • /g, '(X) ').replace(//g, "\n").replace(/<\/h\d>/g, "\n").replace(/
    /g, "\n ").replace(/<\/(li|div)>/g, "\n").replace(/<[^>]+?>/g, '') ); } document.body.innerHTML += html; } diff --git a/node_modules/jsdoc/parser.js b/node_modules/jsdoc/parser.js index 9fd6c2ca..db25e28c 100644 --- a/node_modules/jsdoc/parser.js +++ b/node_modules/jsdoc/parser.js @@ -10,7 +10,7 @@ } var path, - symbols = 'wtf'; + symbols = null; exports.parse = function(src) { symbols = []; @@ -40,8 +40,8 @@ var handle = { JSDOC: function(jsdoc) { - //console.log( '>>> jsdoc "'+jsdoc+'"' ); - symbols.push( new Doclet(jsdoc, {longname: ''}) ); + //print( '>>> jsdoc "'+jsdoc+'"' ); + symbols.push( new Doclet(jsdoc, {longname: ''}) ); }, VAR: function(node) { var child = null, diff --git a/test/jsdoc_parser_comments.js b/test/jsdoc_parser_comments.js index 7cd7f908..8f64fa2c 100644 --- a/test/jsdoc_parser_comments.js +++ b/test/jsdoc_parser_comments.js @@ -36,3 +36,14 @@ exports['Parse a source with only single non-jsdoc multi-line comments.'] = func t.equal( docs.length, 0, 'should result in docs that are empty' ); t.done(); }; + +exports['Parse second source, should be unaffected by the first pasre.'] = function(t) { + t.expect(2); + var docs = parser.parse('/**@doc1*/ /**@doc2*/ var x;'); + t.equal( docs.length, 2 ); + + docs = parser.parse('function y(){}'); + t.equal( docs.length, 1 ); + + t.done(); +};