Skip to content

Commit c39efe7

Browse files
committed
test: add ok/failed
1 parent 18d4d18 commit c39efe7

File tree

2 files changed

+94
-16
lines changed

2 files changed

+94
-16
lines changed

index.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
'use strict';
22
/**
33
* Welcome to the vimeo-regex!
4+
*
5+
* Vimeo videos can use one of three URL schemes:
6+
* https://vimeo.com/*
7+
* https://vimeo.com/channels/{any}/*
8+
* https://vimeo.com/groups/{any}/videos/*
49
*/
510

611
module.exports = function vimeoRegex () {
7-
var regex = /^(http|https)?:\/\/(www\.)?vimeo\.com\/(clip\:)?(\d+).*$/;
8-
var regex2 = /https?:\/\/(?:www\.)?vimeo.com\/(?:channels\/(?:\w+\/)?|groups\/([^\/]*)\/videos\/|album\/(\d+)\/video\/|)(\d+)(?:$|\/|\?)/;
12+
var regex = /^(http|https)?:\/\/(www\.)?vimeo.com\/(?:channels\/(?:\w+\/)?|groups\/([^\/]*)\/videos\/|)(\d+)(?:$|\/|\?)/;
913

1014
return regex;
1115
};

test.js

Lines changed: 88 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,96 @@ function test(str) {
88
}
99

1010
var fixtures = {
11-
invalid: [
12-
'NoNoNo'
13-
],
14-
shortlinks: [
15-
],
16-
mixed: [
17-
],
18-
attrlink: [
19-
]
11+
plain: {
12+
ok: [
13+
'https://vimeo.com/62092214',
14+
'http://vimeo.com/62092214',
15+
'https://www.vimeo.com/62092214'
16+
],
17+
not_ok: [
18+
'NONONO',
19+
'http://vimeo/62092214',
20+
'http://vimeo.com/foo',
21+
]
22+
},
23+
channels: {
24+
ok: [
25+
'https://vimeo.com/channels/documentaryfilm/128373915',
26+
'http://vimeo.com/channels/documentaryfilm/128373915'
27+
],
28+
not_ok: [
29+
'https://vimeo.com/channels/foo-barr/documentaryfilm/128373915',
30+
]
31+
},
32+
groups: {
33+
ok: [
34+
'https://vimeo.com/groups/musicvideo/videos/126199390',
35+
'http://vimeo.com/groups/musicvideo/videos/126199390'
36+
],
37+
not_ok: [
38+
'http://vimeo.com/groups/musicvideo/vid/126199390'
39+
]
40+
},
41+
attrlink: {
42+
ok: [
43+
'https://vimeo.com/62092214?query=foo'
44+
],
45+
not_ok: [
46+
'https://vimeo.com.omomom/62092214?query=foo'
47+
]
48+
}
2049
};
2150

22-
describe('vimeo-regex', function() {
23-
describe('should match id from', function() {
24-
it('shortlinks', function(done) {
25-
fixtures.shortlinks.forEach(function each(link) {
26-
assert.ok(test(link));
51+
52+
describe('vimeo-regex ->', function() {
53+
describe('should be ok with ->', function() {
54+
it('plain url', function(done) {
55+
fixtures.plain.ok.forEach(function (link) {
56+
assert.ok(test(link), link);
57+
});
58+
done();
59+
});
60+
it('channels url', function(done) {
61+
fixtures.channels.ok.forEach(function (link) {
62+
assert.ok(test(link), link);
63+
});
64+
done();
65+
});
66+
it('groups url', function(done) {
67+
fixtures.plain.ok.forEach(function (link) {
68+
assert.ok(test(link), link);
69+
});
70+
done();
71+
});
72+
it('attribute url', function(done) {
73+
fixtures.attrlink.ok.forEach(function (link) {
74+
assert.ok(test(link), link);
75+
});
76+
done();
77+
});
78+
});
79+
describe('should falied with ->', function() {
80+
it('plain url', function(done) {
81+
fixtures.plain.not_ok.forEach(function (link) {
82+
assert.equal(test(link), false, link);
83+
});
84+
done();
85+
});
86+
it('channels url', function(done) {
87+
fixtures.channels.not_ok.forEach(function (link) {
88+
assert.equal(test(link), false, link);
89+
});
90+
done();
91+
});
92+
it('groups url', function(done) {
93+
fixtures.plain.not_ok.forEach(function (link) {
94+
assert.equal(test(link), false, link);
95+
});
96+
done();
97+
});
98+
it('attribute url', function(done) {
99+
fixtures.attrlink.not_ok.forEach(function (link) {
100+
assert.equal(test(link), false, link);
27101
});
28102
done();
29103
});

0 commit comments

Comments
 (0)