Potential bug in GNAT System.Regexp?

I wonder if i found a Bug in GNATs System.Regexp. Let me explain.

What I did is make a copy of GNATs System.Regexp. My code is GPL so I can do that. Then change the code to be generic. Result is here: adacl-strings-regexp.ads and here adacl-generic_strings-regexp.adb.

Next started to write unit test to ensure that the original and the copy still behave the same. At least for String as my version is now generic and will work for any array of diskrete elements. The tests are here adacl_regexp_test-strings.ads and here adacl_regexp_test-strings.adb

The problem is with test data entry 12:

         T.Parameter.Register_Routine (T, Test_01'Access, "12", "Simple |",       To_I ("T Pattern X",         "T|X Pattern T|X",   False, True),  True);
         T.Parameter.Register_Routine (T, Test_01'Access, "13", "Insensitive |",  To_I ("X PATTERN T",         "t|x pattern t|x",   False, False), True);

The test applying the pattern T|X Pattern T|X to the string T Pattern X which should match. In the actual test I first check if the old and new code get the same result:

      package CL_RegExp renames AdaCL.Strings.RegExp;
      package G_RegExp renames GNAT.RegExp;

      CL_Pattern : constant CL_RegExp.RegExp :=
         CL_RegExp.Compile (Unbounded.To_String (Input.Pattern), Input.Glob, Input.Case_Sensitive);
      G_Pattern  : constant G_RegExp.RegExp  :=
         G_RegExp.Compile (Unbounded.To_String (Input.Pattern), Input.Glob, Input.Case_Sensitive);
      CL_Actual  : constant Boolean          := CL_RegExp.Match (Unbounded.To_String (Input.Source), CL_Pattern);
      G_Actual   : constant Boolean          := G_RegExp.Match (Unbounded.To_String (Input.Source), G_Pattern);
   begin
      Assert_Boolean.Equal
         (Actual   => CL_Actual,
          Expected => G_Actual,
          Name     => "AdaCL = GNAT");

And my code does indeed get the same result. But it’s not the result I’m expecting. Which I test next:

      Assert_Boolean.Equal
         (Actual   => CL_Actual,
          Expected => Expected,
          Name     => "AdaCL Match");
      Assert_Boolean.Equal
         (Actual   => G_Actual,
          Expected => Expected,
          Name     => "GNAT Match");

So either it’s a bug or I misunderstand the regular expression I’m testing. Note test data entry 13, which is the same test but case insensitive does match as expeted.

And ideas what is going on?

I think your regular expression should be “(T|X) Pattern (T|X)”.
See Regex Tutorial - Alternation with The Vertical Bar
Paul

1 Like

Welcome to the forums @Paul921!

1 Like