### ----------------------------------------------------
### -- Gherkin::Grammar
### -- Licenses: Artistic-2.0
### -- Authors: Anton Antonov
### -- File: resources/Numeric-word-forms-parsing.rakutest
### ----------------------------------------------------
use v6.d;

use Lingua::NumericWordForms;

#============================================================

proto sub Background($descr) {*}
proto sub ScenarioOutline(@cmdFuncPairs) {*}
proto sub Example($descr) {*}
proto sub Given(Str:D $cmd, |) {*}
proto sub When(Str:D $cmd, |) {*}
proto sub Then(Str:D $cmd, |) {*}

#============================================================

use Test;
plan *;

#============================================================
# Example : Small number parsing, English
#------------------------------------------------------------
my $language;

multi sub Given( $cmd where * eq 'language is English' ) {
	$language = 'English';
}

my $result;

multi sub When( $cmd ) {
	$result = from-numeric-word-form($cmd, $language);
}

multi sub Then( $cmd where * ~~ / ^ 'the result is' .* '"' .* / ) {
	if $cmd ~~ / .+? \" ([\d|'_']+) \" .* / {
		return $result == ~$0;
	}
	return False;
}

multi sub Example('Small number parsing, English') {
	Given( 'language is English' );
	When( 'two hundred and thirty eight' );
	Then( 'the result is "238"' );
}

is Example('Small number parsing, English'), True, 'Small number parsing, English';

#============================================================
# Example : Large number parsing, English
#------------------------------------------------------------

multi sub Example('Large number parsing, English') {
	Given( 'language is English' );
	When( 'thirty million one thousand and four hundred and fifty' );
	Then( 'the result is "30_001_450"' );
}

is Example('Large number parsing, English'), True, 'Large number parsing, English';

#============================================================
# Example : Small number parsing, Bulgarian
#------------------------------------------------------------

multi sub Given( $cmd where * eq 'language is Bulgarian' ) {
	$language = 'Bulgarian';
}

multi sub Example('Small number parsing, Bulgarian') {
	Given( 'language is Bulgarian' );
	When( 'двеста тридесет и осем' );
	Then( 'the result is "238"' );
}

is Example('Small number parsing, Bulgarian'), True, 'Small number parsing, Bulgarian';

#============================================================
# Example : Голямо число на Български
#------------------------------------------------------------

multi sub Example('Голямо число на Български') {
	Given( 'language is Bulgarian' );
	When( 'трийсет милиона хиляда четиристотин и петдесет' );
	Then( 'the result is "30_001_450"' );
}

is Example('Голямо число на Български'), True, 'Голямо число на Български';

done-testing;


