<commit_before><?php
/* This class is part of the XP framework
 *
 * $Id$
 */
 
  uses('net.xp_framework.tools.vm.unittest.emit.php5.AbstractEmitterTest');

  /**
   * Tests PHP5 emitter
   *
   * @see      xp://net.xp_framework.tools.vm.unittest.emit.php5.MethodEmitterTest
   * @purpose  Unit Test
   */
  class MethodOverloadingEmitterTest extends AbstractEmitterTest {

    /**
     * Tests overloading the constructor
     *
     * @access  public
     */
    #[@test]
    function overloadedMethod() {
      $this->assertSourcecodeEquals(
        preg_replace('/\n\s*/', '', 'class Date extends xplangObject{
          protected $stamp;

          public function isBeforestring($value){
            return $this->stamp<strtotime($value); 
          }

          public function isBeforeDate($value){
            return $this->stamp<$value->stamp; 
          }

          public static function main(){
            $d= new Date(); 
            var_dump($d->isBeforeDate(new Date(1))); 
            var_dump($d->isBeforestring(\'1977-12-14\')); 
          }
        };'),
        $this->emit('class Date {
          protected int $stamp= 0;
          
          [@overloaded] public bool isBefore(string $value) {
            return $this->stamp < strtotime($value);
          }

          [@overloaded] public bool isBefore(Date $value) {
            return $this->stamp < $value->stamp;
          }

          public static void main() {
            $d= new Date();
            var_dump($d->isBefore(new Date(1)));
            var_dump($d->isBefore("1977-12-14"));
          }
        }')
      );
    }

    /**
     * Tests overloading the constructor
     *
     * @access  public
     */
    #[@test]
    function overloadedConstructor() {
      $this->assertSourcecodeEquals(
        preg_replace('/\n\s*/', '', 'class Date extends xplangObject{
          protected $stamp;

          public function __constructstring($in){
            $this->stamp= strtotime($in); 
          }

          public function __constructinteger($in){
            $this->stamp= $in; 
          }

          public static function main(){
            xp::spawn(\'Date\', \'__constructinteger\', array(1)); 
            xp::spawn(\'Date\', \'__constructstring\', array(\'1977-12-14\')); 
          }
        };'),
        $this->emit('class Date {
          protected int $stamp= 0;

          [@overloaded] public __construct(string $in) {
            $this->stamp= strtotime($in);
          }

          [@overloaded] public __construct(integer $in) {
            $this->stamp= $in;
          }
          
          public static void main() {
            new Date(1);
            new Date("1977-12-14");
          }
        }')
      );
    }
  }
?><commit_msg>- Fix type name (integer vs. int)<commit_after><?php
/* This class is part of the XP framework
 *
 * $Id$
 */
 
  uses('net.xp_framework.tools.vm.unittest.emit.php5.AbstractEmitterTest');

  /**
   * Tests PHP5 emitter
   *
   * @see      xp://net.xp_framework.tools.vm.unittest.emit.php5.MethodEmitterTest
   * @purpose  Unit Test
   */
  class MethodOverloadingEmitterTest extends AbstractEmitterTest {

    /**
     * Tests overloading the constructor
     *
     * @access  public
     */
    #[@test]
    function overloadedMethod() {
      $this->assertSourcecodeEquals(
        preg_replace('/\n\s*/', '', 'class Date extends xplangObject{
          protected $stamp;

          public function isBeforestring($value){
            return $this->stamp<strtotime($value); 
          }

          public function isBeforeDate($value){
            return $this->stamp<$value->stamp; 
          }

          public static function main(){
            $d= new Date(); 
            var_dump($d->isBeforeDate(new Date(1))); 
            var_dump($d->isBeforestring(\'1977-12-14\')); 
          }
        };'),
        $this->emit('class Date {
          protected integer $stamp= 0;
          
          [@overloaded] public bool isBefore(string $value) {
            return $this->stamp < strtotime($value);
          }

          [@overloaded] public bool isBefore(Date $value) {
            return $this->stamp < $value->stamp;
          }

          public static void main() {
            $d= new Date();
            var_dump($d->isBefore(new Date(1)));
            var_dump($d->isBefore("1977-12-14"));
          }
        }')
      );
    }

    /**
     * Tests overloading the constructor
     *
     * @access  public
     */
    #[@test]
    function overloadedConstructor() {
      $this->assertSourcecodeEquals(
        preg_replace('/\n\s*/', '', 'class Date extends xplangObject{
          protected $stamp;

          public function __constructstring($in){
            $this->stamp= strtotime($in); 
          }

          public function __constructinteger($in){
            $this->stamp= $in; 
          }

          public static function main(){
            xp::spawn(\'Date\', \'__constructinteger\', array(1)); 
            xp::spawn(\'Date\', \'__constructstring\', array(\'1977-12-14\')); 
          }
        };'),
        $this->emit('class Date {
          protected integer $stamp= 0;

          [@overloaded] public __construct(string $in) {
            $this->stamp= strtotime($in);
          }

          [@overloaded] public __construct(integer $in) {
            $this->stamp= $in;
          }
          
          public static void main() {
            new Date(1);
            new Date("1977-12-14");
          }
        }')
      );
    }
  }
?>
{'fraction_non_alphanumeric': 0.14378612716763006, 'fraction_numerical': 0.014812138728323699, 'mean_word_length': 1.7102300538423887, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 41, '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': '686067', 'n_tokens_mistral': 1688, 'n_tokens_neox': 1583, 'n_words': 316}