<commit_before>import test from 'ava';
import fn from './';

test('match exact URLs', t => {
	const fixtures = [
		'http://foo.com/blah_blah',
		'http://foo.com/blah_blah/',
		'http://foo.com/blah_blah_(wikipedia)',
		'http://foo.com/blah_blah_(wikipedia)_(again)',
		'http://www.example.com/wpstyle/?p=364',
		'https://www.example.com/foo/?bar=baz&inga=42&quux',
		'http://a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q.r.s.t.u.v.w.x.y.z.com',
		'http://mw1.google.com/mw-earth-vectordb/kml-samples/gp/seattle/gigapxl/$[level]/r$[y]_c$[x].jpg',
		'http://user:pass@example.com:123/one/two.three?q1=a1&q2=a2#body',
		'http://www.microsoft.xn--comindex-g03d.html.irongeek.com',
		'http://✪df.ws/123',
		'http://localhost/',
		'http://userid:password@example.com:8080',
		'http://userid:password@example.com:8080/',
		'http://userid@example.com',
		'http://userid@example.com/',
		'http://userid@example.com:8080',
		'http://userid@example.com:8080/',
		'http://userid:password@example.com',
		'http://userid:password@example.com/',
		'http://172.16.17.32/',
		'http://172.16.17.32:8080/',
		'http://➡.ws/䨹',
		'http://⌘.ws',
		'http://⌘.ws/',
		'http://foo.com/blah_(wikipedia)#cite-1',
		'http://foo.com/blah_(wikipedia)_blah#cite-1',
		'http://foo.com/unicode_(✪)_in_parens',
		'http://foo.com/(something)?after=parens',
		'http://☺.damowmow.com/',
		'http://code.google.com/events/#&product=browser',
		'http://j.mp',
		'ftp://foo.bar/baz',
		'http://foo.bar/?q=Test%20URL-encoded%20stuff',
		'http://مثال.إختبار',
		'http://例子.测试',
		'http://उदाहरण.परीक्षा',
		'http://-.~_!$&\'()*+\';=:%40:80%2f::::::@example.com',
		'http://1337.net',
		'http://a.b-c.de',
		'http://172.16.17.32',
		'http://example.com?foo=bar',
		'http://example.com#foo',
		'ws://localhost:8080',
		'ws://foo.ws',
		'ws://foo.ws',
		'ws://a.b-c.de',
		'ws://172.16.17.32',
		'ws://userid:<EMAIL>',
		'ws://➡.ws/䨹',
		'//localhost:8080',
		'//foo.ws',
		'//a.b-c.de',
		'//172.16.17.32',
		'//userid:<EMAIL>',
		'//➡.ws/䨹'
	];

	fixtures.forEach(el => t.true(fn({exact: true}).test(el)));
});

test('match URLs in text', t => {
	const fixture = [
		'Lorem ipsum //dolor.sit',
		'<a href="http://example.com">example.com</a>',
		'[and another](https://another.example.com)',
		'Foo //bar.net/?q=Query with spaces'
	].join('\n');

	const expected = [
		'//dolor.sit',
		'http://example.com',
		'https://another.example.com',
		'//bar.net/?q=Query'
	];

	const actual = fixture.match(fn());

	expected.forEach((url, i) => t.is(actual[i], url));
});

test('do not match URLs', t => {
	const fixtures = [
		'http://',
		'http://.',
		'http://..',
		'http://../',
		'http://?',
		'http://??',
		'http://??/',
		'http://#',
		'http://##',
		'http://##/',
		'http://foo.bar?q=Spaces should be encoded',
		'//',<commit_msg>Small fixes for nicer looking test<commit_after>import test from 'ava';
import fn from './';

test('match exact URLs', t => {
	const fixtures = [
		'http://foo.com/blah_blah',
		'http://foo.com/blah_blah/',
		'http://foo.com/blah_blah_(wikipedia)',
		'http://foo.com/blah_blah_(wikipedia)_(again)',
		'http://www.example.com/wpstyle/?p=364',
		'https://www.example.com/foo/?bar=baz&inga=42&quux',
		'http://a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q.r.s.t.u.v.w.x.y.z.com',
		'http://mw1.google.com/mw-earth-vectordb/kml-samples/gp/seattle/gigapxl/$[level]/r$[y]_c$[x].jpg',
		'http://user:pass@example.com:123/one/two.three?q1=a1&q2=a2#body',
		'http://www.microsoft.xn--comindex-g03d.html.irongeek.com',
		'http://✪df.ws/123',
		'http://localhost/',
		'http://userid:password<EMAIL>:8080',
		'http://userid:password@example.com:8080/',
		'http://<EMAIL>',
		'http://<EMAIL>/',
		'http://<EMAIL>:8080',
		'http://<EMAIL>:8080/',
		'http://userid:password@example.com',
		'http://userid:password@example.com/',
		'http://172.16.17.32/',
		'http://172.16.17.32:8080/',
		'http://➡.ws/䨹',
		'http://⌘.ws',
		'http://⌘.ws/',
		'http://foo.com/blah_(wikipedia)#cite-1',
		'http://foo.com/blah_(wikipedia)_blah#cite-1',
		'http://foo.com/unicode_(✪)_in_parens',
		'http://foo.com/(something)?after=parens',
		'http://☺.damowmow.com/',
		'http://code.google.com/events/#&product=browser',
		'http://j.mp',
		'ftp://foo.bar/baz',
		'http://foo.bar/?q=Test%20URL-encoded%20stuff',
		'http://مثال.إختبار',
		'http://例子.测试',
		'http://उदाहरण.परीक्षा',
		'http://-.~_!$&\'()*+\';=:%40:80%2f::::::@example.com',
		'http://1337.net',
		'http://a.b-c.de',
		'http://172.16.17.32',
		'http://example.com?foo=bar',
		'http://example.com#foo',
		'ws://localhost:8080',
		'ws://foo.ws',
		'ws://foo.ws',
		'ws://a.b-c.de',
		'ws://172.16.17.32',
		'ws://userid:<EMAIL>',
		'ws://➡.ws/䨹',
		'//localhost:8080',
		'//foo.ws',
		'//a.b-c.de',
		'//172.16.17.32',
		'//userid:<EMAIL>',
		'//➡.ws/䨹'
	];

	fixtures.forEach(el => t.true(fn({exact: true}).test(el)));
});

test('match URLs in text', t => {
	const fixture = `
		Lorem ipsum //dolor.sit
		<a href="http://example.com">example.com</a>
		[and another](https://another.example.com) and
		Foo //bar.net/?q=Query with spaces
	`;

	const expected = [
		'//dolor.sit',
		'http://example.com',
		'https://another.example.com',
		'//bar.net/?q=Query'
	];

	const actual = fixture.match(fn());

	t.same(actual, expected);
});

test('do not match URLs', t => {
	const fixtures = [
		'http://',
		'http://.',
		'http://..',
		'http://../',
		'http://?',
		'http://??',
		'http://??/',
		'http://#',
		'http://##',
		'http://##/',
		'http://foo.bar?q=Spaces should be encoded',
		'//',
{'fraction_non_alphanumeric': 0.30759401241328954, 'fraction_numerical': 0.038700255567725446, 'mean_word_length': 3.1888379204892967, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 25, 'https://': 6, 'lorem ipsum': 0, 'www.': 6, 'xml': 0}, 'pii_count': 23, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6994696', 'n_tokens_mistral': 2842, 'n_tokens_neox': 2528, 'n_words': 253}