Skip to content

Commit

Permalink
Use native asserts
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitaly Puzrin committed May 19, 2020
1 parent 4575e72 commit 86fe8e2
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 41 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
"autoprefixer-stylus": "^0.14.0",
"benchmark": "^2.1.0",
"browserify": "^16.2.3",
"chai": "^4.2.0",
"coveralls": "^3.0.2",
"eslint": "^7.0.0",
"mdurl": "^1.0.0",
Expand Down
80 changes: 40 additions & 40 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

var fs = require('fs');
var path = require('path');
var assert = require('chai').assert;
var assert = require('assert');

var linkify = require('../');

Expand Down Expand Up @@ -38,15 +38,15 @@ describe('links', function () {
assert.ok(l.pretest(line), '(pretest failed in `' + line + '`)');
assert.ok(l.test('\n' + line + '\n'), '(link not found in `\\n' + line + '\\n`)');
assert.ok(l.test(line), '(link not found in `' + line + '`)');
assert.equal(l.match(line)[0].url, next);
assert.strictEqual(l.match(line)[0].url, next);
});
skipNext = true;
} else {
it('line ' + (idx + 1), function () {
assert.ok(l.pretest(line), '(pretest failed in `' + line + '`)');
assert.ok(l.test('\n' + line + '\n'), '(link not found in `\\n' + line + '\\n`)');
assert.ok(l.test(line), '(link not found in `' + line + '`)');
assert.equal(l.match(line)[0].url, line);
assert.strictEqual(l.match(line)[0].url, line);
});
}
});
Expand All @@ -68,7 +68,7 @@ describe('not links', function () {
if (!line.trim()) { return; }

it('line ' + (idx + 1), function () {
assert.notOk(l.test(line),
assert.ok(!l.test(line),
'(should not find link in `' + line + '`, but found `' +
JSON.stringify((l.match(line) || [])[0]) + '`)');
});
Expand All @@ -81,17 +81,17 @@ describe('API', function () {
it('extend tlds', function () {
var l = linkify();

assert.notOk(l.test('google.myroot'));
assert.ok(!l.test('google.myroot'));

l.tlds('myroot', true);

assert.ok(l.test('google.myroot'));
assert.notOk(l.test('google.xyz'));
assert.ok(!l.test('google.xyz'));

l.tlds(require('tlds'));

assert.ok(l.test('google.xyz'));
assert.notOk(l.test('google.myroot'));
assert.ok(!l.test('google.myroot'));
});


Expand All @@ -102,8 +102,8 @@ describe('API', function () {

var match = l.match('google.com. my:// my://asdf!');

assert.equal(match[0].text, 'google.com');
assert.equal(match[1].text, 'my://asdf');
assert.strictEqual(match[0].text, 'google.com');
assert.strictEqual(match[1].text, 'my://asdf');
});


Expand All @@ -118,8 +118,8 @@ describe('API', function () {

var match = l.match('google.com. my:// my://asdf!');

assert.equal(match[1].text, 'ASDF');
assert.equal(match[1].url, 'MY://ASDF');
assert.strictEqual(match[1].text, 'ASDF');
assert.strictEqual(match[1].url, 'MY://ASDF');
});


Expand All @@ -130,8 +130,8 @@ describe('API', function () {
assert.ok(l.test('foo@bar.com'));
l.add('http:', null);
l.add('mailto:', null);
assert.notOk(l.test('http://google.com'));
assert.notOk(l.test('foo@bar.com'));
assert.ok(!l.test('http://google.com'));
assert.ok(!l.test('foo@bar.com'));
});


Expand All @@ -140,19 +140,19 @@ describe('API', function () {

l = linkify();

assert.throw(function () {
assert.throws(function () {
l.add('test:', []);
});

l = linkify();

assert.throw(function () {
assert.throws(function () {
l.add('test:', { validate: [] });
});

l = linkify();

assert.throw(function () {
assert.throws(function () {
l.add('test:', {
validate: function () { return false; },
normalize: 'bad'
Expand All @@ -166,9 +166,9 @@ describe('API', function () {

assert.ok(l.testSchemaAt('http://google.com', 'http:', 5));
assert.ok(l.testSchemaAt('http://google.com', 'HTTP:', 5));
assert.notOk(l.testSchemaAt('http://google.com', 'http:', 6));
assert.ok(!l.testSchemaAt('http://google.com', 'http:', 6));

assert.notOk(l.testSchemaAt('http://google.com', 'bad_schema:', 6));
assert.ok(!l.testSchemaAt('http://google.com', 'bad_schema:', 6));
});


Expand All @@ -177,9 +177,9 @@ describe('API', function () {

var match = l.match('.com. http://google.com google.com ftp://google.com');

assert.equal(match[0].text, 'http://google.com');
assert.equal(match[1].text, 'google.com');
assert.equal(match[2].text, 'ftp://google.com');
assert.strictEqual(match[0].text, 'http://google.com');
assert.strictEqual(match[1].text, 'google.com');
assert.strictEqual(match[2].text, 'ftp://google.com');
});


Expand All @@ -188,13 +188,13 @@ describe('API', function () {

m = l.match('mailto:foo@bar.com')[0];

// assert.equal(m.text, 'foo@bar.com');
assert.equal(m.url, 'mailto:foo@bar.com');
// assert.strictEqual(m.text, 'foo@bar.com');
assert.strictEqual(m.url, 'mailto:foo@bar.com');

m = l.match('foo@bar.com')[0];

// assert.equal(m.text, 'foo@bar.com');
assert.equal(m.url, 'mailto:foo@bar.com');
// assert.strictEqual(m.text, 'foo@bar.com');
assert.strictEqual(m.url, 'mailto:foo@bar.com');
});


Expand All @@ -221,46 +221,46 @@ describe('API', function () {
}
});

assert.equal(l.match('hello, @gamajoba_!')[0].text, '@gamajoba_');
assert.equal(l.match(':@givi')[0].text, '@givi');
assert.equal(l.match(':@givi')[0].url, 'https://twitter.com/givi');
assert.notOk(l.test('@@invalid'));
assert.strictEqual(l.match('hello, @gamajoba_!')[0].text, '@gamajoba_');
assert.strictEqual(l.match(':@givi')[0].text, '@givi');
assert.strictEqual(l.match(':@givi')[0].url, 'https://twitter.com/givi');
assert.ok(!l.test('@@invalid'));
});


it('set option: fuzzyLink', function () {
var l = linkify({ fuzzyLink: false });

assert.equal(l.test('google.com.'), false);
assert.strictEqual(l.test('google.com.'), false);

l.set({ fuzzyLink: true });

assert.equal(l.test('google.com.'), true);
assert.equal(l.match('google.com.')[0].text, 'google.com');
assert.strictEqual(l.test('google.com.'), true);
assert.strictEqual(l.match('google.com.')[0].text, 'google.com');
});


it('set option: fuzzyEmail', function () {
var l = linkify({ fuzzyEmail: false });

assert.equal(l.test('foo@bar.com.'), false);
assert.strictEqual(l.test('foo@bar.com.'), false);

l.set({ fuzzyEmail: true });

assert.equal(l.test('foo@bar.com.'), true);
assert.equal(l.match('foo@bar.com.')[0].text, 'foo@bar.com');
assert.strictEqual(l.test('foo@bar.com.'), true);
assert.strictEqual(l.match('foo@bar.com.')[0].text, 'foo@bar.com');
});


it('set option: fuzzyIP', function () {
var l = linkify();

assert.equal(l.test('1.1.1.1.'), false);
assert.strictEqual(l.test('1.1.1.1.'), false);

l.set({ fuzzyIP: true });

assert.equal(l.test('1.1.1.1.'), true);
assert.equal(l.match('1.1.1.1.')[0].text, '1.1.1.1');
assert.strictEqual(l.test('1.1.1.1.'), true);
assert.strictEqual(l.match('1.1.1.1.')[0].text, '1.1.1.1');
});

it('should not hang in fuzzy mode with sequences of astrals', function () {
Expand All @@ -275,10 +275,10 @@ describe('API', function () {
it('should accept `---` if enabled', function () {
var l = linkify();

assert.equal(l.match('http://e.com/foo---bar')[0].text, 'http://e.com/foo---bar');
assert.strictEqual(l.match('http://e.com/foo---bar')[0].text, 'http://e.com/foo---bar');

l = linkify(null, { '---': true });

assert.equal(l.match('http://e.com/foo---bar')[0].text, 'http://e.com/foo');
assert.strictEqual(l.match('http://e.com/foo---bar')[0].text, 'http://e.com/foo');
});
});

0 comments on commit 86fe8e2

Please sign in to comment.