<commit_before>// Load modules

var Lab = require('lab');
var Call = require('../');
var Code = require('code');


// Declare internals

var internals = {};


// Test shortcuts

var lab = exports.lab = Lab.script();
var describe = lab.describe;
var it = lab.it;
var expect = Code.expect;


describe('Router', function () {

    it('routes request', function (done) {

        var router = new Call.Router();
        router.add({ method: 'get', path: '/' }, '/');
        router.add({ method: 'get', path: '/a' }, '/a');
        router.add({ method: 'get', path: '/b' }, '/b');

        expect(router.route('get', '/').route).to.equal('/');
        expect(router.route('get', '/a').route).to.equal('/a');
        expect(router.route('get', '/b').route).to.equal('/b');

        done();
    });

    it('routes request (pre-analyzed)', function (done) {

        var router = new Call.Router();
        router.add({ method: 'get', path: '/', analysis: router.analyze('/') }, '/');
        router.add({ method: 'get', path: '/a', analysis: router.analyze('/a') }, '/a');
        router.add({ method: 'get', path: '/b', analysis: router.analyze('/b') }, '/b');

        expect(router.route('get', '/').route).to.equal('/');
        expect(router.route('get', '/a').route).to.equal('/a');
        expect(router.route('get', '/b').route).to.equal('/b');

        done();
    });

    it('matches routes in right order', function (done) {

        var paths = [
            '/',
            '/a',
            '/b',
            '/ab',
            '/a{p}b',
            '/a{p}',
            '/{p}b',
            '/{p}',
            '/a/b',
            '/a/{p}',
            '/b/',
            '/a1{p}/a',
            '/xx{p}/b',
            '/x{p}/a',
            '/x{p}/b',
            '/y{p?}/b',
            '/{p}xx/b',
            '/{p}x/b',
            '/{p}y/b',
            '/a/b/c',
            '/a/b/{p}',
            '/a/d{p}c/b',
            '/a/d{p}/b',
            '/a/{p}d/b',
            '/a/{p}/b',
            '/a/{p}/c',
            '/a/{p*2}',
            '/a/b/c/d',
            '/a/b/{p*2}',
            '/a/{p}/b/{x}',
            '/{p*5}',
            '/a/b/{p*}',
            '/{a}/b/{p*}',
            '/{p*}'
        ];

        var requests = [
            ['/', '/'],
            ['/a', '/a'],
            ['/b', '/b'],
            ['/ab', '/ab'],
            ['/axb', '/a{p}b'],
            ['/axc', '/a{p}'],
            ['/bxb', '/{p}b'],
            ['/c', '/{p}'],
            ['/a/b', '/a/b'],
            ['/a/c', '/a/{p}'],
            ['/b/', '/b/'],
            ['/a1larry/a', '/a1{p}/a'],
            ['/xx1/b', '/xx{p}/b'],
            ['/xx1/a', '/x{p}/a'],
            ['/x1/b', '/x{p}/b'],
            ['/y/b', '/y{p?}/b'],
            ['/0xx/b', '/{p}xx/b'],
            ['/0x/b', '/{p}x/b'],
            ['/ay/b', '/{p}y/b'],
            ['/a/b/c', '/a/b/c'],
            ['/a/b/d', '/a/b/{p}'],
            ['/a/doc/b', '/a/d{p}c/b'],
            ['/a/dl/b', '/a/d{p}/b'],
            ['/a/ld/b', '/a/{p}d/b'],
            ['/a/a/b', '/a/{p}/b'],
            ['/a/d/c', '/a/{p}/c'],
            ['/a/d/d', '/a/{p*2}'],
            ['/a/b/c/d', '/a/b/c/d'],
            ['/a/b/c/e', '/a/b/{p*2}'],
            ['/a/c/b/d', '/a/{p}/b/{x}'],
            ['/a/b/c/d/e', '/a/b/{p*}'],
            ['/a/b/c/d/e/f', '/a/b/{p*}'],
            ['/x/b/c/d/e/f/g', '/{a}/b/{p*}'],
            ['/x/y/c/d/e/f/g', '/{p*}']
        ];

        var router = new Call.Router();
        for (var i = 0, il = paths.length; i < il; ++i) {
            router.add({ method: 'get', path: paths[i] }, paths[i]);
        }

        for (i = 0, il = requests.length; i < il; ++i) {
            expect(router.route('get', requests[i][0]).route).to.equal(requests[i][1]);
        }

        done();
    });<commit_msg>Verify correct sort order. Closes #8, Closes #7, Closes #6<commit_after>// Load modules

var Lab = require('lab');
var Call = require('../');
var Code = require('code');


// Declare internals

var internals = {};


// Test shortcuts

var lab = exports.lab = Lab.script();
var describe = lab.describe;
var it = lab.it;
var expect = Code.expect;


describe('Router', function () {

    it('routes request', function (done) {

        var router = new Call.Router();
        router.add({ method: 'get', path: '/' }, '/');
        router.add({ method: 'get', path: '/a' }, '/a');
        router.add({ method: 'get', path: '/b' }, '/b');

        expect(router.route('get', '/').route).to.equal('/');
        expect(router.route('get', '/a').route).to.equal('/a');
        expect(router.route('get', '/b').route).to.equal('/b');

        done();
    });

    it('routes request (pre-analyzed)', function (done) {

        var router = new Call.Router();
        router.add({ method: 'get', path: '/', analysis: router.analyze('/') }, '/');
        router.add({ method: 'get', path: '/a', analysis: router.analyze('/a') }, '/a');
        router.add({ method: 'get', path: '/b', analysis: router.analyze('/b') }, '/b');

        expect(router.route('get', '/').route).to.equal('/');
        expect(router.route('get', '/a').route).to.equal('/a');
        expect(router.route('get', '/b').route).to.equal('/b');

        done();
    });

    describe('sort', function () {

        var paths = [
            '/',
            '/a',
            '/b',
            '/ab',
            '/a{p}b',
            '/a{p}',
            '/{p}b',
            '/{p}',
            '/a/b',
            '/a/{p}',
            '/b/',
            '/a1{p}/a',
            '/xx{p}/b',
            '/x{p}/a',
            '/x{p}/b',
            '/y{p?}/b',
            '/{p}xx/b',
            '/{p}x/b',
            '/{p}y/b',
            '/a/b/c',
            '/a/b/{p}',
            '/a/d{p}c/b',
            '/a/d{p}/b',
            '/a/{p}d/b',
            '/a/{p}/b',
            '/a/{p}/c',
            '/a/{p*2}',
            '/a/b/c/d',
            '/a/b/{p*2}',
            '/a/{p}/b/{x}',
            '/{p*5}',
            '/a/b/{p*}',
            '/{a}/b/{p*}',
            '/{p*}',
            '/m/n/{p*}',
            '/m/{n}/{o}',
            '/n/{p*}',
            '/n/{p}/{o*}'
        ];

        var router = new Call.Router();
        for (var i = 0, il = paths.length; i < il; ++i) {
            router.add({ method: 'get', path: paths[i] }, paths[i]);
        }

        var requests = [
            ['/', '/'],
            ['/a', '/a'],
            ['/b', '/b'],
            ['/ab', '/ab'],
            ['/axb', '/a{p}b'],
            ['/axc', '/a{p}'],
            ['/bxb', '/{p}b'],
            ['/c', '/{p}'],
            ['/a/b', '/a/b'],
            ['/a/c', '/a/{p}'],
            ['/b/', '/b/'],
            ['/a1larry/a', '/a1{p}/a'],
            ['/xx1/b', '/xx{p}/b'],
            ['/xx1/a', '/x{p}/a'],
            ['/x1/b', '/x{p}/b'],
            ['/y/b', '/y{p?}/b'],
            ['/0xx/b', '/{p}xx/b'],
            ['/0x/b', '/{p}x/b'],
            ['/ay/b', '/{p}y/b'],
            ['/a/b/c', '/a/b/c'],
            ['/a/b/d', '/a/b/{p}'],
            ['/a/doc/b', '/a/d{p}c/b'],
            ['/a/dl/b', '/a/d{p}/b'],
            ['/a/ld/b', '/a/{p}d/b'],
            ['/a/a/b', '/a/{p}/b'],
            ['/a/d/c', '/a/{p}/c'],
            ['/a/d/d', '/a/{p*2}'],
            ['/a/b/c/d', '/a/b/c/d'],
            ['/a/b/c/e', '/a/b/{p*2}'],
            ['/a/c/b/d', '/a/{p}/b/{x}'],
            ['/a/b/c/d/e', '/a/b/{p*}'],
            ['/a/b/c/d/e/f', '/a/b/{p*}'],
            ['/x/b/c/d/e/f/g', '/{a}/b/{p*}'],
            ['/x/y/c/d/e/f/g', '/{p*}'],
            ['/m/n/o', '/m/n/{p*}'],
            ['/m/o/p', '/m/{n}/{o}'],
            ['/n/a/b/c', '/n/{p}/{o*}'],
            ['/n/a', '/n/{p}/{o*}']
        ];

        var test = function (path, route) {

            it('matches \'' + path + '\' to \'' + route + '\'', function (done) {

                expect(router.route('get', path).route).to.equal(route);
                done();
            });
        };

        for (i = 0, il = requests.length; i < il; ++i) {
            test(requests[i][0], requests[i][1]);
        }
    });
{'fraction_non_alphanumeric': 0.3075030750307503, 'fraction_numerical': 0.0045510455104551045, 'mean_word_length': 1.2167393675027263, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, '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': '3773337', 'n_tokens_mistral': 3103, 'n_tokens_neox': 3085, 'n_words': 513}