<commit_before>describe('ns.router', function() {

    describe('API', function() {

        it('should be defined', function() {
            expect(ns.router).to.be.a('function');
        });

        it('ns.router.init should be defined', function() {
            expect(ns.router.init).to.be.a('function');
        });

        it('ns.router.regexps should be defined', function() {
            expect(ns.router.regexps).to.be.an('object');
        });
    });

    describe('routes', function() {

        beforeEach(function() {
            ns.router.routes = {
                redirect: {
                    '/': '/inbox',
                    '/inbox/old/{int:int}': '/inbox',
                    '/inbox/my': function() {
                        return '/inbox';
                    },
                    '/inbox/my/{int:int}': function() {
                        return '/inbox';
                    }
                },
                route: {
                    '/inbox': 'messages',
                    '/message/{mid:int}': 'message',
                    '/page/prefix{page:int}': 'url-with-prefix',
                    '/search/{request:any}': 'search'

                }
            };

            ns.router.regexps['any'] = '.+?';

            ns.router.init();
        });

        afterEach(function() {
            delete ns.router.regexps['any'];
        });

        var test_route = function(url, params, test_name) {
            test_name = test_name || (url + ' -> ' + params.page);
            it(test_name, function() {
                expect(ns.router(url)).to.be.eql(params);
            });
        };

        test_route('', {page: ns.R.REDIRECT, params: {}, redirect: '/inbox'});
        test_route('/', {page: ns.R.REDIRECT, params: {}, redirect: '/inbox'});
        test_route('/inbox/old/123', {page: ns.R.REDIRECT, params: {}, redirect: '/inbox'});
        test_route('/inbox/my', {page: ns.R.REDIRECT, params: {}, redirect: '/inbox'});
        test_route('/inbox/my/123', {page: ns.R.REDIRECT, params: {}, redirect: '/inbox'});
        test_route('/?foo=bar', {page: ns.R.REDIRECT, params: {}, redirect: '/inbox'});
        test_route('/inbox', {page: 'messages', params: {}});
        test_route('/inbox/', {page: 'messages', params: {}});

        test_route('/message', {page: ns.R.NOT_FOUND, params: {}});
        test_route('/message/', {page: ns.R.NOT_FOUND, params: {}});

        test_route('/message/12345', {page: 'message', params: {mid: '12345'}});
        test_route('/message/12345/', {page: 'message', params: {mid: '12345'}});

        test_route('/page/prefix1/', {page: 'url-with-prefix', params: {page: '1'}});

        test_route('/search/request/', {page: 'search', params: {request: 'request'}});
        test_route('/search/' + encodeURIComponent('/') + '/', {page: 'search', params: {request: '/'}});
        // test for invalid urlencode
        test_route('/search/' + encodeURIComponent('/') + '%F/', {page: 'search', params: {request: undefined}});
    });

    describe('default value', function() {

        beforeEach(function() {
            ns.router.regexps[ 'page' ] = 'folder|home';
            ns.router.routes = {
                route: {<commit_msg>test for params in redirect<commit_after>describe('ns.router', function() {

    describe('API', function() {

        it('should be defined', function() {
            expect(ns.router).to.be.a('function');
        });

        it('ns.router.init should be defined', function() {
            expect(ns.router.init).to.be.a('function');
        });

        it('ns.router.regexps should be defined', function() {
            expect(ns.router.regexps).to.be.an('object');
        });
    });

    describe('routes', function() {

        beforeEach(function() {
            ns.router.routes = {
                redirect: {
                    '/': '/inbox',
                    '/inbox/old/{int:int}': '/inbox',
                    '/inbox/my': function() {
                        return '/inbox';
                    },
                    '/inbox/my/{int:int}': function(params) {
                        return '/inbox/' + params.int;
                    }
                },
                route: {
                    '/inbox': 'messages',
                    '/message/{mid:int}': 'message',
                    '/page/prefix{page:int}': 'url-with-prefix',
                    '/search/{request:any}': 'search'

                }
            };

            ns.router.regexps['any'] = '.+?';

            ns.router.init();
        });

        afterEach(function() {
            delete ns.router.regexps['any'];
        });

        var test_route = function(url, params, test_name) {
            test_name = test_name || (url + ' -> ' + params.page);
            it(test_name, function() {
                expect(ns.router(url)).to.be.eql(params);
            });
        };

        test_route('', {page: ns.R.REDIRECT, params: {}, redirect: '/inbox'});
        test_route('/', {page: ns.R.REDIRECT, params: {}, redirect: '/inbox'});
        test_route('/inbox/old/123', {page: ns.R.REDIRECT, params: {}, redirect: '/inbox'});
        test_route('/inbox/my', {page: ns.R.REDIRECT, params: {}, redirect: '/inbox'});
        test_route('/inbox/my/123', {page: ns.R.REDIRECT, params: {}, redirect: '/inbox/123'});
        test_route('/?foo=bar', {page: ns.R.REDIRECT, params: {}, redirect: '/inbox'});
        test_route('/inbox', {page: 'messages', params: {}});
        test_route('/inbox/', {page: 'messages', params: {}});

        test_route('/message', {page: ns.R.NOT_FOUND, params: {}});
        test_route('/message/', {page: ns.R.NOT_FOUND, params: {}});

        test_route('/message/12345', {page: 'message', params: {mid: '12345'}});
        test_route('/message/12345/', {page: 'message', params: {mid: '12345'}});

        test_route('/page/prefix1/', {page: 'url-with-prefix', params: {page: '1'}});

        test_route('/search/request/', {page: 'search', params: {request: 'request'}});
        test_route('/search/' + encodeURIComponent('/') + '/', {page: 'search', params: {request: '/'}});
        // test for invalid urlencode
        test_route('/search/' + encodeURIComponent('/') + '%F/', {page: 'search', params: {request: undefined}});
    });

    describe('default value', function() {

        beforeEach(function() {
            ns.router.regexps[ 'page' ] = 'folder|home';
            ns.router.routes = {
                route: {
{'fraction_non_alphanumeric': 0.20320197044334976, 'fraction_numerical': 0.009082512315270935, 'mean_word_length': 1.862114537444934, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '734343', 'n_tokens_mistral': 2018, 'n_tokens_neox': 1925, 'n_words': 337}