<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
   *
   * @purpose  Unit Test
   */
  class TypesEmitterTest extends AbstractEmitterTest {

    /**
     * Tests 
     *
     */
    #[@test]
    public function unassignedVariableCanBecomeAnything() {
      foreach (array('NULL', '1', '1.0', 'array()', '"Hello"', 'new lang.Object();') as $init) {
        $this->emit('$x= '.$init.';');
      }
    }

    /**
     * Tests an untyped argument
     *
     */
    #[@test]
    public function untypedArgument() {
      $this->emit('class Test { public void test($bar) { $bar= 1; } }');
    }

    /**
     * Tests a typed argument
     *
     */
    #[@test, @expect('lang.FormatException')]
    public function typedArgumentMismatch() {
      $this->emit('class Test { public void test(string $bar) { $bar= 1; } }');
    }

    /**
     * Tests an untyped member
     *
     */
    #[@test]
    public function untypedMember() {
      $this->emit('class Test { private $bar; public void test() { $this->bar= 1; } }');
    }

    /**
     * Tests a typed member
     *
     */
    #[@test, @expect('lang.FormatException')]
    public function typedMemberMismatch() {
      $this->emit('class Test { private string $bar; public void test() { $this->bar= 1; } }');
    }

    /**
     * Tests binary assignment
     *
     */
    #[@test]
    public function binaryAssign() {
      $this->emit('$product= 0; $product+= 3;');
    }

    /**
     * Tests array assignment via []=
     *
     */
    #[@test]
    public function arrayAssign() {
      $this->emit('$args= array(); $args[]= "Hello";');
    } 


    /**
     * Tests array assignment via [X]=
     *
     */
    #[@test]
    public function arrayOffsetAssign() {
      $this->emit('$args= array(); $args[0]= "Hello";');
    } 

    /**
     * Tests array offset return [X]
     *
     */
    #[@test]
    public function arrayOffsetReturn() {
      $this->emit('class Throwable { 
        public lang.StackTraceElement elementAt(int $o) { 
          $a= array();<commit_msg>- Add real-life piece of source from lang.StackTraceElement<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
   *
   * @purpose  Unit Test
   */
  class TypesEmitterTest extends AbstractEmitterTest {

    /**
     * Tests 
     *
     */
    #[@test]
    public function unassignedVariableCanBecomeAnything() {
      foreach (array('NULL', '1', '1.0', 'array()', '"Hello"', 'new lang.Object();') as $init) {
        $this->emit('$x= '.$init.';');
      }
    }

    /**
     * Tests an untyped argument
     *
     */
    #[@test]
    public function untypedArgument() {
      $this->emit('class Test { public void test($bar) { $bar= 1; } }');
    }

    /**
     * Tests a typed argument
     *
     */
    #[@test, @expect('lang.FormatException')]
    public function typedArgumentMismatch() {
      $this->emit('class Test { public void test(string $bar) { $bar= 1; } }');
    }

    /**
     * Tests an untyped member
     *
     */
    #[@test]
    public function untypedMember() {
      $this->emit('class Test { private $bar; public void test() { $this->bar= 1; } }');
    }

    /**
     * Tests a typed member
     *
     */
    #[@test, @expect('lang.FormatException')]
    public function typedMemberMismatch() {
      $this->emit('class Test { private string $bar; public void test() { $this->bar= 1; } }');
    }

    /**
     * Tests binary assignment
     *
     */
    #[@test]
    public function binaryAssign() {
      $this->emit('$product= 0; $product+= 3;');
    }

    /**
     * Tests array assignment via []=
     *
     */
    #[@test]
    public function arrayAssign() {
      $this->emit('$args= array(); $args[]= "Hello";');
    } 

    /**
     * Tests array assignment via []=
     *
     */
    #[@test]
    public function stackTraceElementToString() {
      $this->emit('class ThrowableExcerpt {
       public
         $args     = array();
      
        protected string qualifiedClassName(string $class) {
          return "qname";
        }
        
        public void toString() {
          $args= array();
          if (isset($this->args)) {
            for ($j= 0, $a= sizeof($this->args); $j < $a; $j++) {
              if (is_array($this->args[$j])) {
                $args[]= "array[" ~ sizeof($this->args[$j]) ~ "]";
              } else if (is_object($this->args[$j])) {
                $args[]= $this->qualifiedClassName(get_class($this->args[$j])) ~ "{}";
              } else if (is_string($this->args[$j])) {
                $display= str_replace("%", "%%", addcslashes(substr($this->args[$j], 0, min(
                  (FALSE === $p= strpos($this->args[$j], "\n")) ? 0x40 : $p, 
                  0x40
                )), "\0..\17"));
                $args[]= (
                  "(0x" ~ dechex(strlen($this->args[$j])) ~ ")\"" ~ 
                  $display ~ 
                  "\""
                );
              } else if (is_null($this->args[$j])) {
                $args[]= "NULL";
              } else if (is_scalar($this->args[$j])) {
                $args[]= (string)$this->args[$j];
              } else if (is_resource($this->args[$j])) {
                $args[]= (string)$this->args[$j];
              } else {
                $args[]= "<" ~ gettype($this->args[$j]) ~ ">";
              }
            }
          }
        } 
      }');
    } 

    /**
     * Tests array assignment via [X]=
     *
     */
    #[@test]
    public function arrayOffsetAssign() {
      $this->emit('$args= array(); $args[0]= "Hello";');
    } 

    /**
     * Tests array offset return [X]
     *
     */
    #[@test]
    public function arrayOffsetReturn() {
      $this->emit('class Throwable { 
        public lang.StackTraceElement elementAt(int $o) { 
          $a= array();
{'fraction_non_alphanumeric': 0.18670203946277567, 'fraction_numerical': 0.005969159343392472, 'mean_word_length': 1.876490224129709, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 44, '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': '1700376', 'n_tokens_mistral': 1953, 'n_tokens_neox': 1875, 'n_words': 406}