<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 EnumEmitterTest extends AbstractEmitterTest {

    /**
     * 
     *
     */
    #[@test]
    public function coinEnum() {
      $this->assertSourcecodeEquals('
        uses(\'lang.Enum\'); 

        class mainCoin extends langEnum {
          public static $penny, $nickel, $dime, $quarter;
          
          static function __static() {
            mainCoin::$penny= new mainCoin(1, \'penny\');
            mainCoin::$nickel= new mainCoin(2, \'nickel\');
            mainCoin::$dime= new mainCoin(10, \'dime\');
            mainCoin::$quarter= new mainCoin(25, \'quarter\');
          }
          
          public static function values() { 
            return array(
              mainCoin::$penny, 
              mainCoin::$nickel, 
              mainCoin::$dime, 
              mainCoin::$quarter,
            ); 
          }
        };',
        $this->emit('enum Coin { penny(1), nickel(2), dime(10), quarter(25) }')
      );
    }
  }
?><commit_msg>- Add enumWithMethod() - Add dayEnum()<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 EnumEmitterTest extends AbstractEmitterTest {

    /**
     * Tests basic enum 
     *
     */
    #[@test]
    public function dayEnum() {
      $this->assertSourcecodeEquals('
        uses(\'lang.Enum\'); 

        class mainDay extends langEnum {
          public static
            $monday,  
            $tuesday,
            $wednesday,
            $thursday,
            $friday,
            $saturday,
            $sunday;

          static function __static() {
            mainDay::$monday= new mainDay(0, \'monday\');
            mainDay::$tuesday= new mainDay(1, \'tuesday\');
            mainDay::$wednesday= new mainDay(2, \'wednesday\');
            mainDay::$thursday= new mainDay(3, \'thursday\');
            mainDay::$friday= new mainDay(4, \'friday\');
            mainDay::$saturday= new mainDay(5, \'saturday\');
            mainDay::$sunday= new mainDay(6, \'sunday\');
          }
          
          public static function values() { 
            return array(
              mainDay::$monday,
              mainDay::$tuesday,
              mainDay::$wednesday,
              mainDay::$thursday,
              mainDay::$friday,
              mainDay::$saturday,
              mainDay::$sunday,
            ); 
          }
        };',
        $this->emit('enum Day { 
          monday,  
          tuesday,
          wednesday,
          thursday,
          friday,
          saturday,
          sunday
        }')
      );
    }

    /**
     * Tests basic enum with assigned ordinal values
     *
     */
    #[@test]
    public function coinEnum() {
      $this->assertSourcecodeEquals('
        uses(\'lang.Enum\'); 

        class mainCoin extends langEnum {
          public static $penny, $nickel, $dime, $quarter;
          
          static function __static() {
            mainCoin::$penny= new mainCoin(1, \'penny\');
            mainCoin::$nickel= new mainCoin(2, \'nickel\');
            mainCoin::$dime= new mainCoin(10, \'dime\');
            mainCoin::$quarter= new mainCoin(25, \'quarter\');
          }
          
          public static function values() { 
            return array(
              mainCoin::$penny, 
              mainCoin::$nickel, 
              mainCoin::$dime, 
              mainCoin::$quarter,
            ); 
          }
        };',
        $this->emit('enum Coin { penny(1), nickel(2), dime(10), quarter(25) }')
      );
    }

    /**
     * Tests basic enum with assigned ordinal values
     *
     */
    #[@test]
    public function enumWithMethod() {
      $this->assertSourcecodeEquals('
        uses(\'lang.Enum\'); 

        class mainCoin extends langEnum {
          public static $penny, $nickel, $dime, $quarter;
          
          static function __static() {
            mainCoin::$penny= new mainCoin(1, \'penny\');
            mainCoin::$nickel= new mainCoin(2, \'nickel\');
            mainCoin::$dime= new mainCoin(10, \'dime\');
            mainCoin::$quarter= new mainCoin(25, \'quarter\');
          }
          
          public static function values() { 
            return array(
              mainCoin::$penny, 
              mainCoin::$nickel, 
              mainCoin::$dime, 
              mainCoin::$quarter,
            ); 
          }
          
          /**
           * @return  int
           */
          public function value() {
            return $this->ordinal;
          }
        };',
        $this->emit('enum Coin { 
          penny(1), nickel(2), dime(10), quarter(25);
          
          public int value() {
            return $this->ordinal;
          }
        }')
      );
    }
  }
?>
{'fraction_non_alphanumeric': 0.13942023269572076, 'fraction_numerical': 0.009268388877933346, 'mean_word_length': 1.477772349780166, 'pattern_counts': {'":': 0, '<': 5, '<?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': '685354', 'n_tokens_mistral': 1559, 'n_tokens_neox': 1498, 'n_words': 300}