<commit_before><?php
declare(strict_types=1);

namespace Tests\Unit\Printer;

use Paraunit\Lifecycle\ProcessEvent;
use Paraunit\Printer\ProcessPrinter;
use Paraunit\Printer\SingleResultFormatter;
use Prophecy\Argument;
use Symfony\Component\Console\Output\Output;
use Tests\BaseUnitTestCase;
use Tests\Stub\StubbedParaunitProcess;
use Tests\Stub\UnformattedOutputStub;

/**
 * Class ProcessPrinterTest
 * @package Tests\Unit\Printer
 */
class ProcessPrinterTest extends BaseUnitTestCase
{
    public function testOnProcessParsingCompletedGoesToFormatting()
    {
        $testResult = $this->mockPrintableTestResult();
        $process = new StubbedParaunitProcess();
        $process->addTestResult($testResult);

        $formatter = $this->prophesize(SingleResultFormatter::class);
        $formatter->formatSingleResult($testResult)
            ->shouldBeCalled()
            ->willReturn('<ok>.</ok>');

        $output = new UnformattedOutputStub();
        $printer = new ProcessPrinter($formatter->reveal(), $output);

        $printer->onProcessParsingCompleted(new ProcessEvent($process));

        $this->assertEquals('<ok>.</ok>', $output->getOutput());
    }

    public function testOnEngineEnd()
    {
        $formatter = $this->prophesize(SingleResultFormatter::class);
        $output = new UnformattedOutputStub();
        $printer = new ProcessPrinter($formatter->reveal(), $output);

        $printer->onEngineEnd();

        $consoleOutput = $output->getOutput();
        $this->assertEquals(ProcessPrinter::MAX_CHAR_LENGTH + 1, strlen($consoleOutput));
        $this->assertStringEndsWith(' 0' . PHP_EOL, $consoleOutput);
    }

    /**
     * @dataProvider newLineTimesProvider
     */
    public function testOnProcessParsingCompletedAddsCounterAndNewlineAtFullRow(int $times, int $newLineTimes)
    {
        $process = new StubbedParaunitProcess();
        for ($i = 0; $i < $times; $i++) {
            $process->addTestResult($this->mockPrintableTestResult());
        }

        $output = $this->prophesize(Output::class);
        $output->write(Argument::any())
            ->shouldBeCalledTimes($times);
        $output->writeln(Argument::that(function ($input) {
            $this->assertEquals(6, strlen($input), 'Wrong output: ' . $input);

            return true;
        }))
            ->willReturn()
            ->shouldBeCalledTimes($newLineTimes);

        $formatter = $this->prophesize(SingleResultFormatter::class);
        $formatter->formatSingleResult(Argument::cetera())
            ->shouldBeCalledTimes($times)
            ->willReturn('<tag>.</tag>');

        $printer = new ProcessPrinter($formatter->reveal(), $output->reveal());

        $printer->onProcessParsingCompleted(new ProcessEvent($process));
    }

    public function newLineTimesProvider(): array
    {
        return [
            [73, 0],
            [74, 0],
            [75, 1],
            [195, 2],
            [222, 2],
            [223, 3],
        ];
    }

    public function testOnProcessParsingCompletedAndOnEngineEndWorkWellTogether()
    {
        $process = new StubbedParaunitProcess();
        for ($i = 0; $i < 100; $i++) {
            $process->addTestResult($this->mockPrintableTestResult());
        }

        $formatter = $this->prophesize(SingleResultFormatter::class);
        $formatter->formatSingleResult(Argument::cetera())
            ->shouldBeCalledTimes(100)
            ->willReturn('.');

        $output = new UnformattedOutputStub();
        $printer = new ProcessPrinter($formatter->reveal(), $output);

        $printer->onProcessParsingCompleted(new ProcessEvent($process));
        $printer->onEngineEnd();

        $expectedOutput = str_repeat('.', 74) . '    74' . PHP_EOL
            . str_repeat('.', 26)
            . str_repeat(' ', ProcessPrinter::MAX_CHAR_LENGTH - (26 + 3))
            . '100' . PHP_EOL;
        $this->assertSame($expectedOutput, $output->getOutput());
    }
}<commit_msg>Try to fix Appveyor build with non-specific line endings<commit_after><?php
declare(strict_types=1);

namespace Tests\Unit\Printer;

use Paraunit\Lifecycle\ProcessEvent;
use Paraunit\Printer\ProcessPrinter;
use Paraunit\Printer\SingleResultFormatter;
use Prophecy\Argument;
use Symfony\Component\Console\Output\Output;
use Tests\BaseUnitTestCase;
use Tests\Stub\StubbedParaunitProcess;
use Tests\Stub\UnformattedOutputStub;

/**
 * Class ProcessPrinterTest
 * @package Tests\Unit\Printer
 */
class ProcessPrinterTest extends BaseUnitTestCase
{
    public function testOnProcessParsingCompletedGoesToFormatting()
    {
        $testResult = $this->mockPrintableTestResult();
        $process = new StubbedParaunitProcess();
        $process->addTestResult($testResult);

        $formatter = $this->prophesize(SingleResultFormatter::class);
        $formatter->formatSingleResult($testResult)
            ->shouldBeCalled()
            ->willReturn('<ok>.</ok>');

        $output = new UnformattedOutputStub();
        $printer = new ProcessPrinter($formatter->reveal(), $output);

        $printer->onProcessParsingCompleted(new ProcessEvent($process));

        $this->assertEquals('<ok>.</ok>', $output->getOutput());
    }

    public function testOnEngineEnd()
    {
        $formatter = $this->prophesize(SingleResultFormatter::class);
        $output = new UnformattedOutputStub();
        $printer = new ProcessPrinter($formatter->reveal(), $output);

        $printer->onEngineEnd();

        $consoleOutput = $output->getOutput();
        $this->assertEquals(ProcessPrinter::MAX_CHAR_LENGTH + 1, strlen($consoleOutput));
        $this->assertStringEndsWith(" 0\n", $consoleOutput);
    }

    /**
     * @dataProvider newLineTimesProvider
     */
    public function testOnProcessParsingCompletedAddsCounterAndNewlineAtFullRow(int $times, int $newLineTimes)
    {
        $process = new StubbedParaunitProcess();
        for ($i = 0; $i < $times; $i++) {
            $process->addTestResult($this->mockPrintableTestResult());
        }

        $output = $this->prophesize(Output::class);
        $output->write(Argument::any())
            ->shouldBeCalledTimes($times);
        $output->writeln(Argument::that(function ($input) {
            $this->assertEquals(6, strlen($input), 'Wrong output: ' . $input);

            return true;
        }))
            ->willReturn()
            ->shouldBeCalledTimes($newLineTimes);

        $formatter = $this->prophesize(SingleResultFormatter::class);
        $formatter->formatSingleResult(Argument::cetera())
            ->shouldBeCalledTimes($times)
            ->willReturn('<tag>.</tag>');

        $printer = new ProcessPrinter($formatter->reveal(), $output->reveal());

        $printer->onProcessParsingCompleted(new ProcessEvent($process));
    }

    public function newLineTimesProvider(): array
    {
        return [
            [73, 0],
            [74, 0],
            [75, 1],
            [195, 2],
            [222, 2],
            [223, 3],
        ];
    }

    public function testOnProcessParsingCompletedAndOnEngineEndWorkWellTogether()
    {
        $process = new StubbedParaunitProcess();
        for ($i = 0; $i < 100; $i++) {
            $process->addTestResult($this->mockPrintableTestResult());
        }

        $formatter = $this->prophesize(SingleResultFormatter::class);
        $formatter->formatSingleResult(Argument::cetera())
            ->shouldBeCalledTimes(100)
            ->willReturn('.');

        $output = new UnformattedOutputStub();
        $printer = new ProcessPrinter($formatter->reveal(), $output);

        $printer->onProcessParsingCompleted(new ProcessEvent($process));
        $printer->onEngineEnd();

        $expectedOutput = str_repeat('.', 74) . '    74' . "\n"
            . str_repeat('.', 26)
            . str_repeat(' ', ProcessPrinter::MAX_CHAR_LENGTH - (26 + 3))
            . '100' . "\n";
        $this->assertSame($expectedOutput, $output->getOutput());
    }
}
{'fraction_non_alphanumeric': 0.14407952686548384, 'fraction_numerical': 0.011325028312570781, 'mean_word_length': 2.9075712881022615, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 101, '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': '7237449', 'n_tokens_mistral': 2351, 'n_tokens_neox': 2232, 'n_words': 365}