<commit_before>describe('Testing FakeUriParser factory', function() {
  var parsers = {},
      FakeUriParser,
      paramRegExpString = '([a-z0-9\\-\\_]+)',
      queryRegExpString = '(\\?.*)?';

  beforeEach(module('fake'));

  beforeEach(inject(function(_FakeUriParser_) {
    FakeUriParser = _FakeUriParser_;
    parsers['libraries'] = new FakeUriParser('/libraries');
    parsers['library'] = new FakeUriParser('/libraries/{libraryId}');
    parsers['books'] = new FakeUriParser('/libraries/{libraryId}/books');
    parsers['book'] = new FakeUriParser('/libraries/{libraryId}/books/{bookId}');
  }));


  it('Should extract path param names/keys', function() {
    expect(parsers.library.params).toEqual(['libraryId']);
    expect(parsers.books.params).toEqual(['libraryId']);
    expect(parsers.book.params).toEqual(['libraryId', 'bookId']);
  });

  it('Should created a pattern', function() {
    var libraryRegExp = new RegExp(
          '^\\/libraries\\/' + paramRegExpString + queryRegExpString + '$'),

        booksRegExp = new RegExp(
          '^\\/libraries\\/' + paramRegExpString +
          '\\/books' + queryRegExpString + '$'),

        bookRegExp = new RegExp(
          '^\\/libraries\\/' + paramRegExpString +
          '\\/books\\/' + paramRegExpString + queryRegExpString + '$');

    expect(parsers.library.pattern).toEqual(libraryRegExp);
    expect(parsers.books.pattern).toEqual(booksRegExp);
    expect(parsers.book.pattern).toEqual(bookRegExp);
  });

  it('Should get path params after parsing URI', function() {
    var tests = [
      { parser: 'libraries', url: '/', expected: {} },
      { parser: 'libraries', url: '/libraries', expected: {} },
      { parser: 'library', url: '/libraries/1', expected: { libraryId: '1' } },
      { parser: 'books', url: '/libraries/1/books', expected: { libraryId: '1' } },
      { parser: 'book', url: '/libraries/1/books/2?test=query', expected: { libraryId: '1', bookId: '2' } }
    ];

    tests.forEach(function(test) {
      expect(parsers[test.parser].getPathParams(test.url)).toEqual(test.expected);
    });
  });

  it('Should get query params after parsing URI', function() {
    var tests = [
      { parser: 'library', url: '/libraries/1?', expected: {} },
      { parser: 'library', url: '/libraries/1?&', expected: {} },
      { parser: 'library', url: '/libraries/1?test', expected: { test: '' } },
      { parser: 'library', url: '/libraries/1?test&', expected: { test: '' } },
      { parser: 'library', url: '/libraries/1?field=name', expected: { field: 'name' } },

      { parser: 'book', url: '/libraries/1/books/2', expected: {} },
      { parser: 'books', url: '/libraries/1/books?author=John%20Doe', expected: { author: '<NAME>' } },
      { parser: 'book', url: '/libraries/1/books/2?author=John%20Doe&year=2010', expected: {
        author: '<NAME>',
        year: '2010' } }
    ];

    tests.forEach(function(test) {
      expect(parsers[test.parser].getQueryParams(test.url)).toEqual(test.expected);
    });

  });

  it('Should get both, path and query params after parsing URI', function() {
    var tests = [
      { parser: 'book', url: '/libraries/1/books/2?author=John%20Doe&year=2010',
        expected: {
          path: { libraryId: '1', bookId: '2' },
          query: { author: '<NAME>', year: '2010' }
        }
      },
      { parser: 'libraries', url: '/libraries?x&y&z',
        expected: {
          path: {},
          query: { x: '', y: '', z: '' }
        }
      }
    ];

    tests.forEach(function(test) {
      expect(parsers[test.parser].parse(test.url)).toEqual(test.expected);
    })
  });
});<commit_msg>Update FakeUriParser factory tests<commit_after>describe('Testing FakeUriParser factory', function() {
  var parsers = {},
      FakeUriParser,
      paramRegExpString = '([a-z0-9\\-\\_]+)',
      queryRegExpString = '(\\?.*)?';

  beforeEach(function() {
    angular
    .module('test', ['fake'])
    .config(['FakeConfigProvider', function(FakeConfig) {
      FakeConfig.path('root', 'http://api.example.com:8080/v1');
    }]);
    module('test');
  });

  beforeEach(inject(function(_FakeUriParser_) {
    FakeUriParser = _FakeUriParser_;

    parsers['libraries'] = new FakeUriParser('/libraries');
    parsers['library'] = new FakeUriParser('/libraries/{libraryId}');
    parsers['books'] = new FakeUriParser('/libraries/{libraryId}/books');
    parsers['book'] = new FakeUriParser('/libraries/{libraryId}/books/{bookId}');
    parsers['user'] = new FakeUriParser('$root/users/{uid}');

    // @TODO: Test some invalid parsers like '/users/{}/profiles'
  }));

  it('Should extract path param names/keys', function() {
    var tests = [
      { parser: 'library', params: ['libraryId'] },
      { parser: 'books', params: ['libraryId'] },
      { parser: 'book', params: ['libraryId', 'bookId'] }
    ];

    tests.forEach(function(test) {
      expect(parsers[test.parser].params).toEqual(test.params);
    });
  });

  it('Should match URLs', function() {
    var tests = [
      { parser: 'libraries', url: '/libraries' },
      { parser: 'libraries', url: '/libraries?city=London' },
      { parser: 'library', url: '/libraries/1' },
      { parser: 'library', url: '/libraries/1?fields=name&' },
      { parser: 'books', url: '/libraries/1/books?author=John%20Doe' },
      { parser: 'user', url: 'http://api.example.com:8080/v1/users/1' }
    ];

    tests.forEach(function(test) {
      expect(parsers[test.parser].pattern.test(test.url)).toBe(true);
    });
  });

  it('Should NOT match URLs', function() {
    var tests = [
      { parser: 'libraries', url: '/libraries/1' },
      { parser: 'books', url: '/libraries/1/books/2?author=John%20Doe' },
      { parser: 'user', url: 'http://api.example.com:8080/v1/users' },
      { parser: 'user', url: 'http://api.example.com:9000/v1/users/1' }
    ];

    tests.forEach(function(test) {
      expect(parsers[test.parser].pattern.test(test.url)).toBe(false);
    });
  });

  it('Should get path params after parsing URI', function() {
    var tests = [
      { parser: 'libraries', url: '/', expected: {} },
      { parser: 'libraries', url: '/libraries', expected: {} },
      { parser: 'library', url: '/libraries/1', expected: { libraryId: '1' } },
      { parser: 'books', url: '/libraries/1/books', expected: { libraryId: '1' } },
      { parser: 'book', url: '/libraries/1/books/2?test=query', expected: { libraryId: '1', bookId: '2' } },
      { parser: 'user', url: 'http://api.example.com:8080/v1/users/1', expected: { uid: '1' } },
    ];

    tests.forEach(function(test) {
      expect(parsers[test.parser].getPathParams(test.url)).toEqual(test.expected);
    });
  });

  it('Should get query params after parsing URI', function() {
    var tests = [
      { parser: 'library', url: '/libraries/1?', expected: {} },
      { parser: 'library', url: '/libraries/1?&', expected: {} },
      { parser: 'library', url: '/libraries/1?test', expected: { test: '' } },
      { parser: 'library', url: '/libraries/1?test&', expected: { test: '' } },
      { parser: 'library', url: '/libraries/1?field=name', expected: { field: 'name' } },

      { parser: 'book', url: '/libraries/1/books/2', expected: {} },
      { parser: 'books', url: '/libraries/1/books?author=John%20Doe', expected: { author: '<NAME>' } },
      { parser: 'book', url: '/libraries/1/books/2?author=John%20Doe&year=2010', expected: {
        author: '<NAME>',
        year: '2010' } }
    ];

    tests.forEach(function(test) {
      expect(parsers[test.parser].getQueryParams(test.url)).toEqual(test.expected);
    });

  });

  it('Should get both, path and query params after parsing URI', function() {
    var tests = [
      { parser: 'book', url: '/libraries/1/books/2?author=John%20Doe&year=2010',
        expected: {
          path: { libraryId: '1', bookId: '2' },
          query: { author: '<NAME>', year: '2010' }
        }
      },
      { parser: 'libraries', url: '/libraries?x&y&z',
        expected: {
          path: {},
          query: { x: '', y: '', z: '' }
        }
      }
    ];

    tests.forEach(function(test) {
      expect(parsers[test.parser].parse(test.url)).toEqual(test.expected);
    })
  });
});
{'fraction_non_alphanumeric': 0.20738394053856463, 'fraction_numerical': 0.015961983672474717, 'mean_word_length': 3.0856147336983573, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '4429393', 'n_tokens_mistral': 2766, 'n_tokens_neox': 2674, 'n_words': 492}