From 7202510824a86aea05e7290a0e9c3bb89839b9f9 Mon Sep 17 00:00:00 2001 From: Ivylin Date: Fri, 23 Nov 2018 14:54:40 +0800 Subject: [PATCH] finish mocha test --- lib/meta.js | 6 ++- lib/quantifier.js | 5 +- lib/split.js | 5 +- test/test.js | 119 +++++++++++----------------------------- yarn.lock | 134 ++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 175 insertions(+), 94 deletions(-) create mode 100644 yarn.lock diff --git a/lib/meta.js b/lib/meta.js index a08ee57..99c951b 100644 --- a/lib/meta.js +++ b/lib/meta.js @@ -1,3 +1,5 @@ -module.exports = function (str) { +module.exports = function(str) { // TODO -} \ No newline at end of file + // return /\.$/.test(str); + return /[.]$/.test(str); +}; diff --git a/lib/quantifier.js b/lib/quantifier.js index a08ee57..e0292ed 100644 --- a/lib/quantifier.js +++ b/lib/quantifier.js @@ -1,3 +1,4 @@ -module.exports = function (str) { +module.exports = function(str) { // TODO -} \ No newline at end of file + return /^\d+\.jpe?g$/.test(str); +}; diff --git a/lib/split.js b/lib/split.js index a08ee57..09895c7 100644 --- a/lib/split.js +++ b/lib/split.js @@ -1,3 +1,4 @@ -module.exports = function (str) { +module.exports = function(str) { // TODO -} \ No newline at end of file + return str.split(/\s*,\s*/); +}; diff --git a/test/test.js b/test/test.js index 8385526..c3ab4df 100644 --- a/test/test.js +++ b/test/test.js @@ -1,94 +1,37 @@ -const assert = require('assert') +const assert = require('assert'); -describe('regex', function () { - it('匹配末尾是.', function () { - const meta = require('../lib/meta') +describe('regex', function() { + it('匹配末尾是.', function() { + const meta = require('../lib/meta'); - assert.ok( - meta(`abc.`), - `abc.` - ) - assert.ok( - !meta(`abc`), - `abc` - ) - assert.ok( - meta(`...`), - `...` - ) - assert.ok( - !meta(`...x`), - `...x` - ) - assert.ok( - !meta(`...\n`), - `...\\n` - ) - }) + assert.ok(meta(`abc.`), `abc.`); + assert.ok(!meta(`abc`), `abc`); + assert.ok(meta(`...`), `...`); + assert.ok(!meta(`...x`), `...x`); + assert.ok(!meta(`...\n`), `...\\n`); + }); - it('匹配一张名字为数字的 jpg 图片', function () { - const quantifier = require('../lib/quantifier') + it('匹配一张名字为数字的 jpg 图片', function() { + const quantifier = require('../lib/quantifier'); - assert.ok( - quantifier(`123.jpg`), - `123.jpg` - ) - assert.ok( - quantifier(`123.jpeg`), - `123.jpeg` - ) - assert.ok( - !quantifier(`abc.jpeg`), - `abc.jpeg` - ) - assert.ok( - !quantifier(`123abc.jpeg`), - `123abc.jpeg` - ) - assert.ok( - !quantifier(`123`), - `123` - ) - assert.ok( - !quantifier(`123.jpg2000`), - `123.jpg2000` - ) - assert.ok( - !quantifier(`123.png`), - `123.png` - ) - assert.ok( - !quantifier(`.jpeg`), - `.jpeg` - ) - assert.ok( - !quantifier(`111.jpeeg`), - `111.jpeeg` - ) - }) + assert.ok(quantifier(`123.jpg`), `123.jpg`); + assert.ok(quantifier(`123.jpeg`), `123.jpeg`); + assert.ok(!quantifier(`abc.jpeg`), `abc.jpeg`); + assert.ok(!quantifier(`123abc.jpeg`), `123abc.jpeg`); + assert.ok(!quantifier(`123`), `123`); + assert.ok(!quantifier(`123.jpg2000`), `123.jpg2000`); + assert.ok(!quantifier(`123.png`), `123.png`); + assert.ok(!quantifier(`.jpeg`), `.jpeg`); + assert.ok(!quantifier(`111.jpeeg`), `111.jpeeg`); + }); - it('正确的 split 字符串', function () { - const split = require('../lib/split') + it('正确的 split 字符串', function() { + const split = require('../lib/split'); - assert.deepEqual( - split(`1,2,3`), - ['1', '2', '3'] - ) - assert.deepEqual( - split(`4, 5, 6, 7`), - ['4', '5', '6', '7'] - ) - assert.deepEqual( - split(`1337`), - ['1337'] - ) - assert.deepEqual( - split(`a,\nb,\nc,\nd`), - ['a', 'b', 'c', 'd'] - ) - assert.deepEqual( - split(`q\r\n ,\r\n r\r\n ,\r\n s`), - ['q', 'r', 's'] - ) - }) -}) \ No newline at end of file + assert.deepEqual(split(`1,2,3`), ['1', '2', '3']); + assert.deepEqual(split(`4, 5, 6, 7`), ['4', '5', '6', '7']); + assert.deepEqual(split(`1337`), ['1337']); + assert.deepEqual(split(`a,\nb,\nc,\nd`), ['a', 'b', 'c', 'd']); + assert.deepEqual(split(`q\r\n ,\r\n r\r\n ,\r\n s`), ['q', 'r', 's']); + }); +}); diff --git a/yarn.lock b/yarn.lock new file mode 100644 index 0000000..0fed86f --- /dev/null +++ b/yarn.lock @@ -0,0 +1,134 @@ +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. +# yarn lockfile v1 + + +balanced-match@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.0.tgz#89b4d199ab2bee49de164ea02b89ce462d71b767" + +brace-expansion@^1.1.7: + version "1.1.11" + resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-1.1.11.tgz#3c7fcbf529d87226f3d2f52b966ff5271eb441dd" + dependencies: + balanced-match "^1.0.0" + concat-map "0.0.1" + +browser-stdout@1.3.1: + version "1.3.1" + resolved "https://registry.yarnpkg.com/browser-stdout/-/browser-stdout-1.3.1.tgz#baa559ee14ced73452229bad7326467c61fabd60" + +commander@2.15.1: + version "2.15.1" + resolved "http://registry.npmjs.org/commander/-/commander-2.15.1.tgz#df46e867d0fc2aec66a34662b406a9ccafff5b0f" + +concat-map@0.0.1: + version "0.0.1" + resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b" + +debug@3.1.0: + version "3.1.0" + resolved "https://registry.yarnpkg.com/debug/-/debug-3.1.0.tgz#5bb5a0672628b64149566ba16819e61518c67261" + dependencies: + ms "2.0.0" + +diff@3.5.0: + version "3.5.0" + resolved "https://registry.yarnpkg.com/diff/-/diff-3.5.0.tgz#800c0dd1e0a8bfbc95835c202ad220fe317e5a12" + +escape-string-regexp@1.0.5: + version "1.0.5" + resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4" + +fs.realpath@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f" + +glob@7.1.2: + version "7.1.2" + resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.2.tgz#c19c9df9a028702d678612384a6552404c636d15" + dependencies: + fs.realpath "^1.0.0" + inflight "^1.0.4" + inherits "2" + minimatch "^3.0.4" + once "^1.3.0" + path-is-absolute "^1.0.0" + +growl@1.10.5: + version "1.10.5" + resolved "https://registry.yarnpkg.com/growl/-/growl-1.10.5.tgz#f2735dc2283674fa67478b10181059355c369e5e" + +has-flag@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/has-flag/-/has-flag-3.0.0.tgz#b5d454dc2199ae225699f3467e5a07f3b955bafd" + +he@1.1.1: + version "1.1.1" + resolved "https://registry.yarnpkg.com/he/-/he-1.1.1.tgz#93410fd21b009735151f8868c2f271f3427e23fd" + +inflight@^1.0.4: + version "1.0.6" + resolved "https://registry.yarnpkg.com/inflight/-/inflight-1.0.6.tgz#49bd6331d7d02d0c09bc910a1075ba8165b56df9" + dependencies: + once "^1.3.0" + wrappy "1" + +inherits@2: + version "2.0.3" + resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.3.tgz#633c2c83e3da42a502f52466022480f4208261de" + +minimatch@3.0.4, minimatch@^3.0.4: + version "3.0.4" + resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.0.4.tgz#5166e286457f03306064be5497e8dbb0c3d32083" + dependencies: + brace-expansion "^1.1.7" + +minimist@0.0.8: + version "0.0.8" + resolved "http://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz#857fcabfc3397d2625b8228262e86aa7a011b05d" + +mkdirp@0.5.1: + version "0.5.1" + resolved "http://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz#30057438eac6cf7f8c4767f38648d6697d75c903" + dependencies: + minimist "0.0.8" + +mocha@^5.2.0: + version "5.2.0" + resolved "https://registry.yarnpkg.com/mocha/-/mocha-5.2.0.tgz#6d8ae508f59167f940f2b5b3c4a612ae50c90ae6" + dependencies: + browser-stdout "1.3.1" + commander "2.15.1" + debug "3.1.0" + diff "3.5.0" + escape-string-regexp "1.0.5" + glob "7.1.2" + growl "1.10.5" + he "1.1.1" + minimatch "3.0.4" + mkdirp "0.5.1" + supports-color "5.4.0" + +ms@2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8" + +once@^1.3.0: + version "1.4.0" + resolved "https://registry.yarnpkg.com/once/-/once-1.4.0.tgz#583b1aa775961d4b113ac17d9c50baef9dd76bd1" + dependencies: + wrappy "1" + +path-is-absolute@^1.0.0: + version "1.0.1" + resolved "http://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz#174b9268735534ffbc7ace6bf53a5a9e1b5c5f5f" + +supports-color@5.4.0: + version "5.4.0" + resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-5.4.0.tgz#1c6b337402c2137605efe19f10fec390f6faab54" + dependencies: + has-flag "^3.0.0" + +wrappy@1: + version "1.0.2" + resolved "https://registry.yarnpkg.com/wrappy/-/wrappy-1.0.2.tgz#b5243d8f3ec1aa35f1364605bc0d1036e30ab69f"