### ----------------------------------------------------
### -- Grammar::TokenProcessing
### -- Licenses: Artistic-2.0
### -- Authors: Anton Antonov
### -- File: xt/03-comprehensive-token-definitions-random-sentence-generation.rakutest
### ----------------------------------------------------
use v6.d;
use Test;

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

use Chemistry::Stoichiometry::Grammar;
use DSL::English::DataQueryWorkflows::Grammar;

use Grammar::TokenProcessing;

plan 3;

##-----------------------------------------------------------
## 1
##-----------------------------------------------------------
my $grammar1 = grammar Parser {
    rule  TOP  { I <love> <lang> }
    token love { '♥' | love }
    token lang { < Raku Perl Rust Go Python Ruby > }
}

my %rules1 = $grammar1.^method_table;

my @allSentences1 = (( 'I' X <♥ love>.Array) X <Raku Perl Rust Go Python Ruby>.Array).map(*.flat.join(' '));

ok random-sentence-generation('TOP', %rules1) ∈ @allSentences1;


##-----------------------------------------------------------
## 2
##-----------------------------------------------------------
is random-sentence-generation($grammar1) ∈ @allSentences1, True;


##-----------------------------------------------------------
## 3
##-----------------------------------------------------------
grammar ISBN {
    token TOP {  <tenner>  |  <niner-xray>  }
    token tenner     { [ <digit> <:Pd> ? ] ** 10   }
    token niner-xray { [ <digit> <:Pd> ? ] **  9 X }
}

ok random-sentence-generation(ISBN);


done-testing;


