<commit_before><?php
namespace esperecyan\url;

class URLTest extends \PHPUnit_Framework_TestCase
{
    /**
     * @param string $domain USVString
     * @param string $ascii USVString
     * @param string|null $message
     * @dataProvider asciiProvider
     */
    public function testDomainToASCII($domain, $ascii, $message = null)
    {
        $this->assertSame($ascii, URL::domainToASCII($domain), $message);
    }
    
    /**
     * @link http://www.unicode.org/reports/tr46/#Table_Example_Processing UTS #46: Unicode IDNA Compatibility Processing
     */
    public function asciiProvider()
    {
        return [
            ['Bloß.de'       , 'xn--blo-7ka.de'   ],
            ['xn--blo-7ka.de', 'xn--blo-7ka.de'   ],
            ['ü.com'        , 'xn--tda.com'      ], // u + COMBINING DIAERESIS (U+0308) + .com
            ['xn--tda.com'   , 'xn--tda.com'      ],
            ['xn--u-ccb.com' , ''                 ],
            ['a⒈com'        , ''                 ], // a + DIGIT ONE FULL STOP (U+2488)
            ['xn--a-ecp.ru'  , ''                 ],
            ['xn--0.pt'      , ''                 ],
            ['日本語。ＪＰ'  , 'xn--wgv71a119e.jp'],
            ['☕.us'         , 'xn--53h.us'       ], // HOT BEVERAGE (U+2615) + .us
            ['[2001:db8::1]' , ''                 ],
            ['[2001:db8:::1]', ''                 ],
            ['u/r/l?#.test'  , ''                 ],
            ['203.0.113.1'   , ''                 ],
            ['203.000.113.01', ''                 ],
            ['203.0.113.256' , ''                 ],
            ['0xCB007101'    , ''                 ],
        ];
    }

    /**
     * @param string $domain USVString
     * @param string $unicode USVString
     * @param string|null $message
     * @dataProvider unicodeProvider
     */
    public function testDomainToUnicode($domain, $unicode, $message = null)
    {
        $this->assertSame($unicode, URL::domainToUnicode($domain), $message);
    }
    
    /**
     * @link http://www.unicode.org/reports/tr46/#Table_Example_Processing UTS #46: Unicode IDNA Compatibility Processing
     */
    public function unicodeProvider()
    {
        return [
            ['Bloß.de'       , 'bloß.de'       ],
            ['xn--blo-7ka.de', 'bloß.de'       ],
            ['ü.com'        , 'ü.com'         ], // u + COMBINING DIAERESIS (U+0308) + .com
            ['xn--tda.com'   , 'ü.com'         ],
            ['xn--u-ccb.com' , ''              ],
            ['a⒈com'        , ''              ], // a + DIGIT ONE FULL STOP (U+2488)
            ['xn--a-ecp.ru'  , ''              ],
            ['xn--0.pt'      , ''              ],
            ['日本語。ＪＰ'  , '日本語.jp'     ],
            ['☕.us'         , '☕.us'         ], // HOT BEVERAGE (U+2615) + .us
            ['[2001:db8::1]' , ''              ],
            ['[2001:db8:::1]', ''              ],
            ['u/r/l?#.test'  , ''              ],
            ['203.0.113.1'   , ''              ],
            ['203.000.113.01', ''              ],
            ['203.0.113.256' , ''              ],
            ['0xCB007101'    , ''              ],
        ];
    }
    
    /**
     * @param string $url
     * @param string|null $base
     * @param string $string
     * @dataProvider urlProvider
     */
    public function testConstruct($url, $base, $string)
    {
        $this->assertSame($string, (string)(is_null($base) ? new URL($url) : new URL($url, $base)));
    }
    
    public function urlProvider()
    {
        return [
            ['http://url.test/', null                       , 'http://url.test/'                 ],
            ['//url.test/'     , 'http://base.test/'        , 'http://url.test/'                 ],
            ['/path'           , 'http://base.test/foo/bar' , 'http://base.test/path'            ],
            ['filename'        , 'http://base.test/foo/bar' , 'http://base.test/foo/filename'    ],
            ['filename'        , 'http://base.test/foo/bar/', 'http://base.test/foo/bar/filename'],
            [''                , 'http://base.test/foo/bar' , 'http://base.test/foo/bar'         ],
            ['.'               , 'http://base.test/foo/bar' , 'http://base.test/foo/'            ],
        ];
    }
    
    public function testMissingArgument()
    {
        if (class_exists('ArgumentCountError')) {
            // PHP 7.1 or later
            $this->expectException('ArgumentCountError');
            $this->expectExceptionMessage('Too few arguments to function esperecyan\url\URL::__construct(), 0 passed');
        } else {
            // PHP 7.0 or earlier
            $this->expectException('PHPUnit_Framework_Error_Warning');
            $this->expectExceptionMessage('Missing argument 1 for esperecyan\url\URL::__construct()');
        }
        
        new URL();
    }
    
    /**
     * @expectedException \InvalidArgumentException
     * @expectedExceptionMessage Argument 1 passed to esperecyan\url\URL::__construct() is not of the expected type
     */
    public function testInvalidType()
    {
        new URL(new \stdClass());
    }
    
    /**
     * @param string $url
     * @param string|null $base
     * @expectedException \esperecyan\webidl\TypeError
     * @expectedExceptionMessage is not a valid URL
     * @dataProvider invalidHrefProvider
     * @dataProvider invalidURLProvider
     */
    public function testInvalidURL($url, $base = null)
    {
        if (is_null($base)) {
            new URL($url);
        } else {
            new URL($url, $base);
        }
    }
    
    public function invalidHrefProvider()
    {
        return [
            ['//url.test/'                 ],
            ['/path'                       ],
            ['filename'                    ],
            [''                            ],
            ['.'                           ],
            ['file://invalid:8080/filename'],
        ];
    }<commit_msg>Append some tests to the URL::testConstruct() and testInvalidURL()<commit_after><?php
namespace esperecyan\url;

class URLTest extends \PHPUnit_Framework_TestCase
{
    /**
     * @param string $domain USVString
     * @param string $ascii USVString
     * @param string|null $message
     * @dataProvider asciiProvider
     */
    public function testDomainToASCII($domain, $ascii, $message = null)
    {
        $this->assertSame($ascii, URL::domainToASCII($domain), $message);
    }
    
    /**
     * @link http://www.unicode.org/reports/tr46/#Table_Example_Processing UTS #46: Unicode IDNA Compatibility Processing
     */
    public function asciiProvider()
    {
        return [
            ['Bloß.de'       , 'xn--blo-7ka.de'   ],
            ['xn--blo-7ka.de', 'xn--blo-7ka.de'   ],
            ['ü.com'        , 'xn--tda.com'      ], // u + COMBINING DIAERESIS (U+0308) + .com
            ['xn--tda.com'   , 'xn--tda.com'      ],
            ['xn--u-ccb.com' , ''                 ],
            ['a⒈com'        , ''                 ], // a + DIGIT ONE FULL STOP (U+2488)
            ['xn--a-ecp.ru'  , ''                 ],
            ['xn--0.pt'      , ''                 ],
            ['日本語。ＪＰ'  , 'xn--wgv71a119e.jp'],
            ['☕.us'         , 'xn--53h.us'       ], // HOT BEVERAGE (U+2615) + .us
            ['[2001:db8::1]' , ''                 ],
            ['[2001:db8:::1]', ''                 ],
            ['u/r/l?#.test'  , ''                 ],
            ['203.0.113.1'   , ''                 ],
            ['203.000.113.01', ''                 ],
            ['203.0.113.256' , ''                 ],
            ['0xCB007101'    , ''                 ],
        ];
    }

    /**
     * @param string $domain USVString
     * @param string $unicode USVString
     * @param string|null $message
     * @dataProvider unicodeProvider
     */
    public function testDomainToUnicode($domain, $unicode, $message = null)
    {
        $this->assertSame($unicode, URL::domainToUnicode($domain), $message);
    }
    
    /**
     * @link http://www.unicode.org/reports/tr46/#Table_Example_Processing UTS #46: Unicode IDNA Compatibility Processing
     */
    public function unicodeProvider()
    {
        return [
            ['Bloß.de'       , 'bloß.de'       ],
            ['xn--blo-7ka.de', 'bloß.de'       ],
            ['ü.com'        , 'ü.com'         ], // u + COMBINING DIAERESIS (U+0308) + .com
            ['xn--tda.com'   , 'ü.com'         ],
            ['xn--u-ccb.com' , ''              ],
            ['a⒈com'        , ''              ], // a + DIGIT ONE FULL STOP (U+2488)
            ['xn--a-ecp.ru'  , ''              ],
            ['xn--0.pt'      , ''              ],
            ['日本語。ＪＰ'  , '日本語.jp'     ],
            ['☕.us'         , '☕.us'         ], // HOT BEVERAGE (U+2615) + .us
            ['[2001:db8::1]' , ''              ],
            ['[2001:db8:::1]', ''              ],
            ['u/r/l?#.test'  , ''              ],
            ['203.0.113.1'   , ''              ],
            ['203.000.113.01', ''              ],
            ['203.0.113.256' , ''              ],
            ['0xCB007101'    , ''              ],
        ];
    }
    
    /**
     * @param string $url
     * @param string|null $base
     * @param string $string
     * @dataProvider urlProvider
     */
    public function testConstruct($url, $base, $string)
    {
        $this->assertSame($string, (string)(is_null($base) ? new URL($url) : new URL($url, $base)));
    }
    
    public function urlProvider()
    {
        return [
            ['http://url.test/'                  , null                       , 'http://url.test/'                  ],
            ['//url.test/'                       , 'http://base.test/'        , 'http://url.test/'                  ],
            ['/path'                             , 'http://base.test/foo/bar' , 'http://base.test/path'             ],
            ['filename'                          , 'http://base.test/foo/bar' , 'http://base.test/foo/filename'     ],
            ['filename'                          , 'http://base.test/foo/bar/', 'http://base.test/foo/bar/filename' ],
            [''                                  , 'http://base.test/foo/bar' , 'http://base.test/foo/bar'          ],
            ['.'                                 , 'http://base.test/foo/bar' , 'http://base.test/foo/'             ],
            // https://url.spec.whatwg.org/#example-url-parsing
            ['https:example.org'                 , null                       , 'https://example.org/'              ],
            ['https://////example.com///'        , null                       , 'https://example.com///'            ],
            ['https://example.com/././foo'       , null                       , 'https://example.com/foo'           ],
            ['hello:world'                       , 'https://example.com/'     , 'hello:world'                       ],
            ['https:example.org'                 , 'https://example.com/'     , 'https://example.com/example.org'   ],
            ['\\example\\..\\demo/.\\'           , 'https://example.com/'     , 'https://example.com/demo/'         ],
            ['example'                           , 'https://example.com/demo' , 'https://example.com/example'       ],
            ['file:///C|/demo'                   , null                       , 'file:///C:/demo'                   ],
            ['..'                                , 'file:///C:/demo'          , 'file:///C:/'                       ],
            ['file://loc%61lhost/'               , null                       , 'file:///'                          ],
            ['https://user:password@example.org/', null                       , 'https://user:password@example.org/'],
            ['https://example.org/foo bar'       , null                       , 'https://example.org/foo%20bar'     ],
            ['https://EXAMPLE.com/../x'          , null                       , 'https://example.com/x'             ],
        ];
    }
    
    public function testMissingArgument()
    {
        if (class_exists('ArgumentCountError')) {
            // PHP 7.1 or later
            $this->expectException('ArgumentCountError');
            $this->expectExceptionMessage('Too few arguments to function esperecyan\url\URL::__construct(), 0 passed');
        } else {
            // PHP 7.0 or earlier
            $this->expectException('PHPUnit_Framework_Error_Warning');
            $this->expectExceptionMessage('Missing argument 1 for esperecyan\url\URL::__construct()');
        }
        
        new URL();
    }
    
    /**
     * @expectedException \InvalidArgumentException
     * @expectedExceptionMessage Argument 1 passed to esperecyan\url\URL::__construct() is not of the expected type
     */
    public function testInvalidType()
    {
        new URL(new \stdClass());
    }
    
    /**
     * @param string $url
     * @param string|null $base
     * @expectedException \esperecyan\webidl\TypeError
     * @expectedExceptionMessage is not a valid URL
     * @dataProvider invalidHrefProvider
     * @dataProvider invalidURLProvider
     */
    public function testInvalidURL($url, $base = null)
    {
        if (is_null($base)) {
            new URL($url);
        } else {
            new URL($url, $base);
        }
    }
    
    public function invalidHrefProvider()
    {
        return [
            ['//url.test/'                 ],
            ['/path'                       ],
            ['filename'                    ],
            [''                            ],
            ['.'                           ],
            ['file://invalid:8080/filename'],
            // https://url.spec.whatwg.org/#example-url-parsing
            ['https://ex ample.org/'       ],
            ['example'                     ],
            ['https://example.com:demo'    ],
            ['http://[www.example.com]/ '  ],
        ];
    }
{'fraction_non_alphanumeric': 0.16920083591554372, 'fraction_numerical': 0.022194998919074727, 'mean_word_length': 1.1643792888334372, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, 'https://': 22, 'lorem ipsum': 0, 'www.': 5, 'xml': 0}, 'pii_count': 14, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 13, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '761608', 'n_tokens_mistral': 4336, 'n_tokens_neox': 4073, 'n_words': 627}