<commit_before><?php

namespace League\Url\Test;

use League\Url\Formatter;
use League\Url\Url;
use PHPUnit_Framework_TestCase;

/**
 * @group url
 */
class FormatterTest extends PHPUnit_Framework_TestCase
{
    private $url;

    public function setUp()
    {
        $this->url = Url::createFromUrl(
            'http://login:pass@gwóźdź.pl:443/test/query.php?kingkong=toto&foo=bar+baz#doc3'
        );
    }

    public function testFormatHostAscii()
    {
        $formatter = new Formatter;
        $this->assertSame(Formatter::HOST_UNICODE, $formatter->getHostEncoding());
        $formatter->setHostEncoding(Formatter::HOST_ASCII);
        $this->assertSame(Formatter::HOST_ASCII, $formatter->getHostEncoding());
        $this->assertSame('xn--gwd-hna98db.pl', $formatter->format($this->url->getHost()));
    }

    /**
     * @expectedException \InvalidArgumentException
     */
    public function testInvalidHostEncoding()
    {
        (new Formatter())->setHostEncoding('toto');
    }

    /**
     * @expectedException \InvalidArgumentException
     */
    public function testInvalidQueryEncoding()
    {
        (new Formatter())->setQueryEncoding('toto');
    }

    /**
     * @expectedException \InvalidArgumentException
     */
    public function testInvalidFormat()
    {
        $formatter = new Formatter;
        $formatter->format(new \StdClass);
    }

    public function testFormatHostUnicode()
    {
        $formatter = new Formatter;
        $formatter->setHostEncoding(Formatter::HOST_UNICODE);
        $this->assertSame('gwóźdź.pl', $formatter->format($this->url->getHost()));
    }

    public function testFormatQueryRFC1738()
    {
        $formatter = new Formatter;
        $this->assertSame(PHP_QUERY_RFC3986, $formatter->getQueryEncoding());
        $formatter->setQueryEncoding(PHP_QUERY_RFC1738);
        $this->assertSame(PHP_QUERY_RFC1738, $formatter->getQueryEncoding());
        $this->assertSame('kingkong=toto&foo=bar+baz', $formatter->format($this->url->getQuery()));
    }

    public function testFormatQueryRFC3986()
    {
        $formatter = new Formatter;
        $formatter->setQueryEncoding(PHP_QUERY_RFC3986);
        $this->assertSame('kingkong=toto&foo=bar%20baz', $formatter->format($this->url->getQuery()));
    }

    public function testFormatQueryWithSeparator()
    {
        $formatter = new Formatter;
        $this->assertSame('&', $formatter->getQuerySeparator());
        $formatter->setQuerySeparator('&amp;');
        $this->assertSame('&amp;', $formatter->getQuerySeparator());
        $this->assertSame('kingkong=toto&amp;foo=bar%20baz', $formatter->formatQuery($this->url->getQuery()));
    }

    public function testFormatURL()
    {
        $formatter = new Formatter;
        $formatter->setQuerySeparator('&amp;');
        $formatter->setHostEncoding(Formatter::HOST_ASCII);
        $expected = 'http://login:pass@xn--gwd-hna98db.pl:443/test/query.php?kingkong=toto&amp;foo=bar%20baz#doc3';
        $this->assertSame($expected, $formatter->format($this->url));
    }
}<commit_msg>bug fix Formatter<commit_after><?php

namespace League\Url\Test;

use League\Url\Formatter;
use League\Url\Url;
use PHPUnit_Framework_TestCase;

/**
 * @group url
 */
class FormatterTest extends PHPUnit_Framework_TestCase
{
    private $url;

    public function setUp()
    {
        $this->url = Url::createFromUrl(
            'http://login:pass@gwóźdź.pl:443/test/query.php?kingkong=toto&foo=bar+baz#doc3'
        );
    }

    public function testFormatHostAscii()
    {
        $formatter = new Formatter;
        $this->assertSame(Formatter::HOST_UNICODE, $formatter->getHostEncoding());
        $formatter->setHostEncoding(Formatter::HOST_ASCII);
        $this->assertSame(Formatter::HOST_ASCII, $formatter->getHostEncoding());
        $this->assertSame('xn--gwd-hna98db.pl', $formatter->format($this->url->getHost()));
    }

    /**
     * @expectedException \InvalidArgumentException
     */
    public function testInvalidHostEncoding()
    {
        (new Formatter())->setHostEncoding('toto');
    }

    /**
     * @expectedException \InvalidArgumentException
     */
    public function testInvalidQueryEncoding()
    {
        (new Formatter())->setQueryEncoding('toto');
    }

    /**
     * @expectedException \InvalidArgumentException
     */
    public function testInvalidFormat()
    {
        $formatter = new Formatter;
        $formatter->format(new \StdClass);
    }

    public function testFormatHostUnicode()
    {
        $formatter = new Formatter;
        $formatter->setHostEncoding(Formatter::HOST_UNICODE);
        $this->assertSame('gwóźdź.pl', $formatter->format($this->url->getHost()));
    }

    public function testFormatQueryRFC1738()
    {
        $formatter = new Formatter;
        $this->assertSame(PHP_QUERY_RFC3986, $formatter->getQueryEncoding());
        $formatter->setQueryEncoding(PHP_QUERY_RFC1738);
        $this->assertSame(PHP_QUERY_RFC1738, $formatter->getQueryEncoding());
        $this->assertSame('kingkong=toto&foo=bar+baz', $formatter->format($this->url->getQuery()));
    }

    public function testFormatQueryRFC3986()
    {
        $formatter = new Formatter;
        $formatter->setQueryEncoding(PHP_QUERY_RFC3986);
        $this->assertSame('kingkong=toto&foo=bar%20baz', $formatter->format($this->url->getQuery()));
    }

    public function testFormatQueryWithSeparator()
    {
        $formatter = new Formatter;
        $this->assertSame('&', $formatter->getQuerySeparator());
        $formatter->setQuerySeparator('&amp;');
        $this->assertSame('&amp;', $formatter->getQuerySeparator());
        $this->assertSame('kingkong=toto&amp;foo=bar%20baz', $formatter->format($this->url->getQuery()));
    }

    public function testFormatURL()
    {
        $formatter = new Formatter;
        $formatter->setQuerySeparator('&amp;');
        $formatter->setHostEncoding(Formatter::HOST_ASCII);
        $expected = 'http://login:pass@xn--gwd-hna98db.pl:443/test/query.php?kingkong=toto&amp;foo=bar%20baz#doc3';
        $this->assertSame($expected, $formatter->format($this->url));
    }
}
{'fraction_non_alphanumeric': 0.15356967815716385, 'fraction_numerical': 0.013723247835321027, 'mean_word_length': 3.4138428262436915, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 95, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '3912704', 'n_tokens_mistral': 1981, 'n_tokens_neox': 1863, 'n_words': 234}