Natools

Check-in [4b6433de7a]
Login
Overview
Comment:string_slice_tests: test the new callback-based constructor
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 4b6433de7a0cac740b0cbeaffd89454482f3a667
User & Date: nat on 2017-06-15 19:23:50
Other Links: manifest | tags
Context
2017-06-16
21:17
tools/smaz: remove debug trace left over check-in: fe798b80fc user: nat tags: trunk
2017-06-15
19:23
string_slice_tests: test the new callback-based constructor check-in: 4b6433de7a user: nat tags: trunk
2017-06-14
20:58
string_slices: new callback-based constructor check-in: cd40fb63c6 user: nat tags: trunk
Changes

Modified tests/natools-string_slice_tests.adb from [bab2542056] to [396b4e2586].

1
2
3
4
5
6
7
8
9
------------------------------------------------------------------------------
-- Copyright (c) 2013, Natacha Porté                                        --
--                                                                          --
-- Permission to use, copy, modify, and distribute this software for any    --
-- purpose with or without fee is hereby granted, provided that the above   --
-- copyright notice and this permission notice appear in all copies.        --
--                                                                          --
-- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES --
-- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF         --

|







1
2
3
4
5
6
7
8
9
------------------------------------------------------------------------------
-- Copyright (c) 2013-2017, Natacha Porté                                   --
--                                                                          --
-- Permission to use, copy, modify, and distribute this software for any    --
-- purpose with or without fee is hereby granted, provided that the above   --
-- copyright notice and this permission notice appear in all copies.        --
--                                                                          --
-- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES --
-- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF         --
76
77
78
79
80
81
82

83
84
85
86
87
88
89
      Test_Conversions (Report);
      Test_Extensions (Report);
      Test_Incoming_Range (Report);
      Test_Invalid_Extensions (Report);
      Test_Null_Slice (Report);
      Test_Outgoing_Range (Report);
      Test_Subslices (Report);

   end Slice_Tests;



   ----------------------
   -- Individual tests --
   ----------------------







>







76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
      Test_Conversions (Report);
      Test_Extensions (Report);
      Test_Incoming_Range (Report);
      Test_Invalid_Extensions (Report);
      Test_Null_Slice (Report);
      Test_Outgoing_Range (Report);
      Test_Subslices (Report);
      Test_New_Slice (Report);
   end Slice_Tests;



   ----------------------
   -- Individual tests --
   ----------------------
454
455
456
457
458
459
460






































































461
462
463
464
465
466
467
      if Result then
         Report.Item (Name, NT.Success);
      end if;
   exception
      when Error : others => Report.Report_Exception (Name, Error);
   end Test_Is_Subrange;








































































   procedure Test_Null_Slice (Report : in out NT.Reporter'Class) is
      procedure Check_Null (S : in String);

      Name : constant String := "Null slice to empty string";
      Result : Boolean := True;








>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
      if Result then
         Report.Item (Name, NT.Success);
      end if;
   exception
      when Error : others => Report.Report_Exception (Name, Error);
   end Test_Is_Subrange;


   procedure Test_New_Slice (Report : in out NT.Reporter'Class) is
      Name : constant String := "Callback-based constructor";
      First : constant Positive := 42;
      Last : constant Natural := First + Name'Length - 1;
      Result : Boolean := True;

      procedure Initialize (S : out String);

      procedure Initialize (S : out String) is
      begin
         S := Name;
      end Initialize;
   begin
      declare
         Slice : constant String_Slices.Slice
           := String_Slices.New_Slice (First, Last, Initialize'Access);
      begin
         if Slice.First /= First then
            if Result then
               Report.Item (Name, NT.Fail);
            end if;

            Report.Info ("Incorrect value"
              & Integer'Image (Slice.First) & " for Slice.First, expected"
              & Integer'Image (First));
            Result := False;
         end if;

         if Slice.Last /= Last then
            if Result then
               Report.Item (Name, NT.Fail);
            end if;

            Report.Info ("Incorrect value"
              & Integer'Image (Slice.Last) & " for Slice.Last, expected"
              & Integer'Image (Last));
            Result := False;
         end if;

         if Slice.Length /= Name'Length then
            if Result then
               Report.Item (Name, NT.Fail);
            end if;

            Report.Info ("Incorrect value"
              & Integer'Image (Slice.Length) & " for Slice.Length, expected"
              & Integer'Image (Name'Length));
            Result := False;
         end if;

         if Slice.To_String /= Name then
            if Result then
               Report.Item (Name, NT.Fail);
            end if;

            Report.Info ("Incorrect string """
              & Integer'Image (Slice.Length) & """ in Slice, expected """
              & Name & '"');
            Result := False;
         end if;
      end;

      if Result then
         Report.Item (Name, NT.Success);
      end if;
   exception
      when Error : others => Report.Report_Exception (Name, Error);
   end Test_New_Slice;


   procedure Test_Null_Slice (Report : in out NT.Reporter'Class) is
      procedure Check_Null (S : in String);

      Name : constant String := "Null slice to empty string";
      Result : Boolean := True;

Modified tests/natools-string_slice_tests.ads from [963c091de4] to [eb40299070].

1
2
3
4
5
6
7
8
9
------------------------------------------------------------------------------
-- Copyright (c) 2013, Natacha Porté                                        --
--                                                                          --
-- Permission to use, copy, modify, and distribute this software for any    --
-- purpose with or without fee is hereby granted, provided that the above   --
-- copyright notice and this permission notice appear in all copies.        --
--                                                                          --
-- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES --
-- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF         --

|







1
2
3
4
5
6
7
8
9
------------------------------------------------------------------------------
-- Copyright (c) 2013-2017, Natacha Porté                                   --
--                                                                          --
-- Permission to use, copy, modify, and distribute this software for any    --
-- purpose with or without fee is hereby granted, provided that the above   --
-- copyright notice and this permission notice appear in all copies.        --
--                                                                          --
-- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES --
-- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF         --
36
37
38
39
40
41
42

43
44
45
46
47
48
   procedure Test_Set_Length (Report : in out NT.Reporter'Class);

   procedure Test_Conversions (Report : in out NT.Reporter'Class);
   procedure Test_Extensions (Report : in out NT.Reporter'Class);
   procedure Test_Incoming_Range (Report : in out NT.Reporter'Class);
   procedure Test_Invalid_Extensions (Report : in out NT.Reporter'Class);
   procedure Test_Invalid_Subslices (Report : in out NT.Reporter'Class);

   procedure Test_Null_Slice (Report : in out NT.Reporter'Class);
   procedure Test_Outgoing_Range (Report : in out NT.Reporter'Class);
   procedure Test_Slice_Relations (Report : in out NT.Reporter'Class);
   procedure Test_Subslices (Report : in out NT.Reporter'Class);

end Natools.String_Slice_Tests;







>






36
37
38
39
40
41
42
43
44
45
46
47
48
49
   procedure Test_Set_Length (Report : in out NT.Reporter'Class);

   procedure Test_Conversions (Report : in out NT.Reporter'Class);
   procedure Test_Extensions (Report : in out NT.Reporter'Class);
   procedure Test_Incoming_Range (Report : in out NT.Reporter'Class);
   procedure Test_Invalid_Extensions (Report : in out NT.Reporter'Class);
   procedure Test_Invalid_Subslices (Report : in out NT.Reporter'Class);
   procedure Test_New_Slice (Report : in out NT.Reporter'Class);
   procedure Test_Null_Slice (Report : in out NT.Reporter'Class);
   procedure Test_Outgoing_Range (Report : in out NT.Reporter'Class);
   procedure Test_Slice_Relations (Report : in out NT.Reporter'Class);
   procedure Test_Subslices (Report : in out NT.Reporter'Class);

end Natools.String_Slice_Tests;