<commit_before>var expect = chai.expect;
var router = new RouterRouter();

// Override browser's native Location object. See:
// https://github.com/jashkenas/backbone/blob/master/test/router.js#L13-L41
var Location = function(href) {
	this.replace(href);
};

Location.prototype = {
	parser: document.createElement('a'),

	replace: function(href) {
		this.parser.href = href;

		this.href = this.parser.href;
		this.hash = this.parser.hash;
		this.host = this.parser.host;
		this.search = this.parser.search;
		this.fragment = this.parser.fragment;
		this.pathname = this.parser.pathname;
		this.protocol = this.parser.protocol;

		// In IE, anchor.pathname does not contain a leading slash though
		// window.location.pathname does.
		if (!/^\//.test(this.pathname)) this.pathname = '/' + this.pathname;
	},

	toString: function() {
		return this.href;
	}
};

describe('RouterRouter', function() {
	it('should match an empty string.', function() {
		var isIndex = false;

		router.location = new Location('http://example.com');

		router.route('', function() {
			isIndex = true;
		});

		expect(isIndex).to.equal(true);
	});

	it('should match a string.', function() {
		var isMatched = false;

		router.location = new Location('http://example.com/foo');

		router.route('foo', function() {
			isMatched = true;
		});

		expect(isMatched).to.equal(true);
	});

	it('should match a string with Unicode characters.', function() {
		var isMatched = false;

		router.location = new Location('http://example.com/motleycrüe');

		router.route('motleycrüe', function() {
			isMatched = true;
		});

		expect(isMatched).to.equal(true);
	});

	it('should match a string with newline characters.', function() {
		var isMatched = false;

		router.location = new Location('http://example.com/foo%0Abar');

		router.route('foo\nbar', function() {
			isMatched = true;
		});

		expect(isMatched).to.equal(true);
	});

	it('should match parameter parts.', function() {
		router.location = new Location('http://example.com/1/2/3');

		router.route(':foo/:bar/:biz', function(foo, bar, biz) {
			expect(foo).to.equal('1');
			expect(bar).to.equal('2');
			expect(biz).to.equal('3');
		});
	});

	it('should match splat parts.', function() {
		router.location = new Location('http://example.com/path/to/some/file.txt');

		router.route('path/*foo', function(foo) {
			expect(foo).to.equal('to/some/file.txt');
		});
	});

	describe('should match optional parts and', function() {
		it('returns the optional part when an optional part matches.', function() {
			router.location = new Location('http://example.com/blog/sample-post-title');

			router.route(':foo(/:bar)', function(foo, bar) {
				expect(foo).to.equal('blog');
				expect(bar).to.equal('sample-post-title');
			});
		});

		it('returns null when an optional part does not match.', function() {
			router.location = new Location('http://example.com/blog');

			router.route(':foo(/:bar)', function(foo, bar) {
				expect(foo).to.equal('blog');
				expect(bar).to.equal(null);
			});
		});
	});
});<commit_msg>Switch to use chai.should() instead of chai.expect.<commit_after>var should = chai.should();
var router = new RouterRouter();

// Override browser's native Location object. See:
// https://github.com/jashkenas/backbone/blob/master/test/router.js#L13-L41
var Location = function(href) {
	this.replace(href);
};

Location.prototype = {
	parser: document.createElement('a'),

	replace: function(href) {
		this.parser.href = href;

		this.href = this.parser.href;
		this.hash = this.parser.hash;
		this.host = this.parser.host;
		this.search = this.parser.search;
		this.fragment = this.parser.fragment;
		this.pathname = this.parser.pathname;
		this.protocol = this.parser.protocol;

		// In IE, anchor.pathname does not contain a leading slash though
		// window.location.pathname does.
		if (!/^\//.test(this.pathname)) this.pathname = '/' + this.pathname;
	},

	toString: function() {
		return this.href;
	}
};

describe('RouterRouter', function() {
	it('should match an empty string.', function() {
		var isIndex = false;

		router.location = new Location('http://example.com');

		router.route('', function() {
			isIndex = true;
		});

		isIndex.should.equal(true);
	});

	it('should match a string.', function() {
		var isMatched = false;

		router.location = new Location('http://example.com/foo');

		router.route('foo', function() {
			isMatched = true;
		});

		isMatched.should.equal(true);
	});

	it('should match a string with Unicode characters.', function() {
		var isMatched = false;

		router.location = new Location('http://example.com/motleycrüe');

		router.route('motleycrüe', function() {
			isMatched = true;
		});

		isMatched.should.equal(true);
	});

	it('should match a string with newline characters.', function() {
		var isMatched = false;

		router.location = new Location('http://example.com/foo%0Abar');

		router.route('foo\nbar', function() {
			isMatched = true;
		});

		isMatched.should.equal(true);
	});

	it('should match parameter parts.', function() {
		router.location = new Location('http://example.com/1/2/3');

		router.route(':foo/:bar/:biz', function(foo, bar, biz) {
			foo.should.equal('1');
			bar.should.equal('2');
			biz.should.equal('3');
		});
	});

	it('should match splat parts.', function() {
		router.location = new Location('http://example.com/path/to/some/file.txt');

		router.route('path/*foo', function(foo) {
			foo.should.equal('to/some/file.txt');
		});
	});

	describe('should match optional parts and', function() {
		it('returns the optional part when an optional part matches.', function() {
			router.location = new Location('http://example.com/blog/sample-post-title');

			router.route(':foo(/:bar)', function(foo, bar) {
				foo.should.equal('blog');
				bar.should.equal('sample-post-title');
			});
		});

		it('returns null when an optional part does not match.', function() {
			router.location = new Location('http://example.com/blog');

			router.route(':foo(/:bar)', function(foo, bar) {
				foo.should.equal('blog');
				should.not.exist(bar);
			});
		});
	});
});
{'fraction_non_alphanumeric': 0.18570726110473693, 'fraction_numerical': 0.0036059662350434356, 'mean_word_length': 3.804724409448819, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1299884', 'n_tokens_mistral': 2210, 'n_tokens_neox': 1975, 'n_words': 406}