### ----------------------------------------------------
### -- Grammar::Common
### -- Licenses: Artistic-2.0
### -- Authors: Jeffrey Goff
### -- File: t/06-text.rakutest
### ----------------------------------------------------
use Grammar::Common::Text;

use Test;

plan 3;

grammar Sentences does Grammar::Common::Text {
    token TOP { <sentence>+ % \s+ }
}

class Sentences-Actions {
    method TOP ($/) {
	make gather for $/<sentence> -> $sntnc {
	    take ~$sntnc;
	}
    }
}

subtest "Tokens", {
    ok Sentences.subparse("One", rule => 'words'), "Words";
    ok Sentences.subparse("One", rule => 'first-word'), "First word";
    ok Sentences.subparse("One, two, three", rule => 'sub-sentence'),
        "Sub sentence";
}

subtest "Grammar", {
    ok Sentences.parse( "One, two, three."), "Matches sentence";
    my $str =  "One, two, three. Four, five!";
    my $match = Sentences.parse( $str );
    is $match, $str, "Two sentences";
    is $match<sentence>[0].Hash<first-word>, "One", "Tokenized";
    ok Sentences.parse( "Stir-fry garlic until golden-colored, chopped if you so  like, retire if you don't like the color."), "Long sentence";
}

subtest "Actions", {
    my $parsed = Sentences.parse( "One, two, three? Four, five!", actions => Sentences-Actions.new );
    is $parsed.made.elems, 2, "Sentence tokenized";
    is $parsed.made[0], "One, two, three?", "First sentence";
}

# vim: expandtab shiftwidth=4


