Skip to content

Commit

Permalink
Improve code formatting based on suggestions
Browse files Browse the repository at this point in the history
Co-authored-by: David Chambers <[email protected]>
  • Loading branch information
Avaq and davidchambers committed Jun 13, 2020
1 parent 3bae914 commit e0df4bd
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
18 changes: 9 additions & 9 deletions lib/doctest.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ function iifeWrap(s) {
}

// toModule :: (String, String?, Array String) -> String
function toModule(source, moduleType, logFunctions) {
function toModule(source, moduleType, logFunctionNames) {
switch (moduleType) {
case 'amd':
return common.unlines ([
Expand All @@ -160,10 +160,10 @@ function toModule(source, moduleType, logFunctions) {
' enqueue: function(io) { this.queue.push(io); },',
' logMediator: {emit: function() {}}',
'};',
logFunctions.map (function(logFunction) {
logFunctionNames.map (function(logFunctionName) {
return '\n' + common.unlines ([
'var ' + logFunction + ' = function(value) {',
' __doctest.logMediator.emit ("' + logFunction + '", value);',
'var ' + logFunctionName + ' = function(value) {',
' __doctest.logMediator.emit ("' + logFunctionName + '", value);',
'};'
]);
}).join (''),
Expand Down Expand Up @@ -577,27 +577,27 @@ function rewrite$coffee(options, input) {
);
}

function functionEval(options, source, logFunctions) {
function functionEval(options, source, logFunctionNames) {
// Functions created via the Function function are always run in the
// global context, which ensures that doctests can't access variables
// in _this_ context.
//
// The `evaluate` function takes as arguments all the logger functions and
// the doctest runtime broker as `__doctest`.
var argNames = logFunctions.concat (['__doctest', source]);
var argNames = logFunctionNames.concat (['__doctest', source]);
var evaluate = Function.apply (null, argNames);

var queue = [];
var logMediator = {emit: function() {}};
var runtimeBroker = {enqueue: function(io) { queue.push (io); }};

var loggers = logFunctions.map (function(logFunction) {
var logFunctions = logFunctionNames.map (function(logFunctionName) {
return function log(value) {
logMediator.emit (logFunction, value);
logMediator.emit (logFunctionName, value);
};
});

evaluate.apply (null, loggers.concat ([runtimeBroker]));
evaluate.apply (null, logFunctions.concat ([runtimeBroker]));

return run (options, queue, logMediator);
}
Expand Down
8 changes: 4 additions & 4 deletions lib/doctest.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,17 @@ export default async function(path, options) {
}
}

function wrap(source, logFunctions) {
function wrap(source, logFunctionNames) {
return common.unlines ([
'export const __doctest = {',
' queue: [],',
' enqueue: function(io) { this.queue.push(io); },',
' logMediator: {emit: function() {}}',
'};',
logFunctions.map (function(logFunction) {
logFunctionNames.map (function(logFunctionName) {
return '\n' + common.unlines ([
'const ' + logFunction + ' = value => {',
' __doctest.logMediator.emit ("' + logFunction + '", value);',
'const ' + logFunctionName + ' = value => {',
' __doctest.logMediator.emit ("' + logFunctionName + '", value);',
'};'
]);
}).join (''),
Expand Down
10 changes: 5 additions & 5 deletions lib/program.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ var program = require ('commander');
var pkg = require ('../package.json');


function collect(value, previous) {
return previous.concat ([value]);
function append(x, xs) {
return xs.concat ([x]);
}

program
Expand All @@ -23,9 +23,9 @@ program
.option (' --closing-delimiter <delimiter>',
'specify line following doctest block (e.g. "```")')
.option (' --log-function <name>',
'inject a log function of the given name into your doctests' +
', can be supplied multiple times',
collect,
'expose a log function with the given name to your doctests' +
' (can be specified multiple times)',
append,
[])
.option (' --log-timeout <milliseconds>',
'specify an alternative log timeout time (defaults to 100)',
Expand Down

0 comments on commit e0df4bd

Please sign in to comment.