@@ -14,41 +14,81 @@ function test(str) {
1414 return youtubeRegex ( ) . test ( str ) ;
1515}
1616
17+ var fixtures = {
18+ // should not match
19+ invalid : [
20+ 'youtube.com/embed/v=0EWbonj7f18' ,
21+ 'youtube.com/e/v=0EWbonj7f18' ,
22+ 'youtube.com/attribution_link?u=/embed/v=0EWbonj7f18' ,
23+ 'youtube.com/attribution_link?u=/e/v=0EWbonj7f18' ,
24+ 'hey guys go to youtube and v=thisweird video i found' ,
25+ 'i found a youtube video on 4chan /v/foobarbaz' ,
26+ 'but we work at youtu.be and /thisweird video'
27+ ] ,
28+ // short links
29+ shortlinks : [
30+ 'youtu.be/WijF8aivOo8' ,
31+ 'youtu.be/0EWbonj7f18'
32+ ] ,
33+ // mixed
34+ mixed : [
35+ 'youtube.com/user/sandervandoorntv/watch?v=WijF8aivOo8' ,
36+ 'youtube.com/user/sandervandoorntv/watch?v=WijF8aivOo8&feature=related' ,
37+ 'youtube.com/user/sandervandoorntv/watch?feature=related&v=WijF8aivOo8' ,
38+ 'youtube.com/watch?v=0EWbonj7f18' ,
39+ 'youtube.com/watch?feature=related&v=0EWbonj7f18' ,
40+ 'youtube.com/watch?v=0EWbonj7f18&feature=related' ,
41+ 'youtube.com/embed/watch?v=0EWbonj7f18' ,
42+ 'youtube.com/embed/watch?feature=related&v=0EWbonj7f18' ,
43+ 'youtube.com/embed/v/0EWbonj7f18' ,
44+ 'youtube.com/e/v/0EWbonj7f18' ,
45+ 'youtube.com/e/watch?v=0EWbonj7f18' ,
46+ 'youtube.com/e/watch?feature=related&v=0EWbonj7f18'
47+ ] ,
48+ // attribution link
49+ attrlink : [
50+ 'youtube.com/attribution_link?u=/user/sandervandoorntv/watch?v=WijF8aivOo8' ,
51+ 'youtube.com/attribution_link?u=/user/sandervandoorntv/watch?v=WijF8aivOo8&feature=related' ,
52+ 'youtube.com/attribution_link?u=/user/sandervandoorntv/watch?feature=related&v=WijF8aivOo8' ,
53+ 'youtube.com/attribution_link?u=/watch?v=0EWbonj7f18' ,
54+ 'youtube.com/attribution_link?u=/watch?feature=related&v=0EWbonj7f18' ,
55+ 'youtube.com/attribution_link?u=/watch?v=0EWbonj7f18&feature=related' ,
56+ 'youtube.com/attribution_link?u=/embed/watch?v=0EWbonj7f18' ,
57+ 'youtube.com/attribution_link?u=/embed/watch?feature=related&v=0EWbonj7f18' ,
58+ 'youtube.com/attribution_link?u=/embed/v/0EWbonj7f18' ,
59+ 'youtube.com/attribution_link?u=/e/v/0EWbonj7f18' ,
60+ 'youtube.com/attribution_link?u=/e/watch?v=0EWbonj7f18' ,
61+ 'youtube.com/attribution_link?u=/e/watch?feature=related&v=0EWbonj7f18'
62+ ]
63+ } ;
64+
1765describe ( 'youtube-regex' , function ( ) {
18- it ( 'should work with `watch` links' , function ( done ) {
19- assert . ok ( test ( 'youtube.com/watch?v=0EWbonj7f18' ) ) ;
20- assert . ok ( test ( 'youtube.com/watch?feature=related&v=0EWbonj7f18' ) ) ;
21- assert . ok ( test ( 'youtube.com/watch?v=0EWbonj7f18&feature=related' ) ) ;
22- assert . ok ( test ( 'http://www.youtube.com/watch?v=0EWbonj7f18' ) ) ;
23- assert . ok ( test ( 'http://www.youtube.com/watch?feature=related&v=0EWbonj7f18' ) ) ;
24- assert . ok ( test ( 'http://www.youtube.com/watch?v=0EWbonj7f18&feature=related' ) ) ;
25- assert . ok ( test ( 'https://www.youtube.com/watch?v=0EWbonj7f18' ) ) ;
26- assert . ok ( test ( 'https://www.youtube.com/watch?feature=related&v=0EWbonj7f18' ) ) ;
27- assert . ok ( test ( 'https://www.youtube.com/watch?v=0EWbonj7f18&feature=related' ) ) ;
28- assert . ok ( test ( 'www.youtube.com/watch?v=0EWbonj7f18' ) ) ;
29- assert . ok ( test ( 'www.youtube.com/watch?feature=related&v=0EWbonj7f18' ) ) ;
30- assert . ok ( test ( 'www.youtube.com/watch?v=0EWbonj7f18&feature=related' ) ) ;
31- done ( ) ;
32- } ) ;
33- it ( 'should work with `embed` links' , function ( done ) {
34- assert . ok ( test ( 'youtube.com/embed/watch?v=0EWbonj7f18' ) ) ;
35- assert . ok ( test ( 'youtube.com/embed/watch?feature=related&v=0EWbonj7f18' ) ) ;
36- assert . ok ( test ( 'youtube.com/embed/v/0EWbonj7f18' ) ) ;
37- assert . ok ( test ( 'youtube.com/embed/v=0EWbonj7f18' ) ) ;
38- done ( ) ;
39- } ) ;
40- it ( 'should work with shortlikns youtu.be/{id}' , function ( done ) {
41- assert . ok ( test ( 'http://youtu.be/0EWbonj7f18' ) ) ;
42- assert . ok ( test ( 'http://youtu.be/n17B_uFF4cA' ) ) ;
43- done ( ) ;
66+ describe ( 'should match id from' , function ( ) {
67+ it ( 'shortlinks `youtu.be/{id}`' , function ( done ) {
68+ fixtures . shortlinks . forEach ( function each ( link ) {
69+ assert . ok ( test ( link ) ) ;
70+ } ) ;
71+ done ( ) ;
72+ } ) ;
73+ it ( 'common used links' , function ( done ) {
74+ fixtures . mixed . forEach ( function each ( link ) {
75+ assert . ok ( test ( link ) ) ;
76+ } ) ;
77+ done ( ) ;
78+ } ) ;
79+ it ( 'attribution links' , function ( done ) {
80+ fixtures . attrlink . forEach ( function each ( link ) {
81+ assert . ok ( test ( link ) ) ;
82+ } ) ;
83+ done ( ) ;
84+ } ) ;
4485 } ) ;
45- it ( 'should work with `attribution_link`s (wtf?)' , function ( done ) {
46- assert . ok ( test ( 'youtube.com/attribution_link?u=/watch?v=0EWbonj7f18' ) ) ;
47- assert . ok ( test ( 'youtube.com/attribution_link?u=/v/0EWbonj7f18' ) ) ;
48- assert . ok ( test ( 'youtube.com/attribution_link?u=/embed/watch?feature=related&v=0EWbonj7f18' ) ) ;
49- assert . ok ( test ( 'youtube.com/attribution_link?u=/embed/watch?v=0EWbonj7f18' ) ) ;
50- assert . ok ( test ( 'youtube.com/attribution_link?u=/embed/v/0EWbonj7f18' ) ) ;
51- assert . ok ( test ( 'youtube.com/attribution_link?u=/embed/v=0EWbonj7f18' ) ) ;
52- done ( ) ;
86+ describe ( 'should NOT match id from' , function ( ) {
87+ it ( 'invalid links' , function ( done ) {
88+ fixtures . invalid . forEach ( function each ( link ) {
89+ assert ( ! test ( link ) ) ;
90+ } ) ;
91+ done ( ) ;
92+ } ) ;
5393 } ) ;
5494} ) ;
0 commit comments