briot / gnatbdd

Behavior Driven Development in Ada
7 stars 4 forks source link

The code generator doesn't pass multiline strings #5

Open Lucretia opened 3 years ago

Lucretia commented 3 years ago

Given the following scenario:

    Scenario: Constructing the PPM header
        Given c ← canvas(5, 3)
        When ppm ← canvas_to_ppm(c)
        Then lines 1-3 of ppm are
            """
            P3
            5 3
            255
            """

With a regexp of:

   -- @then ^lines (\d+)-(\d+) of ppm are$
   procedure Test (Start_Line, End_Line : Positive; Str : String);

Fails to generate with the following error:

Too many parameters (or not enough parenthesis groups) for step
   ^lines (\d+)-(\d+) of ppm are$

Remove the String parameter and it generates, but incorrectly. The multiline string is parsed by gnatbdd, but not passed as an extra parameter at the end of the function.

briot commented 3 years ago

-- @then ^lines (\d+)-(\d+) of ppm are$ procedure Test (Start_Line, End_Line : Positive; Str : String);

Shouldn’t you tell the regexp that you expect a string ?

-- @then ^lines (\d+)-(\d+) of ppm are (.+)$

Lucretia commented 3 years ago

I don't know, your documentation doesn't say.

Lucretia commented 3 years ago

That regexp doesn't match it, neither does:

-- @then ^lines (\d+)-(\d+) of ppm are(.+)$
-- @then ^lines (\d+)-(\d+) of ppm are (.*)$

But this does:

-- @then ^lines (\d+)-(\d+) of ppm are(.*)$

But that doesn't give me a string, my Test function prints it:

   procedure Test (Start_Line, End_Line : Positive; Str : String) is
   begin
      put_line("Str: " & Str);
   end Test;

Results:

gen/debug/.obj/rt_bdd --features=../../src/features/
..Str: 
.............................
briot commented 3 years ago

-- @then ^lines (\d+)-(\d+) of ppm are(.*)$

That will match and empty string at the end indeed. which what you are getting.

Had a quick look at the code, seems like multi-strings are not supported in the code generator (though supported in the parser somewhat)

Lucretia commented 3 years ago

I changed gnatbdd-codegen.adb:484 to

      Append (Data.Regexps,
              "   Re_"
              & Image (Data.Steps_Count, Min_Width => 0)
              & " : constant Pattern_Matcher := Compile" & ASCII.LF
              & "      (""" & Escape (Regexp) & """, Multiple_Lines);" & ASCII.LF);

I can get it to pass, but I'm getting nothing passed to the Str parameter.