### ----------------------------------------------------
### -- Gherkin::Grammar
### -- Licenses: Artistic-2.0
### -- Authors: Anton Antonov
### -- File: t/01-Parsing.rakutest
### ----------------------------------------------------
use v6.d;
use Test;

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

use Gherkin::Grammar;

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

plan *;

#-----------------------------------------------------------
## 1
#-----------------------------------------------------------
ok Gherkin::Grammar.parse('Example: Multiple Givens', rule => 'ghk-example-text-line');

#-----------------------------------------------------------
## 2
#-----------------------------------------------------------

my $text2 = q:to/END/;
Feature: Calculation
    Example: One plus one
    When 1 + 1
    Then 2
END

ok gherkin-parse($text2), 'Feature: Calculation';

#-----------------------------------------------------------
## 3
#-----------------------------------------------------------
my $text3 = q:to/END/;
Example: Multiple Givens
  Given one thing
  Given another thing
  Given yet another thing
  When I open my eyes
  Then I should see something
  Then I shouldn't see something else
END

ok gherkin-subparse($text3, rule => 'ghk-example-block');


#-----------------------------------------------------------
## 4
#-----------------------------------------------------------
my $text4 = q:to/END/;
Feature: Highlander
    From the Movie "Highlander" (1986)
    Or the TV series.

  Rule: There can be only One

    Example: Only One -- More than one alive
      Given there are 3 ninjas
      And there are more than one ninja alive
      When 2 ninjas meet, they will fight
      Then one ninja dies (but not me)
      And there is one ninja less alive

    Example: Only One -- One alive
      Given there is only 1 ninja alive
      Then he (or she) will live forever ;-)
END

ok gherkin-subparse($text4);


#-----------------------------------------------------------
## 5
#-----------------------------------------------------------
my $text5 = q:to/END/;
  """
  New block
  ===============
  Here is a paragraph...
  Or two.
  """
END
ok Gherkin::Grammar.parse($text5, rule => 'ghk-doc-string');


#-----------------------------------------------------------
## 6
#-----------------------------------------------------------
my $text6 = q:to/END/;
Given a blog post named "Random" with Markdown body
  """
  New block
  ===============
  Here is a paragraph...
  Or two.
  """
END

ok Gherkin::Grammar.parse($text6, rule => 'ghk-given-block');


#-----------------------------------------------------------
## 7
#-----------------------------------------------------------
my $text7 = q:to/END/;
Feature: Random Markdown
Example: Pass it
Given a blog post named "Random" with Markdown body
  """
  New block
  ===============
  Here is a paragraph...
  Or two.
  """
Then Squish into "MD"
END

ok gherkin-parse($text7);


#-----------------------------------------------------------
## 8
#-----------------------------------------------------------
my $text8 = q:to/END/;
Given Table of company contacts:
  | Company                      | Contact           | Country |
  |------------------------------|-------------------|---------|
  | Alfreds Futterkiste          | Maria Anders      | Germany |
  | Centro comercial Moctezuma   | Francisco Chang   | Mexico  |
  | Ernst Handel                 | Roland Mendel     | Austria |
  | Island Trading               | Helen Bennett     | UK      |
  | Laughing Bacchus Winecellars | Yoshi Tannamuri   | Canada  |
  | Magazzini Alimentari Riuniti | Giovanni Rovelli  | Italy   |

END

ok gherkin-parse($text8, rule => 'ghk-given-block');


#-----------------------------------------------------------
## 9
#-----------------------------------------------------------
my $text9 = q:to/END/;
Given Table datetime specs
      | Spec      | Result                        |
      | today     | DateTime.today                |
      | yesterday | DateTime.today.earlier(:1day) |
      | tomorrow  | DateTime.today.later(:1day)   |
END

ok gherkin-parse($text9, rule => 'ghk-given-block');


#-----------------------------------------------------------
## 10
#-----------------------------------------------------------

my $text10 = q:to/END/;
@calc @arith
Feature: Calculation
    Example: One plus one
    When 1 + 1
    Then 2
END

ok gherkin-parse($text10), 'tagged Feature: Calculation';


#-----------------------------------------------------------
## 11
#-----------------------------------------------------------

my $text11 = q:to/END/;
Scenario Outline: eating
  Given there are <start> cucumbers
  When I eat <eat> cucumbers
  Then I should have <left> cucumbers
  Examples:
    | start | eat | left |
    |    12 |   5 |    7 |
    |    20 |   5 |   15 |
END

ok gherkin-parse($text11, rule => 'ghk-scenario-outline-block'), 'block Scenario Outline: eating';


#-----------------------------------------------------------
## 12
#-----------------------------------------------------------

my $text12 = 'Feature: Comendo pepino' ~ "\n" ~ $text11;
ok gherkin-parse($text12), 'Feature with block Scenario Outline';


done-testing;


