--  Verada.Strings.Texts (T30): texts in records, copied, replaced and joined; each copy
--  shares the characters, and the last holder frees them.
with Ada.Text_IO; use Ada.Text_IO;
with Verada.Strings.Texts; use Verada.Strings.Texts;

procedure Main is
   type Person is record
      Name : Text;
      Age  : Natural := 0;
   end record;

   function Greeting (P : Person) return Text is
     (To_Text ("hello, ") & P.Name)
     with Pre => Length (P.Name) < 100,
          Post => Length (Greeting'Result) < 200;

   A : constant Person := (Name => To_Text ("Ann"), Age => 3);
   B : Person := A;
   C : Text;
begin
   B.Name := To_Text ("Bob");
   C := Greeting (A);
   Put_Line (To_String (A.Name) & " " & To_String (B.Name) & " " & To_String (C));
   Put_Line (Natural'Image (Length (C)) & Boolean'Image (A.Name = To_Text ("Ann")));
   for I in 1 .. 3 loop
      pragma Loop_Invariant (Length (C) < 200 + I);
      C := C & To_Text ("!");
   end loop;
   Put_Line (To_String (C));
end Main;
