<commit_before>import test from 'ava';
import errors from '../errors.json';
import * as chromiumNetErrors from '../build';

test('create new error', (t) => {
  errors.forEach((error) => {
    const ChromiumError = chromiumNetErrors[error.name];
    const thrower = () => { throw new ChromiumError(); };

    t.throws(() => thrower(), ChromiumError);
  });
});

test('create error by code', (t) => {
  const thrower = () => { throw chromiumNetErrors.createByCode(-324); };

  t.throws(() => thrower(), chromiumNetErrors.EmptyResponseError);
});

test('error type', (t) => {
  errors.forEach((error) => {
    const ChromiumError = chromiumNetErrors[error.name];
    const err = new ChromiumError();
    t.log(err.name, err.type, error.name, error.type);

    t.is(err.type, error.type);
    t.is(err.isSystemError(), error.type === 'system');
    t.is(err.isConnectionError(), error.type === 'connection');
    t.is(err.isCertificateError(), error.type === 'certificate');
    t.is(err.isHttpError(), error.type === 'http');
    t.is(err.isCacheError(), error.type === 'cache');
    t.is(err.isUnknownError(), error.type === 'unknown');
    t.is(err.isFtpError(), error.type === 'ftp');
    t.is(err.isCertificateManagerError(), error.type === 'certificate-manager');
    t.is(err.isDnsError(), error.type === 'dns');
  });
});
<commit_msg>Add more tests<commit_after>import test from 'ava';
import errors from '../errors.json';
import * as chromiumNetErrors from '../build';

test('create new error', (t) => {
  errors.forEach((error) => {
    const ChromiumError = chromiumNetErrors[error.name];
    const thrower = () => { throw new ChromiumError(); };
    t.throws(() => thrower(), ChromiumError);
  });
});

test('create error by code', (t) => {
  errors.forEach((error) => {
    const thrower = () => { throw chromiumNetErrors.createByCode(error.code); };
    t.throws(() => thrower(), chromiumNetErrors[error.name]);
  });
});

test('error type', (t) => {
  errors.forEach((error) => {
    const ChromiumError = chromiumNetErrors[error.name];
    const err = new ChromiumError();
    t.log(err.name, err.type, error.name, error.type);

    t.is(err.code, error.code);
    t.is(err.type, error.type);
    t.is(err.message, error.message);

    t.is(err.isSystemError(), error.type === 'system');
    t.is(err.isConnectionError(), error.type === 'connection');
    t.is(err.isCertificateError(), error.type === 'certificate');
    t.is(err.isHttpError(), error.type === 'http');
    t.is(err.isCacheError(), error.type === 'cache');
    t.is(err.isUnknownError(), error.type === 'unknown');
    t.is(err.isFtpError(), error.type === 'ftp');
    t.is(err.isCertificateManagerError(), error.type === 'certificate-manager');
    t.is(err.isDnsError(), error.type === 'dns');
  });
});

test('getErrors', (t) => {
  t.is(chromiumNetErrors.getErrors().length, errors.length);
});

test('unknown error', (t) => {
  const thrower = () => { throw chromiumNetErrors.createByCode(9999); };
  t.throws(() => thrower(), chromiumNetErrors.UnknownError);
});
{'fraction_non_alphanumeric': 0.212668198227765, 'fraction_numerical': 0.002297341647522153, 'mean_word_length': 4.157360406091371, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 26, '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': '7077255', 'n_tokens_mistral': 1026, 'n_tokens_neox': 990, 'n_words': 191}