<commit_before><?php

final class PHPASTParserTestCase extends PhutilTestCase {

  public function testParser() {
    if (!xhpast_is_available()) {
      $this->assertSkipped(pht('xhpast is not built or not up to date.'));
    }

    $dir = dirname(__FILE__).'/data/';
    foreach (Filesystem::listDirectory($dir) as $file) {
      if (preg_match('/\.test$/', $file)) {
        $this->executeParserTest($file, Filesystem::readFile($dir.$file));
      }
    }
  }

  private function executeParserTest($name, $data) {
    $data = explode("\n", $data, 2);
    if (count($data) !== 2) {
      throw new Exception(
        pht('Expected multiple lines in parser test file "%s".', $name));
    }
<commit_msg>Attempt to build XHPAST during unit tests<commit_after><?php

final class PHPASTParserTestCase extends PhutilTestCase {

  public function testParser() {
    if (!PhutilXHPASTBinary::isAvailable()) {
      try {
        PhutilXHPASTBinary::build();
      } catch (Exception $ex) {
        $this->assertSkipped(pht('xhpast is not built or not up to date.'));
      }
    }

    $dir = dirname(__FILE__).'/data/';
    foreach (Filesystem::listDirectory($dir) as $file) {
      if (preg_match('/\.test$/', $file)) {
        $this->executeParserTest($file, Filesystem::readFile($dir.$file));
      }
    }
  }

  private function executeParserTest($name, $data) {
    $data = explode("\n", $data, 2);
    if (count($data) !== 2) {
      throw new Exception(
        pht('Expected multiple lines in parser test file "%s".', $name));
    }

{'fraction_non_alphanumeric': 0.16265452179570591, 'fraction_numerical': 0.002602472348731295, 'mean_word_length': 3.1344086021505375, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '6340794', 'n_tokens_mistral': 499, 'n_tokens_neox': 487, 'n_words': 119}