<?php

declare(strict_types=1);
namespace Tests\git2;
use git2\git;
use git2\git_buf;
use git2\git_message_trailer_array;

final class MessageTest extends GitTestCase
{

	public function testPrettify(): void
	{
		$message = "foo\n\n#comment\nbar  ";
		$this->assertOK(git::message_prettify($buf, $message, true, '#'));
		$this->assertInstanceOf(git_buf::class, $buf);
		$this->assertSame("foo\n\nbar\n", (string) $buf);
		$this->assertOK(git::message_prettify($buf2, $message, false));
		$this->assertSame("foo\n\n#comment\nbar\n", (string) $buf2);
	}

	public function testTrailers(): void
	{
		$this->assertOK(git::message_trailers($arr, "foo\n\nfoo: bar\nbar: foo\n"));
		$this->assertInstanceOf(git_message_trailer_array::class, $arr);
		$this->assertCount(2, $arr);
		$this->assertSame('foo', $arr[0]->key);
		$this->assertSame('bar', $arr[0]->value);
		$this->assertSame('bar', $arr[1]->key);
		$this->assertSame('foo', $arr[1]->value);
	}

}