<commit_before><?php namespace xp\unittest\sources;

use io\Folder;
use io\collections\FileCollection;
use io\collections\iterate\FilteredIOCollectionIterator;
use io\collections\iterate\ExtensionEqualsFilter;
use lang\IllegalArgumentException;
use lang\XPClass;
use lang\reflect\Modifiers;

/**
 * Source that loads tests from test case classes inside a folder and
 * its subfolders.
 */
class FolderSource extends AbstractSource {
  protected $folder= null;
  
  /**
   * Constructor
   *
   * @param   io.Folder folder
   * @throws  lang.IllegalArgumentException if the given folder does not exist
   */
  public function __construct(Folder $folder) {
    if (!$folder->exists()) {
      throw new IllegalArgumentException('Folder "'.$folder->getURI().'" does not exist!');
    }
    $this->folder= $folder;
  }

  /**
   * Find first classloader responsible for a given path
   *
   * @param   string path
   * @return  lang.IClassLoader
   */
  protected function findLoaderFor($path) {
    foreach (\lang\ClassLoader::getLoaders() as $cl) {
      if (0 === strncmp($cl->path, $path, strlen($cl->path))) return $cl;
    }
    return null;      
  }

  /**
   * Get all test cases
   *
   * @param   var[] arguments
   * @return  unittest.TestCase[]
   */
  public function testCasesWith($arguments) {
    if (null === ($cl= $this->findLoaderFor($this->folder->getURI()))) {
      throw new IllegalArgumentException($this->folder->toString().' is not in class path');
    }
    $l= strlen($cl->path);
    $e= -strlen(\xp::CLASS_FILE_EXT);

    $it= new FilteredIOCollectionIterator(
      new FileCollection($this->folder),
      new ExtensionEqualsFilter(\xp::CLASS_FILE_EXT),
      true  // recursive
    );
    $cases= [];
    foreach ($it as $element) {<commit_msg>Only check lang.FileSystemClassLoader instances for classes in folder<commit_after><?php namespace xp\unittest\sources;

use io\Folder;
use io\collections\FileCollection;
use io\collections\iterate\FilteredIOCollectionIterator;
use io\collections\iterate\ExtensionEqualsFilter;
use lang\IllegalArgumentException;
use lang\XPClass;
use lang\reflect\Modifiers;

/**
 * Source that loads tests from test case classes inside a folder and
 * its subfolders.
 */
class FolderSource extends AbstractSource {
  protected $folder= null;
  
  /**
   * Constructor
   *
   * @param   io.Folder folder
   * @throws  lang.IllegalArgumentException if the given folder does not exist
   */
  public function __construct(Folder $folder) {
    if (!$folder->exists()) {
      throw new IllegalArgumentException('Folder "'.$folder->getURI().'" does not exist!');
    }
    $this->folder= $folder;
  }

  /**
   * Find first classloader responsible for a given path
   *
   * @param   string path
   * @return  lang.IClassLoader
   */
  protected function findLoaderFor($path) {
    foreach (\lang\ClassLoader::getLoaders() as $cl) {
      if (
        $cl instanceof \lang\FileSystemClassLoader &&
        0 === strncmp($cl->path, $path, strlen($cl->path))
      ) return $cl;
    }
    return null;      
  }

  /**
   * Get all test cases
   *
   * @param   var[] arguments
   * @return  unittest.TestCase[]
   */
  public function testCasesWith($arguments) {
    if (null === ($cl= $this->findLoaderFor($this->folder->getURI()))) {
      throw new IllegalArgumentException($this->folder->toString().' is not in class path');
    }
    $l= strlen($cl->path);
    $e= -strlen(\xp::CLASS_FILE_EXT);

    $it= new FilteredIOCollectionIterator(
      new FileCollection($this->folder),
      new ExtensionEqualsFilter(\xp::CLASS_FILE_EXT),
      true  // recursive
    );
    $cases= [];
    foreach ($it as $element) {
{'fraction_non_alphanumeric': 0.13344226579520696, 'fraction_numerical': 0.0005446623093681918, 'mean_word_length': 3.295906432748538, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 27, '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': '6716736', 'n_tokens_mistral': 1099, 'n_tokens_neox': 1088, 'n_words': 284}