<commit_before><?php

namespace Spatie\YamlFrontMatter\Tests;

use Spatie\YamlFrontMatter\Document;
use Spatie\YamlFrontMatter\YamlFrontMatter;
use PHPUnit\Framework\TestCase;

class YamlFrontMatterMarkdownCompatibleParseTest extends TestCase
{
    /** @test */
    public function it_can_parse_simple_front_matter_from_a_file()
    {
        $document = YamlFrontMatter::markdownCompatibleParse(
            file_get_contents(__DIR__.'/document.md')
        );

        $this->assertInstanceOf(Document::class, $document);
        $this->assertEquals(['foo' => 'bar'], $document->matter());
        $this->assertStringContainsString('Lorem ipsum.', $document->body());
    }

    /** @test */
    public function it_can_parse_complex_front_matter_from_a_file()
    {
        $document = YamlFrontMatter::markdownCompatibleParse(
            file_get_contents(__DIR__.'/meta-document.md')
        );

        $this->assertInstanceOf(Document::class, $document);
        $this->assertEquals(['foo' => 'bar'], $document->matter());
        $this->assertStringContainsString('Lorem ipsum.', $document->body());
    }
    
    /** @test */
    public function it_separates_the_front_matter_from_the_body()
    {
        $document = YamlFrontMatter::markdownCompatibleParse(
           "---\ntitle: Front Matter\n---\n\nLorem ipsum."
        );

        $this->assertInstanceOf(Document::class, $document);

        // This implicitly asserts that the front matter does not contain any markdown
        $this->assertEquals(['title' => 'Front Matter'], $document->matter());
        // This implicitly asserts that the body does not contain any front matter remnants
        $this->assertEquals('Lorem ipsum.', $document->body());
    }
       
    /** @test */
    public function it_leaves_string_without_front_matter_intact()
    {
        $document = YamlFrontMatter::markdownCompatibleParse(
            "Lorem ipsum."
        ); 

        $this->assertInstanceOf(Document::class, $document);
        $this->assertEmpty($document->matter());
        $this->assertEquals('Lorem ipsum.', $document->body());
    }

    /** @test */
    public function it_can_parse_a_file_partial_front_matter()
    {
        // If there is only one YAML control block, (---) the front matter is invalid
        // and the document should be interpreted as having no front matter.

        $document = YamlFrontMatter::markdownCompatibleParse(
           "---\ntitle: Front Matter\n\nLorem ipsum."
        );

        $this->assertInstanceOf(Document::class, $document);
        $this->assertEmpty($document->matter());
        $this->assertEquals("---\ntitle: Front Matter\n\nLorem ipsum.", $document->body());
    }
}<commit_msg>Add test for differing end of line characters<commit_after><?php

namespace Spatie\YamlFrontMatter\Tests;

use Spatie\YamlFrontMatter\Document;
use Spatie\YamlFrontMatter\YamlFrontMatter;
use PHPUnit\Framework\TestCase;

class YamlFrontMatterMarkdownCompatibleParseTest extends TestCase
{
    /** @test */
    public function it_can_parse_simple_front_matter_from_a_file()
    {
        $document = YamlFrontMatter::markdownCompatibleParse(
            file_get_contents(__DIR__.'/document.md')
        );

        $this->assertInstanceOf(Document::class, $document);
        $this->assertEquals(['foo' => 'bar'], $document->matter());
        $this->assertStringContainsString('Lorem ipsum.', $document->body());
    }

    /** @test */
    public function it_can_parse_complex_front_matter_from_a_file()
    {
        $document = YamlFrontMatter::markdownCompatibleParse(
            file_get_contents(__DIR__.'/meta-document.md')
        );

        $this->assertInstanceOf(Document::class, $document);
        $this->assertEquals(['foo' => 'bar'], $document->matter());
        $this->assertStringContainsString('Lorem ipsum.', $document->body());
    }

    /** @test */
    public function it_separates_the_front_matter_from_the_body()
    {
        $document = YamlFrontMatter::markdownCompatibleParse(
           "---\ntitle: Front Matter\n---\n\nLorem ipsum."
        );

        $this->assertInstanceOf(Document::class, $document);

        // This implicitly asserts that the front matter does not contain any markdown
        $this->assertEquals(['title' => 'Front Matter'], $document->matter());
        // This implicitly asserts that the body does not contain any front matter remnants
        $this->assertEquals('Lorem ipsum.', $document->body());
    }

    /** @test */
    public function it_leaves_string_without_front_matter_intact()
    {
        $document = YamlFrontMatter::markdownCompatibleParse(
            "Lorem ipsum."
        );

        $this->assertInstanceOf(Document::class, $document);
        $this->assertEmpty($document->matter());
        $this->assertEquals('Lorem ipsum.', $document->body());
    }

    /** @test */
    public function it_can_parse_a_file_partial_front_matter()
    {
        // If there is only one YAML control block, (---) the front matter is invalid
        // and the document should be interpreted as having no front matter.

        $document = YamlFrontMatter::markdownCompatibleParse(
           "---\ntitle: Front Matter\n\nLorem ipsum."
        );

        $this->assertInstanceOf(Document::class, $document);
        $this->assertEmpty($document->matter());
        $this->assertEquals("---\ntitle: Front Matter\n\nLorem ipsum.", $document->body());
    }

    /** @test */
    public function it_can_parse_a_string_with_unix_line_endings()
    {
        $document = YamlFrontMatter::markdownCompatibleParse(
           "---\nfoo: bar\n---\n\nLorem ipsum."
        );

        $this->assertInstanceOf(Document::class, $document);
        $this->assertEquals(['foo' => 'bar'], $document->matter());
        $this->assertStringContainsString('Lorem ipsum.', $document->body());
    }

    /** @test */
    public function it_can_parse_a_string_with_windows_line_endings()
    {
        $document = YamlFrontMatter::markdownCompatibleParse(
           "---\r\nfoo: bar\r\n---\r\n\r\nLorem ipsum."
        );

        $this->assertInstanceOf(Document::class, $document);
        $this->assertEquals(['foo' => 'bar'], $document->matter());
        $this->assertStringContainsString('Lorem ipsum.', $document->body());
    }
}
{'fraction_non_alphanumeric': 0.143695479777954, 'fraction_numerical': 0.0, 'mean_word_length': 3.0319693094629154, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 71, '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': '4148674', 'n_tokens_mistral': 1867, 'n_tokens_neox': 1791, 'n_words': 327}