<commit_before><?php

class CM_File_Filesystem_AdapterTest extends CMTest_TestCase {

    public function testNormalizePath() {
        $adapter = $this->getMockBuilder('CM_File_Filesystem_Adapter')
            ->setConstructorArgs(array('/base/base2/'))->getMockForAbstractClass();
        /** @var CM_File_Filesystem_Adapter $adapter */

        $method = CMTest_TH::getProtectedMethod('CM_File_Filesystem_Adapter', '_normalizePath');
        $this->assertSame('/foo', $method->invoke($adapter, '/foo'));
        $this->assertSame('/foo', $method->invoke($adapter, '/foo/'));
        $this->assertSame('/', $method->invoke($adapter, '/'));
        $this->assertSame('/', $method->invoke($adapter, ''));
        $this->assertSame('/', $method->invoke($adapter, '//'));
        $this->assertSame('/foo/mega', $method->invoke($adapter, '/foo/bar/../mega'));
        $this->assertSame('/', $method->invoke($adapter, '/../..'));
        $this->assertSame('/foo/bar', $method->invoke($adapter, '/foo/./bar'));
        $this->assertSame('/foo/bar', $method->invoke($adapter, '/foo/./bar///'));
        $this->assertSame('/foo', $method->invoke($adapter, '../foo'));
        $this->assertSame('/foo', $method->invoke($adapter, 'foo'));
    }

    public function testGetAbsolutePath() {
        $adapter = $this->getMockBuilder('CM_File_Filesystem_Adapter')
            ->setConstructorArgs(array('/base/base2'))->getMockForAbstractClass();
        /** @var CM_File_Filesystem_Adapter $adapter */

        $method = CMTest_TH::getProtectedMethod('CM_File_Filesystem_Adapter', '_getAbsolutePath');
        $this->assertSame('/base/base2/bar', $method->invoke($adapter, 'bar'));
        $this->assertSame('/base/base2/foo', $method->invoke($adapter, '/bar/../foo'));
        $this->assertSame('/base/base2/foo', $method->invoke($adapter, 'bar/../foo'));
        $this->assertSame('/base/base2', $method->invoke($adapter, '/'));
    }

    /**
     * @expectedException CM_Exception
     * @expectedExceptionMessage Path is out of filesystem directory
     */
    public function testGetAbsolutePathOutOfFilesystem() {
        $adapter = $this->getMockBuilder('CM_File_Filesystem_Adapter')
            ->setConstructorArgs(array('/base/base2'))->getMockForAbstractClass();
        /** @var CM_File_Filesystem_Adapter $adapter */

        $method = CMTest_TH::getProtectedMethod('CM_File_Filesystem_Adapter', '_getAbsolutePath');
        $method->invoke($adapter, '/..');
    }

    public function testGetRelativePath() {
        $adapter = $this->getMockBuilder('CM_File_Filesystem_Adapter')
            ->setConstructorArgs(array('/base/base2'))->getMockForAbstractClass();
        /** @var CM_File_Filesystem_Adapter $adapter */

        $method = CMTest_TH::getProtectedMethod('CM_File_Filesystem_Adapter', '_getRelativePath');<commit_msg>Add assertion for not ending on slash<commit_after><?php

class CM_File_Filesystem_AdapterTest extends CMTest_TestCase {

    public function testNormalizePath() {
        $adapter = $this->getMockBuilder('CM_File_Filesystem_Adapter')
            ->setConstructorArgs(array('/base/base2/'))->getMockForAbstractClass();
        /** @var CM_File_Filesystem_Adapter $adapter */

        $method = CMTest_TH::getProtectedMethod('CM_File_Filesystem_Adapter', '_normalizePath');
        $this->assertSame('/foo', $method->invoke($adapter, '/foo'));
        $this->assertSame('/foo', $method->invoke($adapter, '/foo/'));
        $this->assertSame('/', $method->invoke($adapter, '/'));
        $this->assertSame('/', $method->invoke($adapter, ''));
        $this->assertSame('/', $method->invoke($adapter, '//'));
        $this->assertSame('/foo/mega', $method->invoke($adapter, '/foo/bar/../mega'));
        $this->assertSame('/', $method->invoke($adapter, '/../..'));
        $this->assertSame('/foo/bar', $method->invoke($adapter, '/foo/./bar'));
        $this->assertSame('/foo/bar', $method->invoke($adapter, '/foo/./bar///'));
        $this->assertSame('/foo', $method->invoke($adapter, '../foo'));
        $this->assertSame('/foo', $method->invoke($adapter, 'foo'));
    }

    public function testGetAbsolutePath() {
        $adapter = $this->getMockBuilder('CM_File_Filesystem_Adapter')
            ->setConstructorArgs(array('/base/base2'))->getMockForAbstractClass();
        /** @var CM_File_Filesystem_Adapter $adapter */

        $method = CMTest_TH::getProtectedMethod('CM_File_Filesystem_Adapter', '_getAbsolutePath');
        $this->assertSame('/base/base2/bar', $method->invoke($adapter, 'bar'));
        $this->assertSame('/base/base2/bar', $method->invoke($adapter, 'bar/'));
        $this->assertSame('/base/base2/foo', $method->invoke($adapter, '/bar/../foo'));
        $this->assertSame('/base/base2/foo', $method->invoke($adapter, 'bar/../foo'));
        $this->assertSame('/base/base2', $method->invoke($adapter, '/'));
    }

    /**
     * @expectedException CM_Exception
     * @expectedExceptionMessage Path is out of filesystem directory
     */
    public function testGetAbsolutePathOutOfFilesystem() {
        $adapter = $this->getMockBuilder('CM_File_Filesystem_Adapter')
            ->setConstructorArgs(array('/base/base2'))->getMockForAbstractClass();
        /** @var CM_File_Filesystem_Adapter $adapter */

        $method = CMTest_TH::getProtectedMethod('CM_File_Filesystem_Adapter', '_getAbsolutePath');
        $method->invoke($adapter, '/..');
    }

    public function testGetRelativePath() {
        $adapter = $this->getMockBuilder('CM_File_Filesystem_Adapter')
            ->setConstructorArgs(array('/base/base2'))->getMockForAbstractClass();
        /** @var CM_File_Filesystem_Adapter $adapter */

        $method = CMTest_TH::getProtectedMethod('CM_File_Filesystem_Adapter', '_getRelativePath');
{'fraction_non_alphanumeric': 0.19539234366880304, 'fraction_numerical': 0.002944742768058202, 'mean_word_length': 3.7483552631578947, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 91, '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': '1209236', 'n_tokens_mistral': 1669, 'n_tokens_neox': 1646, 'n_words': 214}