mirror of https://github.com/showdownjs/showdown
chore: add test for repeat helper
Several test cleanups and minor test fixespull/896/head
parent
5f5304ccaa
commit
df76f984a3
10
Gruntfile.js
10
Gruntfile.js
|
@ -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']);
|
||||
|
|
|
@ -946,6 +946,49 @@ showdown.helper.encodeEmailAddress = function (mail) {
|
|||
};
|
||||
|
||||
/**
|
||||
* String.prototype.repeat polyfill
|
||||
*
|
||||
* @param {string} str
|
||||
* @param {int} count
|
||||
* @returns {string}
|
||||
*/
|
||||
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');
|
||||
}
|
||||
if (count === Infinity) {
|
||||
throw new RangeError('repeat count must be less than infinity');
|
||||
}
|
||||
count = Math.floor(count);
|
||||
if (str.length === 0 || count === 0) {
|
||||
return '';
|
||||
}
|
||||
// Ensuring count is a 31-bit integer allows us to heavily optimize the
|
||||
// main part. But anyway, most current (August 2014) browsers can't handle
|
||||
// strings 1 << 28 chars or longer, so:
|
||||
/*jshint bitwise: false*/
|
||||
if (str.length * count >= 1 << 28) {
|
||||
throw new RangeError('repeat count must not overflow maximum string size');
|
||||
}
|
||||
/*jshint bitwise: true*/
|
||||
var maxCount = str.length * count;
|
||||
count = Math.floor(Math.log(count) / Math.log(2));
|
||||
while (count) {
|
||||
str += str;
|
||||
count--;
|
||||
}
|
||||
str += str.substring(0, maxCount - str.length);
|
||||
return str;
|
||||
};
|
||||
|
||||
/**
|
||||
* String.prototype.padEnd polyfill
|
||||
*
|
||||
* @param str
|
||||
* @param targetLength
|
||||
|
@ -964,7 +1007,7 @@ showdown.helper.padEnd = function padEnd (str, targetLength, padString) {
|
|||
} else {
|
||||
targetLength = targetLength - str.length;
|
||||
if (targetLength > padString.length) {
|
||||
padString += padString.repeat(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);
|
||||
}
|
||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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 () {
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
|
||||
});
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
require('source-map-support').install();
|
||||
require('chai').should();
|
||||
require('sinon');
|
||||
var expect = require('chai').expect,
|
||||
showdown = require('../../.build/showdown.js');
|
||||
|
||||
|
|
Loading…
Reference in New Issue