### ----------------------------------------------------
### -- FunctionalParsers
### -- Licenses: Artistic-2.0
### -- Authors: Anton Antonov
### -- File: t/16-random-sentence.rakutest
### ----------------------------------------------------
use v6.d;

use FunctionalParsers::EBNF;
use Test;

plan *;

##===========================================================
## 1
##===========================================================
my $ebnfCode1 = "
<top> = 'a' , 'b' , 'c' ;
";

## 1
is-deeply fp-random-sentence($ebnfCode1), ("a b c",), 'Comma separated';

##===========================================================
## 2
##===========================================================
my $ebnfCode2 = "
<top> = 'a' <& 'b' <& 'c' ;
";

## 2
is-deeply fp-random-sentence($ebnfCode2), ("a b c",), 'Left pick separated';


##===========================================================
## 3
##===========================================================
my $ebnfCode3 = "
<top> = 'a' &> 'b' &> 'c' ;
";

is-deeply fp-random-sentence($ebnfCode3), ("a b c",), 'Right pick separated';

##===========================================================
## 4
##===========================================================
my $ebnfCode4 = "
<top> = 'a' &> 'b' , 'c' ;
";

is-deeply fp-random-sentence($ebnfCode4), ("a b c",), 'Mix pick separated, a-c';

##===========================================================
## 5
##===========================================================
my $ebnfCode5 = "
<top> = 'a' &> 'b' , 'c' <& 'd' <& 'e';
";

is-deeply fp-random-sentence($ebnfCode5), ("a b c d e",), 'Mix pick separated, a-e';

##===========================================================
## 6
##===========================================================
my $ebnfCode6 = "
<top> = <a> , <b> , <c>;
<a> = 'a' | 'A' ;
<b> = 'b' | 'B' ;
<c> = 'c' | 'C' ;
";

is 'a B C' (elem) fp-random-sentence($ebnfCode6, 120).List,
        True,
        'Variaties, a-c, A-C';

##===========================================================
## 7
##===========================================================
my $ebnfCode7 = "
<top> = 'Range[10, 14] | Range[0,88]';
";

is '10' (elem) fp-random-sentence($ebnfCode7, 120).List,
        True,
        'Range[10, 14]';


##===========================================================
## 8
##===========================================================
my $ebnfCode8 = "
<top> = '_WordString' | '_LetterString' | '_IdentifierString';
";

is fp-random-sentence($ebnfCode8, 12).all ~~ Str,
        True,
        '_WordString | _LetterString | _IdentifierString';


##===========================================================
## 9
##===========================================================
my $ebnfCode9 = "
<top> = '_Integer' ;
";

isa-ok fp-random-sentence($ebnfCode9, 12)>>.Int.sum, Int,
        '_Integer';

##===========================================================
## 10
##===========================================================
my $ebnfCode10 = "
<top> = '_?NumericQ' ;
";

isa-ok fp-random-sentence($ebnfCode10, 12)>>.Num.sum, Num,
        '_?NumericQ';


##===========================================================
## 11
##===========================================================
my $res11 = q:to/END/;
class Random_1688405698_3444304 {
	my BagHash $visits;
	my UInt $maxReps = 4;
	method pTOP { $visits.add('pTOP'); if $visits<pTOP> ≤ $maxReps { ('a', 'b', 'c') } else { Empty }}
	has &.parser is rw = { $visits .= new; self.pTOP };
}
END

is-deeply fp-random-sentence($ebnfCode1, no-value => 'Empty', :!eval).lines[1, *-1],
        $res11.lines[1, *-1],
        'With no-value => Empty';


done-testing;


