### ----------------------------------------------------
### -- Markdown::Grammar
### -- Licenses: Artistic-2.0
### -- Authors: Anton Antonov
### -- File: t/05-Raku-section-tree.rakutest
### ----------------------------------------------------
use v6.d;

use lib '.';
use lib './lib';

use Markdown::Grammar;

use Test;

plan *;

## 1
my $text1 = q:to/END/;
# A

## B

This is some food
for thought.

## C

That

## D

Other

END

ok md-section-tree($text1);

## 2
isa-ok md-section-tree($text1).all ~~ Pair, True;

## 3
is-deeply
        md-section-tree($text1).Hash,
        ${ :A($[(Whatever) => (),
                :B((${ :content("\nThis is some food\nfor thought.\n\n"), :level(7), :name(Whatever), :type("md-text-block") },)),
                :C((${ :content("\nThat\n\n"), :level(7), :name(Whatever), :type("md-text-block") },)),
                :D((${ :content("\nOther\n\n"), :level(7), :name(Whatever), :type("md-text-block") },))]) },
        'Expected Hash for simple Markdown text';

## 4
is-deeply
        md-section-tree($text1, modifier => 'text').Hash,
        ${ :A($[(Whatever) => "", :B("\nThis is some food\nfor thought.\n\n"), :C("\nThat\n\n"), :D("\nOther\n\n")]) },
        "Expected Hash for simple Markdown text with modifier 'text'";

## 5
my $text5 = q:to/END/;
# A
## B
```perl6
my $obj = 1 + π;
```

## C

```raku
1_000 + 23
```
END

is-deeply
        md-section-tree($text5, modifier => 'code').Hash,
        ${ :A($[:B(['my $obj = 1 + π;',]), :C(['1_000 + 23',])]) },
        "Expected Hash for simple Markdown text with modifier 'code'";

## 6
is-deeply
        md-section-tree($text5, modifier => 'lang-code').Hash,
        ${:A($[:B([:perl6("my \$obj = 1 + π;")]), :C([:raku("1_000 + 23")])])},
        "Expected Hash for simple Markdown text with modifier 'lang-code'";

## 7
is-deeply
        md-section-tree($text5, modifier => 'code-block').Hash,
        ${:A($[:B(["```perl6\nmy \$obj = 1 + π;\n```"]), :C(["```raku\n1_000 + 23\n```"])])},
        "Expected Hash for simple Markdown text with modifier 'code-block'";

## 8
is-deeply
        md-section-tree(
                $text5,
                max-level => 1,
                modifier => { $_.grep({ $_<type> ∈ <md-header2 md-header3> }).map(*<content>).Array }).Hash,
        ${:A($["## B\n", "## C\n"])},
        "Expected Hash for simple Markdown text with modifier 'code-block'";

## 9
my $text9 = q:to/END/;
Here is data wrangling code:

    obj = dfTitanic;
    obj = GroupBy[ obj, #["passengerSex"]& ];
    Echo[Map[ Length, obj], "counts:"]

## References
TBD...
END

is-deeply
        md-section-tree($text9, modifier => 'code'),
        $["\n    obj = dfTitanic;\n    obj = GroupBy[ obj, #[\"passengerSex\"]\& ];\n    Echo[Map[ Length, obj], \"counts:\"]\n\n"],
        "Expected Hash for indented code block with modifier 'code'";


done-testing;


