<commit_before><?php

use Lechimp\STG\Gen\GClass;
use Lechimp\STG\Gen\GPrivateProperty;
use Lechimp\STG\Gen\GProtectedProperty;
use Lechimp\STG\Gen\GPublicProperty;
use Lechimp\STG\Gen\GPrivateMethod;
use Lechimp\STG\Gen\GProtectedMethod;
use Lechimp\STG\Gen\GPublicMethod;
use Lechimp\STG\Gen\GArgument;
use Lechimp\STG\Gen\GStatement;

class GenText extends PHPUnit_Framework_TestCase {
    protected function assertCodeEquals($left, $right) {
        $_left = $this->removeEmptyLines(split("\n", $left));
        $_right = $this->removeEmptyLines(split("\n", $right));
        $this->assertEquals($_left, $_right);
    }

    protected function removeEmptyLines(array $lines) {
        return array_filter($lines, function($line) {
            return trim($line) != "";
        });
    }

    public function test_emptyClass() {
        $gen = new GClass("Lechimp\\STG", "Test", array(), array());
        $generated = $gen->render(0);
        $expected = <<<'PHP'
class Lechimp\\STG\\Test {
}
PHP;
        $this->assertCodeEquals($generated, $expected);
    }

    public function test_filledClass() {
        $gen = new GClass("Lechimp\\STG", "Test"
            , array
                ( new GPrivateProperty("foo")
                , new GProtectedProperty("bar")
                , new GPublicProperty("baz")
                )
            , array
                ( new GPrivateMethod("get_bar", array(), array())
                , new GProtectedMethod("get_foo", array(), array())
                , new GPublicMethod("__construct", array(), array())
                )
            );
        $generated = $gen->render(0);
        $expected = <<<'PHP'
class Lechimp\\STG\\Test {
    private $foo;
    protected $bar;
    public $baz;
    public function get_bar() {
    } <commit_msg>added tests on class generation<commit_after><?php

use Lechimp\STG\Gen\GClass;
use Lechimp\STG\Gen\GPrivateProperty;
use Lechimp\STG\Gen\GProtectedProperty;
use Lechimp\STG\Gen\GPublicProperty;
use Lechimp\STG\Gen\GPrivateMethod;
use Lechimp\STG\Gen\GProtectedMethod;
use Lechimp\STG\Gen\GPublicMethod;
use Lechimp\STG\Gen\GArgument;
use Lechimp\STG\Gen\GStatement;

class GenText extends PHPUnit_Framework_TestCase {
    protected function assertCodeEquals($left, $right) {
        $_left = $this->removeEmptyLines(split("\n", $left));
        $_right = $this->removeEmptyLines(split("\n", $right));
        $this->assertEquals($_left, $_right);
    }

    protected function removeEmptyLines(array $lines) {
        return array_filter($lines, function($line) {
            return trim($line) != "";
        });
    }

    public function test_emptyClass() {
        $gen = new GClass("Lechimp\\STG", "Test", array(), array());
        $generated = $gen->render(0);
        $expected = <<<'PHP'
class Lechimp\\STG\\Test {
}
PHP;
        $this->assertCodeEquals($generated, $expected);
    }

    public function test_extendedClass() {
        $gen = new GClass("Lechimp\\STG", "Test", array(), array(), "Foo");
        $generated = $gen->render(0);
        $expected = <<<'PHP'
class Lechimp\\STG\\Test extends Foo {
}
PHP;
        $this->assertCodeEquals($generated, $expected);
    }

    public function test_noNamespaceClass() {
        $gen = new GClass("", "Test", array(), array());
        $generated = $gen->render(0);
        $expected = <<<'PHP'
class Test {
}
PHP;
        $this->assertCodeEquals($generated, $expected);
    }

    public function test_filledClass() {
        $gen = new GClass("Lechimp\\STG", "Test"
            , array
                ( new GPrivateProperty("foo")
                , new GProtectedProperty("bar")
                , new GPublicProperty("baz")
                )
            , array
                ( new GPrivateMethod("get_bar", array(), array())
                , new GProtectedMethod("get_foo", array(), array())
                , new GPublicMethod("__construct", array(), array())
                )
            );
        $generated = $gen->render(0);
        $expected = <<<'PHP'
class Lechimp\\STG\\Test {
    private $foo;
    protected $bar;
    public $baz;
    public function get_bar() {
    } 
{'fraction_non_alphanumeric': 0.15096618357487923, 'fraction_numerical': 0.0014492753623188406, 'mean_word_length': 2.5272572402044293, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 19, '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': '185975', 'n_tokens_mistral': 1284, 'n_tokens_neox': 1260, 'n_words': 251}