@@ -13,6 +13,7 @@ var debug = require('debug')('mocha:watch');
1313var fs = require ( 'fs' ) ;
1414var glob = require ( 'glob' ) ;
1515var path = require ( 'path' ) ;
16+ var util = require ( 'util' ) ;
1617var join = path . join ;
1718var he = require ( 'he' ) ;
1819var errors = require ( './errors' ) ;
@@ -530,7 +531,7 @@ exports.lookupFiles = function lookupFiles(filepath, extensions, recursive) {
530531 files = glob . sync ( filepath ) ;
531532 if ( ! files . length ) {
532533 throw createNoFilesMatchPatternError (
533- 'Cannot find any files matching pattern " ' + filepath + '"' ,
534+ 'Cannot find any files matching pattern ' + exports . dQuote ( filepath ) ,
534535 filepath
535536 ) ;
536537 }
@@ -564,7 +565,11 @@ exports.lookupFiles = function lookupFiles(filepath, extensions, recursive) {
564565 }
565566 if ( ! extensions ) {
566567 throw createMissingArgumentError (
567- 'Argument "extensions" required when argument "filepath" is a directory' ,
568+ util . format (
569+ 'Argument %s required when argument %s is a directory' ,
570+ exports . sQuote ( 'extensions' ) ,
571+ exports . sQuote ( 'filepath' )
572+ ) ,
568573 'extensions' ,
569574 'array'
570575 ) ;
@@ -715,6 +720,76 @@ exports.clamp = function clamp(value, range) {
715720 return Math . min ( Math . max ( value , range [ 0 ] ) , range [ 1 ] ) ;
716721} ;
717722
723+ /**
724+ * Single quote text by combining with undirectional ASCII quotation marks.
725+ *
726+ * @description
727+ * Provides a simple means of markup for quoting text to be used in output.
728+ * Use this to quote names of variables, methods, and packages.
729+ *
730+ * <samp>package 'foo' cannot be found</samp>
731+ *
732+ * @private
733+ * @param {string } str - Value to be quoted.
734+ * @returns {string } quoted value
735+ * @example
736+ * sQuote('n') // => 'n'
737+ */
738+ exports . sQuote = function ( str ) {
739+ return "'" + str + "'" ;
740+ } ;
741+
742+ /**
743+ * Double quote text by combining with undirectional ASCII quotation marks.
744+ *
745+ * @description
746+ * Provides a simple means of markup for quoting text to be used in output.
747+ * Use this to quote names of datatypes, classes, pathnames, and strings.
748+ *
749+ * <samp>argument 'value' must be "string" or "number"</samp>
750+ *
751+ * @private
752+ * @param {string } str - Value to be quoted.
753+ * @returns {string } quoted value
754+ * @example
755+ * dQuote('number') // => "number"
756+ */
757+ exports . dQuote = function ( str ) {
758+ return '"' + str + '"' ;
759+ } ;
760+
761+ /**
762+ * Provides simplistic message translation for dealing with plurality.
763+ *
764+ * @description
765+ * Use this to create messages which need to be singular or plural.
766+ * Some languages have several plural forms, so _complete_ message clauses
767+ * are preferable to generating the message on the fly.
768+ *
769+ * @private
770+ * @param {number } n - Non-negative integer
771+ * @param {string } msg1 - Message to be used in English for `n = 1`
772+ * @param {string } msg2 - Message to be used in English for `n = 0, 2, 3, ...`
773+ * @returns {string } message corresponding to value of `n`
774+ * @example
775+ * var sprintf = require('util').format;
776+ * var pkgs = ['one', 'two'];
777+ * var msg = sprintf(
778+ * ngettext(
779+ * pkgs.length,
780+ * 'cannot load package: %s',
781+ * 'cannot load packages: %s'
782+ * ),
783+ * pkgs.map(sQuote).join(', ')
784+ * );
785+ * console.log(msg); // => cannot load packages: 'one', 'two'
786+ */
787+ exports . ngettext = function ( n , msg1 , msg2 ) {
788+ if ( typeof n === 'number' && n >= 0 ) {
789+ return n === 1 ? msg1 : msg2 ;
790+ }
791+ } ;
792+
718793/**
719794 * It's a noop.
720795 * @public
0 commit comments