chore: add test for repeat helper

Several test cleanups and minor test fixes
This commit is contained in:
Estevao Soares dos Santos 2022-03-10 12:56:34 +00:00
parent 5f5304ccaa
commit df76f984a3
10 changed files with 37 additions and 24 deletions

View File

@ -144,7 +144,6 @@ module.exports = function (grunt) {
}
},
single: {
src: 'test/node/**/*.js',
options: {
globals: ['should'],
timeout: 3000,
@ -153,7 +152,7 @@ module.exports = function (grunt) {
}
},
cli: {
src: 'test/node/testsuite.cli.js',
src: 'test/unit/cli.js',
options: {
globals: ['should'],
timeout: 3000,
@ -208,14 +207,12 @@ module.exports = function (grunt) {
/**
* Run a single test
*/
grunt.registerTask('single-test', function (grep) {
grunt.registerTask('single-test', function (file) {
'use strict';
grunt.config.merge({
simplemocha: {
single: {
options: {
grep: grep
}
src: file
}
}
});
@ -230,6 +227,7 @@ module.exports = function (grunt) {
grunt.registerTask('test-functional', ['concat:test', 'simplemocha:functional', 'clean']);
grunt.registerTask('test-unit', ['concat:test', 'simplemocha:unit', 'clean']);
grunt.registerTask('test-cli', ['clean', 'lint', 'concat:test', 'simplemocha:cli', 'clean']);
grunt.registerTask('performance', ['concat:test', 'performancejs', 'clean']);
grunt.registerTask('build', ['test', 'concat:dist', 'concat:cli', 'uglify:dist', 'uglify:cli', 'endline']);
grunt.registerTask('build-without-test', ['concat:dist', 'uglify', 'endline']);

BIN
dist/showdown.js vendored

Binary file not shown.

BIN
dist/showdown.js.map vendored

Binary file not shown.

BIN
dist/showdown.min.js vendored

Binary file not shown.

Binary file not shown.

View File

@ -363,12 +363,16 @@ showdown.helper.encodeEmailAddress = function (mail) {
/**
* String.prototype.repeat polyfill
*
* @param str
* @param count
* @param {string} str
* @param {int} count
* @returns {string}
*/
function repeat (str, count) {
showdown.helper.repeat = function (str, count) {
'use strict';
// use built-in method if it's available
if (!showdown.helper.isUndefined(String.prototype.repeat)) {
return str.repeat(count);
}
str = '' + str;
if (count < 0) {
throw new RangeError('repeat count must be non-negative');
@ -396,7 +400,7 @@ function repeat (str, count) {
}
str += str.substring(0, maxCount - str.length);
return str;
}
};
/**
* String.prototype.padEnd polyfill
@ -418,7 +422,7 @@ showdown.helper.padEnd = function padEnd (str, targetLength, padString) {
} else {
targetLength = targetLength - str.length;
if (targetLength > padString.length) {
padString += repeat(padString, targetLength / padString.length); //append to original to ensure we are longer than needed
padString += showdown.helper.repeat(padString, targetLength / padString.length); //append to original to ensure we are longer than needed
}
return String(str) + padString.slice(0,targetLength);
}

View File

@ -1,15 +1,14 @@
/**
* Created by Estevao on 15-01-2015.
*/
require('source-map-support').install();
require('chai').should();
require('sinon');
var showdown = require('../../.build/showdown.js');
describe('showdown.Converter', function () {
'use strict';
require('source-map-support').install();
require('chai').should();
var showdown = require('../../.build/showdown.js');
describe('Converter.options extensions', function () {
var runCount;
showdown.extension('testext', function () {

View File

@ -1,15 +1,14 @@
/**
* Created by Estevao on 15-01-2015.
*/
require('source-map-support').install();
require('chai').should();
require('sinon');
var showdown = require('../../.build/showdown.js');
describe('showdown.Converter', function () {
'use strict';
require('source-map-support').install();
require('chai').should();
var jsdom = require('jsdom'),
document = new jsdom.JSDOM('', {}).window.document, // jshint ignore:line
showdown = require('../../.build/showdown.js');
describe('makeMarkdown()', function () {
var converter = new showdown.Converter();
@ -18,7 +17,7 @@ describe('showdown.Converter', function () {
var html = '<a href="/somefoo.html">a link</a>\n';
var md = '[a link](</somefoo.html>)';
converter.makeMarkdown(html, document).should.equal(md);
converter.makeMarkdown(html).should.equal(md);
});
});

View File

@ -1,11 +1,14 @@
/**
* Created by Estevao on 27/01/2017.
* Created by Tivie on 27/01/2017.
*/
require('source-map-support').install();
require('chai').should();
require('sinon');
var showdown = require('../../.build/showdown.js');
/*jshint expr: true*/
/*jshint -W053 */
/*jshint -W010 */
/*jshint -W009 */
var showdown = require('../../.build/showdown.js');
describe('encodeEmailAddress()', function () {
'use strict';
@ -245,3 +248,12 @@ describe('matchRecursiveRegExp()', function () {
});
describe('repeat()', function () {
'use strict';
it('work produce the same output as String.prototype.repeat()', function () {
var str = 'foo',
expected = str.repeat(100),
actual = showdown.helper.repeat(str, 100);
expected.should.equal(actual);
});
});

View File

@ -1,5 +1,6 @@
require('source-map-support').install();
require('chai').should();
require('sinon');
var expect = require('chai').expect,
showdown = require('../../.build/showdown.js');