File: test_chardata.adb

package info (click to toggle)
libxmlada1 1.0-2
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 2,704 kB
  • ctags: 94
  • sloc: ada: 22,582; sh: 1,804; makefile: 142; xml: 140; perl: 128
file content (54 lines) | stat: -rw-r--r-- 1,550 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
with DOM.Core;                 use DOM.Core;
with DOM.Core.Documents;       use DOM.Core.Documents;
with DOM.Core.Nodes;           use DOM.Core.Nodes;
with Sax.Encodings;            use Sax.Encodings;
with Unicode.CES;              use Unicode.CES;
with Unicode.CES.Basic_8bit;   use Unicode.CES.Basic_8bit;
with DOM.Core.Character_Datas; use DOM.Core.Character_Datas;

with Ada.Text_IO; use Ada.Text_IO;

procedure Test_Chardata is

   function "-" (Str : String) return Byte_Sequence;
   procedure Expect (Got, Expected : DOM_String);

   ---------
   -- Str --
   ---------

   function "-" (Str : String) return Byte_Sequence is
   begin
      return Sax.Encodings.From_Utf32 (Unicode.CES.Basic_8bit.To_Utf32 (Str));
   end "-";

   ------------
   -- Expect --
   ------------

   procedure Expect (Got, Expected : DOM_String) is
   begin
      if Got /= Expected then
         Put_Line ("Expected: --" & Expected & "--");
         Put_Line ("Got     : --" & Got & "--");
      end if;
   end Expect;

   Implementation : DOM_Implementation;
   Doc  : Node;
   Elem : Node;
begin
   Doc := Create_Document (Implementation);
   Elem := Append_Child (Doc, Create_Element (Doc, -"elem"));
   Elem := Append_Child (Elem, Create_Text_Node (Doc, -"Dummy text"));

   Append_Data (Elem, -"appended");
   Expect (Data (Elem), -"Dummy textappended");

   Delete_Data (Elem, 3, 3);
   Expect (Data (Elem), -"Dumtextappended");

   Replace_Data (Elem, 3, 3, -"replaced");
   Expect (Data (Elem), -"Dumreplacedtappended");
   Free (Doc);
end Test_Chardata;