<commit_before><?php
use \Wordpress\ShortcodeTree;

class ShortcodeTreeTest extends \PHPUnit\Framework\TestCase
{
    public function test_readmeExampleShouldWork()
    {
        add_shortcode('folder', null);
        add_shortcode('document', null);

        $post_content = '
        [folder name="SampleFolder"]
            [document type="image/png" size="64000" path="/path/to/image.png" name="File 1"]
            [document type="image/png" size="64000" path="/path/to/image.png" name="File 2"]
            [folder name="SampleFolder2"]
            [document type="image/png" size="64000" path="/path/to/image.png" name="File 3"]
            [document type="image/png" size="64000" path="/path/to/image.png" name="File 4"]
            [/folder]
        [/folder]
        ';

        $expected_content = '[folder name="SampleFolder"][document type="image/png" size="64000" path="/path/to/image.png" name="My File 1"][document type="image/png" size="64000" path="/path/to/image.png" name="My File 2"][folder name="SampleFolder2"][document type="image/png" size="64000" path="/path/to/image.png" name="My File 3"][document type="image/png" size="64000" path="/path/to/image.png" name="My File 4"][/folder]';

        $content = ShortcodeTree::fromString ( $post_content );
        $folder = $content->getRoot ();

        $documents = $folder->findAll('document');

        // Prepend 'My ' to filename
        foreach($documents as $doc) {
            $doc->attr('name', 'My ' . $doc->attr('name'));
        }
        
        $this->assertEquals($expected_content, $content);
    }
}<commit_msg>added tests for unematiii/wp-shortcode-tree#4 and unematiii/wp-shortcode-tree#5<commit_after><?php
use \Wordpress\ShortcodeTree;

class ShortcodeTreeTest extends \PHPUnit\Framework\TestCase
{
    public function test_readmeExampleShouldWork()
    {
        add_shortcode('folder', null);
        add_shortcode('document', null);

        $post_content = '
        [folder name="SampleFolder"]
            [document type="image/png" size="64000" path="/path/to/image.png" name="File 1"]
            [document type="image/png" size="64000" path="/path/to/image.png" name="File 2"]
            [folder name="SampleFolder2"]
            [document type="image/png" size="64000" path="/path/to/image.png" name="File 3"]
            [document type="image/png" size="64000" path="/path/to/image.png" name="File 4"]
            [/folder]
        [/folder]
        ';

        $expected_content = '[folder name="SampleFolder"][document type="image/png" size="64000" path="/path/to/image.png" name="My File 1"][document type="image/png" size="64000" path="/path/to/image.png" name="My File 2"][folder name="SampleFolder2"][document type="image/png" size="64000" path="/path/to/image.png" name="My File 3"][document type="image/png" size="64000" path="/path/to/image.png" name="My File 4"][/folder]';

        $content = ShortcodeTree::fromString ( $post_content );
        $folder = $content->getRoot ();

        $documents = $folder->findAll('document');

        // Prepend 'My ' to filename
        foreach($documents as $doc) {
            $doc->attr('name', 'My ' . $doc->attr('name'));
        }
        
        $this->assertEquals($expected_content, $content);
    }

    public function test_immediatelyClosedEmptyTagsShouldWork() {
        add_shortcode('av_tab_section', null);
        add_shortcode('av_tab_sub_section', null);
        add_shortcode('custom_sc', null);

        $post_content = "[av_tab_section][av_tab_sub_section][custom_sc foo='bar'][/custom_sc][custom_sc][/custom_sc][/av_tab_sub_section][av_tab_section]";
        $expected_content = '[av_tab_section][av_tab_sub_section][custom_sc foo="bar"][/custom_sc][custom_sc][/custom_sc][/av_tab_sub_section][av_tab_section]';

        $content = ShortcodeTree::fromString ( $post_content );

        $this->assertEquals($expected_content, (string)$content);   
    }

    public function test_keyOnlyAttributesShouldWork() {
        add_shortcode('av_one_third', null);

        $post_content = "[av_one_third first min_height='']";
        $expected_content = '[av_one_third first min_height=""]';

        $content = ShortcodeTree::fromString ( $post_content );

        $this->assertEquals($expected_content, (string)$content);   
    }
}
{'fraction_non_alphanumeric': 0.1672085462145843, 'fraction_numerical': 0.023687877380399444, 'mean_word_length': 3.403885480572597, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, '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': '3192526', 'n_tokens_mistral': 1405, 'n_tokens_neox': 1311, 'n_words': 227}