<commit_before>var test = require('tape'),
    Byway = require('../');

test('matches simple :names', function(t) {
    var config = [{"pattern": "/mojits/:mojitname/:controller.:affinity.js"}],
        byway = new Byway(config);

    t.ok(byway.of('abc/mojits/foo/foo.server.js'));
    t.ok(byway.of('/abc/def/mojits/foo/foo.server.js'));
    t.ok(byway.of('/mojits/foo/foo.server.js'));
    t.ok(byway.of('/mojits/_/ghi.jkl.js'));
    t.end();
});

test('match •name route (i.e. want a name to capture .+? not just \\w)', function(t) {
    var config = [{"pattern": "/archetype/•subpath/package.json"}],
        byway = new Byway(config);

    t.ok(byway.of('/archetype/a/b/c/package.json'));
    //                        ^^^^^ gets matched by name "•subpath"
    //                              returned object has parts.subpath:"a/b/c"

    t.ok(byway.of('/archetype/abc%20def+123///package.json'));
    //                        ^^^^^^^^^^^^^^^ gets matched by name "•subpath"
    //                                        parts.subpath: "abc%20def+123//"

    t.end();
});

test('matches :names numbers and underscores', function(t) {
    var config = [{"pattern": "/mojits/:abc_123/:12_34.:affinity.js"}],
        byway = new Byway(config);

    t.ok(byway.of('abc/mojits/foo/foo.server.js'));
    t.ok(byway.of('/abc/def/mojits/foo/foo.server.js'));
    t.ok(byway.of('/mojits/foo/foo.server.js'));
    t.ok(byway.of('/mojits/_/ghi.jkl.js'));
    t.end();
});

test('special regex characters in name patterns are allowed', function(t) {
    var config = [{"pattern": "/{m+*.}[(o/)]jits/:abc/:def.:affinity.js"}],
        byway = new Byway(config);

    t.ok(byway.of('abc/{m+*.}[(o/)]jits/foo/foo.server.js'));
    t.end();
});

test('unmatched :routes', function(t) {
    var config = [
            {"pattern": "/modules/:modname/:filename.json"},
            {"pattern": "/mojits/:mojitname/:controller.:affinity.js"}
        ];

    byway = new Byway(config);

    t.notok(byway.of('modules/mymod/config.json')); // missing ^/
    t.notok(byway.of('/mojits//ghi.jkl'));
    t.notok(byway.of('/abc/def/ghi'));
    t.end();
});

test('match /modules/:modname/:filename.json', function(t) {
    var config = [{"pattern": "/modules/:modname/:filename.json"}]
        byway = new Byway(config);

    t.ok(byway.of('abc/modules/mymod/config.json ohhai!'), 'match not $anchored');
    t.ok(byway.of('/modules/mymod/config.json'), 'match not ^anchored');
    t.ok(byway.of('/abc/def/modules/mymod/config.json'), 'match not ^anchored');
    t.ok(byway.of('/modules/MYMODULE/FOOBAR.json'), 'named params match case-insensitively');
    t.ok(byway.of('abc/moDUles/mymod/config.JSON'), 'all letters match case-insensitively');
    t.end();
});

test('match anchored$ /modules/:modname/:filename.json$', function(t) {
    var config = [{"pattern": "/modules/:modname/:filename.json$"}]
        byway = new Byway(config);

    t.ok(byway.of('/modules/mymod/config.json'), 'match not ^anchored');
    t.ok(byway.of('/abc/def/modules/mymod/config.json'), 'match not ^anchored');
    t.ok(byway.of('/modules/MYMODULE/FOOBAR.json'), 'named params match case-insensitively');
    t.ok(byway.of('abc/moDUles/mymod/config.JSON'), 'all letters match case-insensitively');
    t.notok(byway.of('abc/modules/mymod/config.json ohhai!'), 'match is $anchored');
    t.end();
});

test('match ^anchored ^/modules/:modname/:filename.json', function(t) {
    var config = [{"pattern": "^/modules/:modname/:filename.json"}]
        byway = new Byway(config);

    t.ok(byway.of('/modules/mymod/config.json ohhai!'), '^ but not $');
    t.ok(byway.of('/modules/mymod/config.json'), '^');
    t.ok(byway.of('/modules/MYMODULE/FOOBAR.json'), 'named params match case-insensitively');
    t.notok(byway.of('/abc/def/modules/mymod/config.json'), 'match not ^anchored');
    t.notok(byway.of('abc/moDUles/mymod/config.JSON'), 'all letters match case-insensitively');
    t.end();
});

test('match ^anchored$ ^/modules/:modname/:filename.json$', function(t) {
    var config = [{"pattern": "^/modules/:modname/:filename.json$"}]
        byway = new Byway(config);

    t.ok(byway.of('/modules/mymod/config.json'));
    t.notok(byway.of('abc/modules/mymod/config.json'));
    t.notok(byway.of('/modules/mymod/config.json/cheezits'));
    t.end();
});
<commit_msg>lint, +test<commit_after>var test = require('tape'),
    Byway = require('../');

test('matches simple :names', function(t) {
    var config = [{"pattern": "/mojits/:mojitname/:controller.:affinity.js"}],
        byway = new Byway(config);

    t.ok(byway.of('abc/mojits/foo/foo.server.js'));
    t.ok(byway.of('/abc/def/mojits/foo/foo.server.js'));
    t.ok(byway.of('/mojits/foo/foo.server.js'));
    t.ok(byway.of('/mojits/_/ghi.jkl.js'));
    t.end();
});

test('match •name route (i.e. want a name to capture .+? not just \\w)', function(t) {
    var config = [{"pattern": "/archetype/•subpath/package.json"}],
        byway = new Byway(config);

    t.ok(byway.of('/archetype/a/b/c/package.json'));
    //                        ^^^^^ gets matched by name "•subpath"
    //                              returned object has parts.subpath:"a/b/c"

    t.ok(byway.of('/archetype/abc%20def+123///package.json'));
    //                        ^^^^^^^^^^^^^^^ gets matched by name "•subpath"
    //                                        parts.subpath: "abc%20def+123//"

    t.end();
});

test('matches :names numbers and underscores', function(t) {
    var config = [{"pattern": "/mojits/:abc_123/:12_34.:affinity.js"}],
        byway = new Byway(config);

    t.ok(byway.of('abc/mojits/foo/foo.server.js'));
    t.ok(byway.of('/abc/def/mojits/foo/foo.server.js'));
    t.ok(byway.of('/mojits/foo/foo.server.js'));
    t.ok(byway.of('/mojits/_/ghi.jkl.js'));
    t.end();
});

test('special regex characters in name patterns are allowed', function(t) {
    var config = [{"pattern": "/{m+*.}[(o/)]jits/:abc/:def.:affinity.js"}],
        byway = new Byway(config);

    t.ok(byway.of('abc/{m+*.}[(o/)]jits/foo/foo.server.js'));
    t.end();
});

test('unmatched :routes', function(t) {
    var config = [
            {"pattern": "/modules/:modname/:filename.json"},
            {"pattern": "/mojits/:mojitname/:controller.:affinity.js"}
        ],
        byway = new Byway(config);

    t.notok(byway.of('modules/mymod/config.json')); // missing ^/
    t.notok(byway.of('/mojits//ghi.jkl'));
    t.notok(byway.of('/abc/def/ghi'));
    t.end();
});

test('match /modules/:modname/:filename.json', function(t) {
    var config = [{"pattern": "/modules/:modname/:filename.json"}],
        byway = new Byway(config);

    t.ok(byway.of('abc/modules/mymod/config.json ohhai!'), 'match not $anchored');
    t.ok(byway.of('/modules/mymod/config.json'), 'match not ^anchored');
    t.ok(byway.of('/abc/def/modules/mymod/config.json'), 'match not ^anchored');
    t.ok(byway.of('/modules/MYMODULE/FOOBAR.json'), 'named params match case-insensitively');
    t.ok(byway.of('abc/moDUles/mymod/config.JSON'), 'all letters match case-insensitively');
    t.end();
});

test('match anchored$ /modules/:modname/:filename.json$', function(t) {
    var config = [{"pattern": "/modules/:modname/:filename.json$"}],
        byway = new Byway(config);

    t.ok(byway.of('/modules/mymod/config.json'), 'match not ^anchored');
    t.ok(byway.of('/abc/def/modules/mymod/config.json'), 'match not ^anchored');
    t.ok(byway.of('/modules/MYMODULE/FOOBAR.json'), 'named params match case-insensitively');
    t.ok(byway.of('abc/moDUles/mymod/config.JSON'), 'all letters match case-insensitively');
    t.notok(byway.of('abc/modules/mymod/config.json ohhai!'), 'match is $anchored');
    t.end();
});

test('match ^anchored ^/modules/:modname/:filename.json', function(t) {
    var config = [{"pattern": "^/modules/:modname/:filename.json"}],
        byway = new Byway(config);

    t.ok(byway.of('/modules/mymod/config.json ohhai!'), '^ but not $');
    t.ok(byway.of('/modules/mymod/config.json'), '^');
    t.ok(byway.of('/modules/MYMODULE/FOOBAR.json'), 'named params match case-insensitively');
    t.notok(byway.of('/abc/def/modules/mymod/config.json'), 'match not ^anchored');
    t.notok(byway.of('abc/moDUles/mymod/config.JSON'), 'all letters match case-insensitively');
    t.end();
});

test('match ^anchored$ ^/modules/:modname/:filename.json$', function(t) {
    var config = [{"pattern": "^/modules/:modname/:filename.json$"}],
        byway = new Byway(config);

    t.ok(byway.of('/modules/mymod/config.json'));
    t.notok(byway.of('abc/modules/mymod/config.json'));
    t.notok(byway.of('/modules/mymod/config.json/cheezits'));
    t.end();
});

test('robots are coming', function(t) {
    var config = [
            {"pattern": "^/robots.txt$"},
            {"pattern": "^/cache.manifest$"}
        ],
        byway = new Byway(config);

    t.ok(byway.of('/robots.txt'));
    t.ok(byway.of('/cache.manifest'));
    t.end();
});

{'fraction_non_alphanumeric': 0.22573086364650746, 'fraction_numerical': 0.0037937960276723946, 'mean_word_length': 3.0666969147005445, 'pattern_counts': {'":': 22, '<': 3, '<?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': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4852773', 'n_tokens_mistral': 3356, 'n_tokens_neox': 3331, 'n_words': 473}