<commit_before><?php
/**
 * @group trl
 */
class Vps_Trl_TrlTest extends PHPUnit_Framework_TestCase
{
    private $_trlObject;
    public function setUp()
    {
        $this->_trlObject = new Vps_Trl();
    }

    public function testTrlParsePhp()
    {
        $values = $this->_trlObject->parse('trl("\n")');
        $this->assertEquals(Vps_Trl::ERROR_INVALID_STRING, $values[0]['error_short']);

        $values = $this->_trlObject->parse('trl("")');
        $this->assertEquals(Vps_Trl::ERROR_WRONG_NR_OF_ARGUMENTS, $values[0]['error_short']);

        $values = $this->_trlObject->parse('trlc("aaa")');
        $this->assertEquals(Vps_Trl::ERROR_WRONG_NR_OF_ARGUMENTS, $values[0]['error_short']);

        $values = $this->_trlObject->parse('trlc("aaa", array("hallo")');
        $this->assertEquals(Vps_Trl::ERROR_WRONG_NR_OF_ARGUMENTS, $values[0]['error_short']);

        $values = $this->_trlObject->parse('trl("hallo");
        trlc("context", "text");
        trlp("one beer", "{0} beers") asdfjklkasjf asklfjdksadljf trl("asdf"."asdf") asklfjsdalkfj trl("test"))');
        $this->assertEquals("hallo", $values[0]['text']);
        $this->assertEquals("context", $values[1]['context']);
        $this->assertEquals("text", $values[1]['text']);
        $this->assertEquals("one beer", $values[2]['text']);
        $this->assertEquals("{0} beers", $values[2]['plural']);
        $this->assertEquals(Vps_Trl::ERROR_INVALID_CHAR, $values[3]['error_short']);
        $this->assertEquals("test", $values[4]['text']);

        $values = $this->_trlObject->parse('trl("test"."foo")');
        $this->assertEquals(true, $values[0]['error']);
        $this->assertEquals(Vps_Trl::ERROR_INVALID_CHAR, $values[0]['error_short']);

        $values = $this->_trlObject->parse('trl("test$foo")');
        $this->assertEquals(Vps_Trl::ERROR_INVALID_STRING, $values[0]['error_short']);

        $values = $this->_trlObject->parse('trl("test\$foo")');
        $this->assertEquals('test\$foo', $values[0]['text']);

        $values = $this->_trlObject->parse('asdfdsa
        fasdfasdf
        asdf a
        s
        trl(\'check\')
        asfsdafa

        asdfsafd
        trl(\'test$foo\')');
        $this->assertEquals('check', $values[0]['text']);
        $this->assertEquals(5, $values[0]['linenr']);
        $this->assertEquals('test$foo', $values[1]['text']);
        $this->assertEquals(9, $values[1]['linenr']);

        //gleicher test mit fehler
        $values = $this->_trlObject->parse('asdfdsa
        fasdfasdf
        asdf a
        s
        trl(\'check\')
        asfsdafa

        asdfsafd
        trl("test"."foo")');
        $this->assertEquals('check', $values[0]['text']);
        $this->assertEquals(5, $values[0]['linenr']);
        $this->assertEquals(Vps_Trl::ERROR_INVALID_CHAR, $values[1]['error_short']);
        $this->assertEquals(9, $values[1]['linenr']);
        $values = $this->_trlObject->parse("trl(\"test\nfoo\")");
        $this->assertEquals(Vps_Trl::ERROR_INVALID_STRING, $values[0]['error_short']);

        $values = $this->_trlObject->parse("trl('testWord')");
        $this->assertEquals('web', $values[0]['source']);
        $this->assertEquals('testWord', $values[0]['text']);

        $values = $this->_trlObject->parse("trlVps('testWord')");
        $this->assertEquals('vps', $values[0]['source']);
        $this->assertEquals('testWord', $values[0]['text']);

        $values = $this->_trlObject->parse("trlc(\"testContext\", \"testWord\")");
        $this->assertEquals('web', $values[0]['source']);
        $this->assertEquals('testWord', $values[0]['text']);
        $this->assertEquals('testContext', $values[0]['context']);

        $values = $this->_trlObject->parse("trlcVps(\"testContext\", \"testWord\")");
        $this->assertEquals('vps', $values[0]['source']);
        $this->assertEquals('testWord', $values[0]['text']);
        $this->assertEquals('testContext', $values[0]['context']);

        $values = $this->_trlObject->parse("trlp('testWord', 'testWords', 3)");
        $this->assertEquals('web', $values[0]['source']);
        $this->assertEquals('testWord', $values[0]['text']);
        $this->assertEquals('testWords', $values[0]['plural']);
        $values = $this->_trlObject->parse("trlpVps('testWord', 'testWords', 3)");
        $this->assertEquals('vps', $values[0]['source']);
        $this->assertEquals('testWord', $values[0]['text']);
        $this->assertEquals('testWords', $values[0]['plural']);

        $values = $this->_trlObject->parse("trlcpVps('testContext', 'testWord', 'testWords', 3)");
        $this->assertEquals('vps', $values[0]['source']);
        $this->assertEquals('testWord', $values[0]['text']);
        $this->assertEquals('testWords', $values[0]['plural']);
        $this->assertEquals('testContext', $values[0]['context']);
        $this->assertEquals('trlcp', $values[0]['type']);
        $this->assertEquals("trlcpVps('testContext', 'testWord', 'testWords', 3)", $values[0]['before']);

        //more complicated tests
        $values = $this->_trlObject->parse("trl('testWord {0} and {1}', array('word1' and 'word2')");
        $this->assertEquals('web', $values[0]['source']);
        $this->assertEquals('testWord {0} and {1}', $values[0]['text']);

        $values = $this->_trlObject->parse('trl("te\'st")');
        $this->assertEquals("te'st", $values[0]['text']);

        $values = $this->_trlObject->parse('trl("testW\"ord {0} and {1}")');
        $this->assertEquals('testW"ord {0} and {1}', $values[0]['text']);

        $values = $this->_trlObject->parse("trl('te\"st')");
        $this->assertEquals('te"st', $values[0]['text']);

        $values = $this->_trlObject->parse("trl('test')");
        $this->assertEquals('test', $values[0]['text']);

        $values = $this->_trlObject->parse('trl(\'test\')');
        $this->assertEquals('test', $values[0]['text']);

        $values = $this->_trlObject->parse('trl("testWord {0} and {1}", array("word1", "word2");');
        $this->assertEquals("testWord {0} and {1}", $values[0]['text']);

        $values = $this->_trlObject->parse('trlc("context", "text"); trl("text2");');
        $this->assertEquals("context", $values[0]['context']);
    }

    public function testTrlParseJs ()
    {
        $values = $this->_trlObject->parse('trlc("context", "{0} days a week", [5])', 'js');
        $this->assertEquals('context', $values[0]['context']);
        $this->assertEquals('{0} days a week', $values[0]['text']);

        $values = $this->_trlObject->parse('trl("hallo")', 'js');
        $this->assertEquals('hallo', $values[0]['text']);

        $values = $this->_trlObject->parse('trlp("one error found", "{0} errors found", [2])', 'js');
        $this->assertEquals('one error found', $values[0]['text']);
        $this->assertEquals('{0} errors found', $values[0]['plural']);

        $values = $this->_trlObject->parse('trlcp("errors", "one error found", "{0} errors found", [2])', 'js');
        $this->assertEquals('errors', $values[0]['context']);
        $this->assertEquals('one error found', $values[0]['text']);
        $this->assertEquals('{0} errors found', $values[0]['plural']);

        $values = $this->_trlObject->parse('trl("signs{}[])=!")', 'js');
        $this->assertEquals('signs{}[])=!', $values[0]['text']);

        $values = $this->_trlObject->parse('trl("signs{}[])=!$")', 'js');
        $this->assertEquals("signs{}[])=!$", $values[0]['text']);

        $values = $this->_trlObject->parse('trl("signs{}[])\n=!")', 'js');
        $this->assertEquals(true, $values[0]['error']);

        $values = $this->_trlObject->parse('trl("signs{}[])
        =!")', 'js');
        $this->assertEquals(true, $values[0]['error']);
    }

    public function testTrlParseJsLargeString()
    {
        //$this->markTestIncomplete();
        //wenn behoben in JsLoader Zeile 77 Hack entfernen

        $input = str_repeat(' ', 10015)." trlVps('Info')";
        $result = $this->_trlObject->parse($input, 'js');
        $this->assertEquals(1, count($result));

        $input = str_repeat(' ', 11000)." trlVps('Info')";
        $result = $this->_trlObject->parse($input, 'js');
        $this->assertEquals(1, count($result));

        $input = str_repeat(' ', 7998)."trlVps('Info')".
                 str_repeat(' ', 11000)."trlVps('Foo')";<commit_msg>wurde vor ewig schon behoben denke ich<commit_after><?php
/**
 * @group trl
 */
class Vps_Trl_TrlTest extends PHPUnit_Framework_TestCase
{
    private $_trlObject;
    public function setUp()
    {
        $this->_trlObject = new Vps_Trl();
    }

    public function testTrlParsePhp()
    {
        $values = $this->_trlObject->parse('trl("\n")');
        $this->assertEquals(Vps_Trl::ERROR_INVALID_STRING, $values[0]['error_short']);

        $values = $this->_trlObject->parse('trl("")');
        $this->assertEquals(Vps_Trl::ERROR_WRONG_NR_OF_ARGUMENTS, $values[0]['error_short']);

        $values = $this->_trlObject->parse('trlc("aaa")');
        $this->assertEquals(Vps_Trl::ERROR_WRONG_NR_OF_ARGUMENTS, $values[0]['error_short']);

        $values = $this->_trlObject->parse('trlc("aaa", array("hallo")');
        $this->assertEquals(Vps_Trl::ERROR_WRONG_NR_OF_ARGUMENTS, $values[0]['error_short']);

        $values = $this->_trlObject->parse('trl("hallo");
        trlc("context", "text");
        trlp("one beer", "{0} beers") asdfjklkasjf asklfjdksadljf trl("asdf"."asdf") asklfjsdalkfj trl("test"))');
        $this->assertEquals("hallo", $values[0]['text']);
        $this->assertEquals("context", $values[1]['context']);
        $this->assertEquals("text", $values[1]['text']);
        $this->assertEquals("one beer", $values[2]['text']);
        $this->assertEquals("{0} beers", $values[2]['plural']);
        $this->assertEquals(Vps_Trl::ERROR_INVALID_CHAR, $values[3]['error_short']);
        $this->assertEquals("test", $values[4]['text']);

        $values = $this->_trlObject->parse('trl("test"."foo")');
        $this->assertEquals(true, $values[0]['error']);
        $this->assertEquals(Vps_Trl::ERROR_INVALID_CHAR, $values[0]['error_short']);

        $values = $this->_trlObject->parse('trl("test$foo")');
        $this->assertEquals(Vps_Trl::ERROR_INVALID_STRING, $values[0]['error_short']);

        $values = $this->_trlObject->parse('trl("test\$foo")');
        $this->assertEquals('test\$foo', $values[0]['text']);

        $values = $this->_trlObject->parse('asdfdsa
        fasdfasdf
        asdf a
        s
        trl(\'check\')
        asfsdafa

        asdfsafd
        trl(\'test$foo\')');
        $this->assertEquals('check', $values[0]['text']);
        $this->assertEquals(5, $values[0]['linenr']);
        $this->assertEquals('test$foo', $values[1]['text']);
        $this->assertEquals(9, $values[1]['linenr']);

        //gleicher test mit fehler
        $values = $this->_trlObject->parse('asdfdsa
        fasdfasdf
        asdf a
        s
        trl(\'check\')
        asfsdafa

        asdfsafd
        trl("test"."foo")');
        $this->assertEquals('check', $values[0]['text']);
        $this->assertEquals(5, $values[0]['linenr']);
        $this->assertEquals(Vps_Trl::ERROR_INVALID_CHAR, $values[1]['error_short']);
        $this->assertEquals(9, $values[1]['linenr']);
        $values = $this->_trlObject->parse("trl(\"test\nfoo\")");
        $this->assertEquals(Vps_Trl::ERROR_INVALID_STRING, $values[0]['error_short']);

        $values = $this->_trlObject->parse("trl('testWord')");
        $this->assertEquals('web', $values[0]['source']);
        $this->assertEquals('testWord', $values[0]['text']);

        $values = $this->_trlObject->parse("trlVps('testWord')");
        $this->assertEquals('vps', $values[0]['source']);
        $this->assertEquals('testWord', $values[0]['text']);

        $values = $this->_trlObject->parse("trlc(\"testContext\", \"testWord\")");
        $this->assertEquals('web', $values[0]['source']);
        $this->assertEquals('testWord', $values[0]['text']);
        $this->assertEquals('testContext', $values[0]['context']);

        $values = $this->_trlObject->parse("trlcVps(\"testContext\", \"testWord\")");
        $this->assertEquals('vps', $values[0]['source']);
        $this->assertEquals('testWord', $values[0]['text']);
        $this->assertEquals('testContext', $values[0]['context']);

        $values = $this->_trlObject->parse("trlp('testWord', 'testWords', 3)");
        $this->assertEquals('web', $values[0]['source']);
        $this->assertEquals('testWord', $values[0]['text']);
        $this->assertEquals('testWords', $values[0]['plural']);
        $values = $this->_trlObject->parse("trlpVps('testWord', 'testWords', 3)");
        $this->assertEquals('vps', $values[0]['source']);
        $this->assertEquals('testWord', $values[0]['text']);
        $this->assertEquals('testWords', $values[0]['plural']);

        $values = $this->_trlObject->parse("trlcpVps('testContext', 'testWord', 'testWords', 3)");
        $this->assertEquals('vps', $values[0]['source']);
        $this->assertEquals('testWord', $values[0]['text']);
        $this->assertEquals('testWords', $values[0]['plural']);
        $this->assertEquals('testContext', $values[0]['context']);
        $this->assertEquals('trlcp', $values[0]['type']);
        $this->assertEquals("trlcpVps('testContext', 'testWord', 'testWords', 3)", $values[0]['before']);

        //more complicated tests
        $values = $this->_trlObject->parse("trl('testWord {0} and {1}', array('word1' and 'word2')");
        $this->assertEquals('web', $values[0]['source']);
        $this->assertEquals('testWord {0} and {1}', $values[0]['text']);

        $values = $this->_trlObject->parse('trl("te\'st")');
        $this->assertEquals("te'st", $values[0]['text']);

        $values = $this->_trlObject->parse('trl("testW\"ord {0} and {1}")');
        $this->assertEquals('testW"ord {0} and {1}', $values[0]['text']);

        $values = $this->_trlObject->parse("trl('te\"st')");
        $this->assertEquals('te"st', $values[0]['text']);

        $values = $this->_trlObject->parse("trl('test')");
        $this->assertEquals('test', $values[0]['text']);

        $values = $this->_trlObject->parse('trl(\'test\')');
        $this->assertEquals('test', $values[0]['text']);

        $values = $this->_trlObject->parse('trl("testWord {0} and {1}", array("word1", "word2");');
        $this->assertEquals("testWord {0} and {1}", $values[0]['text']);

        $values = $this->_trlObject->parse('trlc("context", "text"); trl("text2");');
        $this->assertEquals("context", $values[0]['context']);
    }

    public function testTrlParseJs ()
    {
        $values = $this->_trlObject->parse('trlc("context", "{0} days a week", [5])', 'js');
        $this->assertEquals('context', $values[0]['context']);
        $this->assertEquals('{0} days a week', $values[0]['text']);

        $values = $this->_trlObject->parse('trl("hallo")', 'js');
        $this->assertEquals('hallo', $values[0]['text']);

        $values = $this->_trlObject->parse('trlp("one error found", "{0} errors found", [2])', 'js');
        $this->assertEquals('one error found', $values[0]['text']);
        $this->assertEquals('{0} errors found', $values[0]['plural']);

        $values = $this->_trlObject->parse('trlcp("errors", "one error found", "{0} errors found", [2])', 'js');
        $this->assertEquals('errors', $values[0]['context']);
        $this->assertEquals('one error found', $values[0]['text']);
        $this->assertEquals('{0} errors found', $values[0]['plural']);

        $values = $this->_trlObject->parse('trl("signs{}[])=!")', 'js');
        $this->assertEquals('signs{}[])=!', $values[0]['text']);

        $values = $this->_trlObject->parse('trl("signs{}[])=!$")', 'js');
        $this->assertEquals("signs{}[])=!$", $values[0]['text']);

        $values = $this->_trlObject->parse('trl("signs{}[])\n=!")', 'js');
        $this->assertEquals(true, $values[0]['error']);

        $values = $this->_trlObject->parse('trl("signs{}[])
        =!")', 'js');
        $this->assertEquals(true, $values[0]['error']);
    }

    public function testTrlParseJsLargeString()
    {
        $input = str_repeat(' ', 10015)." trlVps('Info')";
        $result = $this->_trlObject->parse($input, 'js');
        $this->assertEquals(1, count($result));

        $input = str_repeat(' ', 11000)." trlVps('Info')";
        $result = $this->_trlObject->parse($input, 'js');
        $this->assertEquals(1, count($result));

        $input = str_repeat(' ', 7998)."trlVps('Info')".
                 str_repeat(' ', 11000)."trlVps('Foo')";
{'fraction_non_alphanumeric': 0.2433766859344894, 'fraction_numerical': 0.015052986512524085, 'mean_word_length': 3.759025787965616, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 288, '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': '6312753', 'n_tokens_mistral': 5351, 'n_tokens_neox': 5197, 'n_words': 734}