<commit_before>export type SatisfyExpected<T> = {
  [P in keyof T]: Partial<SatisfyExpected<T[P]>> | RegExp | Function
}

export function satisfy<
  Actual,
  Expected extends Partial<SatisfyExpected<Actual>>>(actual: Actual, expected: Expected) {
  satisfyInternal(actual, expected, '')
}
export class FailedPredicate extends Error {
  constructor(path: string) {
    super(`Property ${path ? path : 'actual'} fails predicate`)
    Object.setPrototypeOf(this, new.target.prototype)
  }
}
export class NotMatch extends Error {
  constructor(actual, expected, path) {
    super(`Expect ${path ? path : 'actual'} to be ${typeof expected === 'string' ? `'${expected}'` : expected}, but received ${typeof actual === 'string' ? `'${actual}'` : actual}`)
    Object.setPrototypeOf(this, new.target.prototype)
  }
}
export class MissingProperty extends Error {
  constructor(path: string) {
    super(`Missing property ${path}`)
    Object.setPrototypeOf(this, new.target.prototype)
  }
}
function satisfyInternal(actual, expected, path: string) {
  if (expected instanceof RegExp && typeof actual === 'string')
    expected.test(actual)
  else if (expected instanceof Function) {
    if (!expected(actual))
      throw new FailedPredicate(path)
  }
  // tslint:disable-next-line
  else if (typeof actual !== typeof expected)<commit_msg>feat: add satisfy()<commit_after>export type SatisfyExpected<T> = {
  [P in keyof T]: Partial<SatisfyExpected<T[P]>> | RegExp | Function
}

export function satisfy<
  Actual,
  Expected extends Partial<SatisfyExpected<Actual>>>(actual: Actual, expected: Expected) {
  satisfyInternal(actual, expected, '')
}
export class FailedPredicate extends Error {
  constructor(path: string) {
    super(`Property ${path} fails predicate`)
    Object.setPrototypeOf(this, new.target.prototype)
  }
}
export class NotMatch extends Error {
  constructor(actual, expected, path) {
    super(`Expect ${path ? path : 'actual'} to be ${typeof expected === 'string' ? `'${expected}'` : expected}, but received ${typeof actual === 'string' ? `'${actual}'` : actual}`)
    Object.setPrototypeOf(this, new.target.prototype)
  }
}
export class MissingProperty extends Error {
  constructor(path: string) {
    super(`Missing property ${path}`)
    Object.setPrototypeOf(this, new.target.prototype)
  }
}
function satisfyInternal(actual, expected, path: string) {
  if (expected instanceof RegExp && typeof actual === 'string')
    expected.test(actual)
  else if (expected instanceof Function) {
    if (!expected(actual))
      throw new FailedPredicate(path)
  }
  // tslint:disable-next-line
  else if (typeof actual !== typeof expected)
{'fraction_non_alphanumeric': 0.13708459214501512, 'fraction_numerical': 0.0, 'mean_word_length': 4.873614190687362, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, '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': '4389875', 'n_tokens_mistral': 774, 'n_tokens_neox': 772, 'n_words': 213}