Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Charlike Mike Reagent committed Dec 12, 2014
1 parent 1273d8c commit 3021a61
Show file tree
Hide file tree
Showing 9 changed files with 104 additions and 233 deletions.
116 changes: 0 additions & 116 deletions .jscsrc

This file was deleted.

23 changes: 0 additions & 23 deletions .jshintignore

This file was deleted.

35 changes: 0 additions & 35 deletions .jshintrc

This file was deleted.

34 changes: 34 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Makefile <https://github.com/tunnckoCore/dotfiles>
#
# Copyright (c) 2014 Charlike Mike Reagent, contributors.
# Released under the MIT license.
#

JSCS = node_modules/.bin/jscs
MOCHA = node_modules/.bin/mocha
_MOCHA = node_modules/.bin/_mocha
JSHINT = node_modules/.bin/jshint
ISTANBUL = node_modules/.bin/istanbul
COVERALLS = node_modules/.bin/coveralls

lint:
npm install
${JSHINT} .
${JSCS} . --reporter inline

test: lint
${MOCHA}

test-cov: lint
${ISTANBUL} cover ${_MOCHA}

test-travis: lint
${ISTANBUL} cover ${_MOCHA} --report lcovonly

coveralls: test-travis
cat ./coverage/lcov.info | ${COVERALLS}

clean:
rm -rf node_modules coverage

.PHONY: lint test coveralls clean
44 changes: 0 additions & 44 deletions fixture.txt

This file was deleted.

6 changes: 4 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

'use strict';

module.exports = function youtubeRegex() {
return /youtu(?:.+\/v\/|.*v\=|\.be\/)([A-Za-z0-9_\-]{6,11})/g;
module.exports = function youtubeRegex() {
var regex = /youtu(?:.+\/v\/|.*v\=|\.be\/)([A-Za-z0-9_\-]{6,11})/g;

return regex;
};
10 changes: 3 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
"description": "The correct Youtube video id regex. Regex done right!",
"version": "0.0.0",
"scripts": {
"lint": "npm install && node_modules/.bin/jshint . && node_modules/.bin/jscs . --reporter inline",
"test": "npm run lint && node_modules/.bin/mocha",
"test-cov": "npm run lint && node_modules/.bin/istanbul cover node_modules/.bin/_mocha",
"test-travis": "npm run lint && node_modules/.bin/istanbul cover node_modules/.bin/_mocha --report lcovonly",
"test": "npm install && node_modules/.bin/mocha",
"test-cov": "node_modules/.bin/istanbul cover node_modules/.bin/_mocha",
"test-travis": "node_modules/.bin/istanbul cover node_modules/.bin/_mocha --report lcovonly",
"coveralls": "npm run test-travis && cat ./coverage/lcov.info | node_modules/.bin/coveralls"
},
"author": {
Expand Down Expand Up @@ -37,9 +36,6 @@
"devDependencies": {
"coveralls": "^2.11.2",
"istanbul": "^0.3.2",
"jscs": ">=1.8.0",
"jscs-jsdoc": ">=0.2.0",
"jshint": "^2.5.10",
"mocha": "^2.0.1",
"mocha-lcov-reporter": "0.0.1"
},
Expand Down
13 changes: 13 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,20 @@ var youtubeRegex = require('youtube-regex');
// contains youtube url address
youtubeRegex().test('unicorn youtube.com/watch?v=0EWbonj7f18');
//=> true

// also these will works
youtubeRegex().test('youtube.com/watch?v=0EWbonj7f18');
//=> true
youtubeRegex().test('youtube.com/watch?feature=related&v=0EWbonj7f18');
//=> true
youtubeRegex().test('youtube.com/watch?v=0EWbonj7f18&feature=related');
//=> true
youtubeRegex().test('http://www.youtube.com/watch?v=0EWbonj7f18');
//=> true
youtubeRegex().test('http://www.youtube.com/watch?feature=related&v=0EWbonj7f18');
//=> true
```
> For more use-cases see [tests](./test.js)

## Authors & Contributors
Expand Down
56 changes: 50 additions & 6 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,54 @@
/**
* youtube-regex <https://github.com/tunnckoCore/youtube-regex>
*
* Copyright (c) 2014 Charlike Mike Reagent, contributors.
* Released under the MIT license.
*/

'use strict';

var youtubeRegex = require('./index')
var read = require('fs').readFileSync;
var youtubeRegex = require('./index');
var assert = require('assert');

var fixture = read('fixture.txt', 'utf-8');
function test(str) {
return youtubeRegex().test(str);
}

// contains youtube url address
youtubeRegex().test(fixture);
//=> true
describe('youtube-regex', function() {
it('should work with `watch` links', function(done) {
assert.ok(test('youtube.com/watch?v=0EWbonj7f18'));
assert.ok(test('youtube.com/watch?feature=related&v=0EWbonj7f18'));
assert.ok(test('youtube.com/watch?v=0EWbonj7f18&feature=related'));
assert.ok(test('http://www.youtube.com/watch?v=0EWbonj7f18'));
assert.ok(test('http://www.youtube.com/watch?feature=related&v=0EWbonj7f18'));
assert.ok(test('http://www.youtube.com/watch?v=0EWbonj7f18&feature=related'));
assert.ok(test('https://www.youtube.com/watch?v=0EWbonj7f18'));
assert.ok(test('https://www.youtube.com/watch?feature=related&v=0EWbonj7f18'));
assert.ok(test('https://www.youtube.com/watch?v=0EWbonj7f18&feature=related'));
assert.ok(test('www.youtube.com/watch?v=0EWbonj7f18'));
assert.ok(test('www.youtube.com/watch?feature=related&v=0EWbonj7f18'));
assert.ok(test('www.youtube.com/watch?v=0EWbonj7f18&feature=related'));
done();
});
it('should work with `embed` links', function(done) {
assert.ok(test('youtube.com/embed/watch?v=0EWbonj7f18'));
assert.ok(test('youtube.com/embed/watch?feature=related&v=0EWbonj7f18'));
assert.ok(test('youtube.com/embed/v/0EWbonj7f18'));
assert.ok(test('youtube.com/embed/v=0EWbonj7f18'));
done();
});
it('should work with shortlikns youtu.be/{id}', function(done) {
assert.ok(test('http://youtu.be/0EWbonj7f18'));
assert.ok(test('http://youtu.be/n17B_uFF4cA'));
done();
});
it('should work with `attribution_link`s (wtf?)', function(done) {
assert.ok(test('youtube.com/attribution_link?u=/watch?v=0EWbonj7f18'));
assert.ok(test('youtube.com/attribution_link?u=/v/0EWbonj7f18'));
assert.ok(test('youtube.com/attribution_link?u=/embed/watch?feature=related&v=0EWbonj7f18'));
assert.ok(test('youtube.com/attribution_link?u=/embed/watch?v=0EWbonj7f18'));
assert.ok(test('youtube.com/attribution_link?u=/embed/v/0EWbonj7f18'));
assert.ok(test('youtube.com/attribution_link?u=/embed/v=0EWbonj7f18'));
done();
});
});

0 comments on commit 3021a61

Please sign in to comment.