<commit_before><?php
namespace Neos\Eel\Tests\Unit;

/*
 * This file is part of the Neos.Eel package.
 *
 * (c) Contributors of the Neos Project - www.neos.io
 *
 * This package is Open Source Software. For the full copyright and license
 * information, please view the LICENSE file which was distributed with this
 * source code.
 */

use Neos\Eel\Helper\StringHelper;
use Neos\Eel\Tests\Unit\Fixtures\TestObject;
use Neos\Flow\Tests\UnitTestCase;

/**
 * Tests for StringHelper
 */
class StringHelperTest extends UnitTestCase
{
    public function substrExamples()
    {
        return [
            'positive start and length lower count' => ['Hello, World!', 7, 5, 'World'],
            'start equal to count' => ['Foo', 3, 42, ''],
            'start greater than count' => ['Foo', 42, 5, ''],
            'start negative' => ['Hello, World!', -6, 5, 'World'],
            'start negative larger than abs(count)' => ['Hello, World!', -42, 5, 'Hello'],
            'start positive and length omitted' => ['Hello, World!', 7, null, 'World!'],
            'start positive and length is 0' => ['Hello, World!', 7, 0, ''],
            'start positive and length is negative' => ['Hello, World!', 7, -1, ''],
            'unicode content is extracted' => ['Öaßaä', 2, 1, 'ß']
        ];
    }

    /**
     * @test
     * @dataProvider substrExamples
     */
    public function substrWorks($string, $start, $length, $expected)
    {
        $helper = new StringHelper();
        $result = $helper->substr($string, $start, $length);
        $this->assertSame($expected, $result);
    }

    public function substringExamples()
    {
        return [
            'start equals end' => ['Hello, World!', 7, 7, ''],
            'end omitted' => ['Hello, World!', 7, null, 'World!'],
            'negative start' => ['Hello, World!', -7, null, 'Hello, World!'],
            'negative end' => ['Hello, World!', 5, -5, 'Hello'],
            'start greater than end' => ['Hello, World!', 5, 0, 'Hello'],
            'start greater than count' => ['Hello, World!', 15, 0, 'Hello, World!'],
            'end greater than count' => ['Hello, World!', 7, 15, 'World!'],
            'unicode content is extracted' => ['Öaßaä', 2, 3, 'ß']
        ];
    }

    /**
     * @test
     * @dataProvider substringExamples
     */
    public function substringWorks($string, $start, $end, $expected)
    {
        $helper = new StringHelper();
        $result = $helper->substring($string, $start, $end);
        $this->assertSame($expected, $result);
    }

    public function charAtExamples()
    {
        return [
            'index in string' => ['Hello, World!', 5, ','],
            'index greater than count' => ['Hello, World!', 42, ''],
            'index negative' => ['Hello, World!', -1, ''],
            'unicode content can be accessed' => ['Öaßaü', 2, 'ß']
        ];
    }

    /**
     * @test
     * @dataProvider charAtExamples
     */
    public function charAtWorks($string, $index, $expected)
    {
        $helper = new StringHelper();
        $result = $helper->charAt($string, $index);
        $this->assertSame($expected, $result);
    }

    public function endsWithExamples()
    {
        return [
            'search matched' => ['To be, or not to be, that is the question.', 'question.', null, true],
            'search not matched' => ['To be, or not to be, that is the question.', 'to be', null, false],
            'search with position' => ['To be, or not to be, that is the question.', 'to be', 19, true],
            'unicode content can be searched' => ['Öaßaü', 'aü', null, true]
        ];
    }

    /**
     * @test
     * @dataProvider endsWithExamples
     */
    public function endsWithWorks($string, $search, $position, $expected)
    {
        $helper = new StringHelper();
        $result = $helper->endsWith($string, $search, $position);
        $this->assertSame($expected, $result);
    }

    public function chrExamples()
    {
        return [
            ['value' => 65, 'expected' => 'A'],
            ['value' => 256, 'expected' => chr(256)],
            ['value' => 'not a number', 'expected' => chr('not a number')],
            ['value' => 0, 'expected' => chr(0)],
        ];
    }

    /**
     * @test
     * @dataProvider chrExamples
     */
    public function chrWorks($value, $expected)
    {
        $helper = new StringHelper();
        $result = $helper->chr($value);
        $this->assertSame($expected, $result);
    }

    public function ordExamples()
    {
        return [
            ['value' => 'A', 'expected' => 65],
            ['value' => '', 'expected' => 0],
            ['value' => 1, 'expected' => 49],
            ['value' => 'longer string', 'expected' => 108],
        ];
    }

    /**
     * @test
     * @dataProvider ordExamples
     */
    public function ordWorks($value, $expected)
    {<commit_msg>TASK: PHP 7.4 adjustments<commit_after><?php
namespace Neos\Eel\Tests\Unit;

/*
 * This file is part of the Neos.Eel package.
 *
 * (c) Contributors of the Neos Project - www.neos.io
 *
 * This package is Open Source Software. For the full copyright and license
 * information, please view the LICENSE file which was distributed with this
 * source code.
 */

use Neos\Eel\Helper\StringHelper;
use Neos\Eel\Tests\Unit\Fixtures\TestObject;
use Neos\Flow\Tests\UnitTestCase;

/**
 * Tests for StringHelper
 */
class StringHelperTest extends UnitTestCase
{
    public function substrExamples()
    {
        return [
            'positive start and length lower count' => ['Hello, World!', 7, 5, 'World'],
            'start equal to count' => ['Foo', 3, 42, ''],
            'start greater than count' => ['Foo', 42, 5, ''],
            'start negative' => ['Hello, World!', -6, 5, 'World'],
            'start negative larger than abs(count)' => ['Hello, World!', -42, 5, 'Hello'],
            'start positive and length omitted' => ['Hello, World!', 7, null, 'World!'],
            'start positive and length is 0' => ['Hello, World!', 7, 0, ''],
            'start positive and length is negative' => ['Hello, World!', 7, -1, ''],
            'unicode content is extracted' => ['Öaßaä', 2, 1, 'ß']
        ];
    }

    /**
     * @test
     * @dataProvider substrExamples
     */
    public function substrWorks($string, $start, $length, $expected)
    {
        $helper = new StringHelper();
        $result = $helper->substr($string, $start, $length);
        $this->assertSame($expected, $result);
    }

    public function substringExamples()
    {
        return [
            'start equals end' => ['Hello, World!', 7, 7, ''],
            'end omitted' => ['Hello, World!', 7, null, 'World!'],
            'negative start' => ['Hello, World!', -7, null, 'Hello, World!'],
            'negative end' => ['Hello, World!', 5, -5, 'Hello'],
            'start greater than end' => ['Hello, World!', 5, 0, 'Hello'],
            'start greater than count' => ['Hello, World!', 15, 0, 'Hello, World!'],
            'end greater than count' => ['Hello, World!', 7, 15, 'World!'],
            'unicode content is extracted' => ['Öaßaä', 2, 3, 'ß']
        ];
    }

    /**
     * @test
     * @dataProvider substringExamples
     */
    public function substringWorks($string, $start, $end, $expected)
    {
        $helper = new StringHelper();
        $result = $helper->substring($string, $start, $end);
        $this->assertSame($expected, $result);
    }

    public function charAtExamples()
    {
        return [
            'index in string' => ['Hello, World!', 5, ','],
            'index greater than count' => ['Hello, World!', 42, ''],
            'index negative' => ['Hello, World!', -1, ''],
            'unicode content can be accessed' => ['Öaßaü', 2, 'ß']
        ];
    }

    /**
     * @test
     * @dataProvider charAtExamples
     */
    public function charAtWorks($string, $index, $expected)
    {
        $helper = new StringHelper();
        $result = $helper->charAt($string, $index);
        $this->assertSame($expected, $result);
    }

    public function endsWithExamples()
    {
        return [
            'search matched' => ['To be, or not to be, that is the question.', 'question.', null, true],
            'search not matched' => ['To be, or not to be, that is the question.', 'to be', null, false],
            'search with position' => ['To be, or not to be, that is the question.', 'to be', 19, true],
            'unicode content can be searched' => ['Öaßaü', 'aü', null, true]
        ];
    }

    /**
     * @test
     * @dataProvider endsWithExamples
     */
    public function endsWithWorks($string, $search, $position, $expected)
    {
        $helper = new StringHelper();
        $result = $helper->endsWith($string, $search, $position);
        $this->assertSame($expected, $result);
    }

    public function chrExamples()
    {
        return [
            ['value' => 65, 'expected' => 'A'],
            ['value' => 256, 'expected' => chr(256)],
            ['value' => 0, 'expected' => chr(0)],
        ];
    }

    /**
     * @test
     * @dataProvider chrExamples
     */
    public function chrWorks($value, $expected)
    {
        $helper = new StringHelper();
        $result = $helper->chr($value);
        $this->assertSame($expected, $result);
    }

    public function ordExamples()
    {
        return [
            ['value' => 'A', 'expected' => 65],
            ['value' => '', 'expected' => 0],
            ['value' => 1, 'expected' => 49],
            ['value' => 'longer string', 'expected' => 108],
        ];
    }

    /**
     * @test
     * @dataProvider ordExamples
     */
    public function ordWorks($value, $expected)
    {
{'fraction_non_alphanumeric': 0.1727197688815518, 'fraction_numerical': 0.013206768468840282, 'mean_word_length': 2.2170594092266844, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 103, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '4808162', 'n_tokens_mistral': 3026, 'n_tokens_neox': 2855, 'n_words': 867}