Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

finish mocha test #68

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/meta.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module.exports = function (str) {
module.exports = function(str) {
// TODO
}
// return /\.$/.test(str);
return /[.]$/.test(str);
};
5 changes: 3 additions & 2 deletions lib/quantifier.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
module.exports = function (str) {
module.exports = function(str) {
// TODO
}
return /^\d+\.jpe?g$/.test(str);
};
5 changes: 3 additions & 2 deletions lib/split.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
module.exports = function (str) {
module.exports = function(str) {
// TODO
}
return str.split(/\s*,\s*/);
};
119 changes: 31 additions & 88 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -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']
)
})
})
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']);
});
});
134 changes: 134 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
@@ -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"

[email protected]:
version "1.3.1"
resolved "https://registry.yarnpkg.com/browser-stdout/-/browser-stdout-1.3.1.tgz#baa559ee14ced73452229bad7326467c61fabd60"

[email protected]:
version "2.15.1"
resolved "http://registry.npmjs.org/commander/-/commander-2.15.1.tgz#df46e867d0fc2aec66a34662b406a9ccafff5b0f"

[email protected]:
version "0.0.1"
resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b"

[email protected]:
version "3.1.0"
resolved "https://registry.yarnpkg.com/debug/-/debug-3.1.0.tgz#5bb5a0672628b64149566ba16819e61518c67261"
dependencies:
ms "2.0.0"

[email protected]:
version "3.5.0"
resolved "https://registry.yarnpkg.com/diff/-/diff-3.5.0.tgz#800c0dd1e0a8bfbc95835c202ad220fe317e5a12"

[email protected]:
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"

[email protected]:
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"

[email protected]:
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"

[email protected]:
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"

[email protected], 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"

[email protected]:
version "0.0.8"
resolved "http://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz#857fcabfc3397d2625b8228262e86aa7a011b05d"

[email protected]:
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"

[email protected]:
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"

[email protected]:
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"