diff options
| author | 8cy <[email protected]> | 2020-04-03 02:48:28 -0700 |
|---|---|---|
| committer | 8cy <[email protected]> | 2020-04-03 02:48:28 -0700 |
| commit | f9159ea2d994e14180fb02ab562f0119513e67cf (patch) | |
| tree | 09d14cdf05456567156738b681379d4bccd64e5c /node_modules/textr/test | |
| parent | 2020/04/03, 02:42, V1.2.1 (diff) | |
| download | s5nical-f9159ea2d994e14180fb02ab562f0119513e67cf.tar.xz s5nical-f9159ea2d994e14180fb02ab562f0119513e67cf.zip | |
2020/04/03, 02:47, V1.2.2
Diffstat (limited to 'node_modules/textr/test')
| -rw-r--r-- | node_modules/textr/test/bench.js | 65 | ||||
| -rw-r--r-- | node_modules/textr/test/index.js | 130 | ||||
| -rw-r--r-- | node_modules/textr/test/support.js | 28 |
3 files changed, 0 insertions, 223 deletions
diff --git a/node_modules/textr/test/bench.js b/node_modules/textr/test/bench.js deleted file mode 100644 index 9907e14..0000000 --- a/node_modules/textr/test/bench.js +++ /dev/null @@ -1,65 +0,0 @@ -#!/usr/bin/env node - -'use strict'; - -// dependencies -var textr = require('../'); -var program = require('commander'); -var pkg = require('../package'); - -/** - * Simple benchmark which can be used as CLI in the future. - * - * @example - * - * $ echo 'hello "world"' > test - * $ cat test | bench.js -t typographic-single-spaces,typographic-quotes - * - * hello "world" - * 1654434 cycles per second% - * - * - * - */ -program - .version(pkg.version) - .option('-c, --cycles', 'create new tf on every cycle') - .option('-t, --transforms [modules]', 'add transform functions to the bench') -; - -program.parse(process.argv); - -var tfs = []; -if (program.transforms) { - tfs = program.transforms - .split(',') - .map(function(tf) { - return require(tf); - }); -} - -var buf = ''; - -process.stdin.setEncoding('utf8'); -process.stdin.on('data', function(chunk) { - buf += chunk; -}); -process.stdin.on('end', bench); - - -function bench() { - var res; - var startedAt = +new Date(); - var endedAt = startedAt + 1000; - var i = 0; - var tf; - if (!program.cycles) { tf = textr().use.apply(null, tfs); } - do { - if (program.cycles) { tf = textr().use.apply(null, tfs); } - res = tf(buf); - i++; - } while (+new Date() < endedAt); - process.stdout.write(res); - process.stdout.write('\r\n'); - process.stdout.write(i + ' cycles per second'); -} diff --git a/node_modules/textr/test/index.js b/node_modules/textr/test/index.js deleted file mode 100644 index c9a308e..0000000 --- a/node_modules/textr/test/index.js +++ /dev/null @@ -1,130 +0,0 @@ -/* global describe, it, before, navigator */ - -'use strict'; - -var textr = require('..'); -var should = require('should'); -var noop = require('./support').noop; -var capitalize = require('./support').capitalize; -var headline = require('./support').headline; - -describe('textr', function() { - - describe('api', function() { - - it('should register transformers', function() { - var tf = textr(); - tf.should.have.property('use'); - tf.use.should.be.a.Function; - }); - - it('should process text', function() { - var tf = textr(); - tf.should.be.a.Function; - tf.should.have.property('exec'); - tf.exec.should.be.a.Function; - tf('hello').should.be.equal('hello'); - }); - - }); - - describe('use', function() { - - it('should return transformer', function() { - var tf = textr().use(noop); - tf.should.be.a.Function; - tf.use.should.be.a.Function; - }); - - it('should use plugins', function() { - textr() - .use(noop, noop) - .use(noop) - .mws.should.has.length(3) - ; - }); - - it('should use itself as transform', function() { - var one = textr() - .use(capitalize) - ; - var two = textr() - .use(headline(1)) - ; - var tf = textr() - .use(one, two) - .exec('hello world') - .should.be.equal('<h1>Hello World</h1>') - ; - }); - - it('should support string.prototype methods', function() { - var tf = textr() - .use(String.prototype.trim) - ; - tf('text\t\n').should.be.equal('text'); - }); - - }); - - describe('exec', function() { - - it('should apply transformers to given text', function() { - textr() - .use(capitalize) - .exec('hello world') - .should.be.equal('Hello World') - ; - }); - - it('should apply transformers with order of registration', function() { - textr() - .use(capitalize) - .use(headline(1)) - .exec('hello world') - .should.be.equal('<h1>Hello World</h1>') - ; - }); - - it('should not miss text if on of the middlewares return falsy', function() { - textr() - .use(function (text, ctx) { - // define mw that not transforming text; - if ('undefined' === typeof navigator) { return; } - ctx.locale = navigator.locale; - }) - .exec('some text') - .should.be.equal('some text') - ; - }); - - it('should support options to correct recursive usage', function() { - var pluginWithDefaultOptions = textr({ locale: 'ru', ownprop: true }) - .use(function(text, options) { - options.locale.should.be.equal('en-us'); - options.direction.should.be.equal('ltr'); - options.ownprop.should.be.equal(true); - options.other.should.be.equal('redefine'); - }) - ; - var tf = textr({ locale: 'en-us', direction: 'ltr', other: 'param' }) - .use(pluginWithDefaultOptions) - .exec('text', { other: 'redefine' }) - ; - }); - }); - - describe('options', function() { - it('should pass options through each middleware', function() { - textr({ locale: 'ru' }) - .use(function(text, opts) { - return text + opts.locale; - }) - .exec('locale: ') - .should.be.equal('locale: ru') - ; - }); - }); - - -}); diff --git a/node_modules/textr/test/support.js b/node_modules/textr/test/support.js deleted file mode 100644 index a530253..0000000 --- a/node_modules/textr/test/support.js +++ /dev/null @@ -1,28 +0,0 @@ -'use strict'; - -/** - * Convert text to capitalized string - * @param {String} text - * @return {String} - */ -exports.capitalize = function(text) { - return text.replace(/\b(.{1})/g, function (l) { - return l.toUpperCase(); - }); -}; - -/** - * Wrap text by html headline with given level - * @param {Number} level - * @return {Function} - */ -exports.headline = function(level) { - return function(text) { - return '<h' + level + '>' + text + '</h' + level + '>'; - }; -}; - -/** - * noop function - */ -exports.noop = function() {}; |