septum_0.0.7_88e658ca/tests/src/sp-strings-tests.adb

 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
with Ada.Characters.Latin_1;
with Ada.Strings.Unbounded;
with Trendy_Test.Assertions.Integer_Assertions;

package body SP.Strings.Tests is

    package ASU renames Ada.Strings.Unbounded;

    use Trendy_Test.Assertions;
    use Trendy_Test.Assertions.Integer_Assertions;

    function "+" (S : String) return ASU.Unbounded_String renames ASU.To_Unbounded_String;

    procedure Test_String_Split (Op : in out Trendy_Test.Operation'Class) is
        E : Exploded_Line;
    begin
        Op.Register;

        E := Make ("   this   is an     exploded    line  with--content ");

        Assert_EQ (Op, Num_Words (E), 6);
        Assert_EQ (Op, Get_Word (E, 1), "this");
        Assert_EQ (Op, Get_Word (E, 2), "is");
        Assert_EQ (Op, Get_Word (E, 3), "an");
        Assert_EQ (Op, Get_Word (E, 4), "exploded");
        Assert_EQ (Op, Get_Word (E, 5), "line");
        Assert_EQ (Op, Get_Word (E, 6), "with--content");
    end Test_String_Split;

    procedure Test_Is_Quoted (Op : in out Trendy_Test.Operation'Class) is
        use Ada.Characters.Latin_1;
    begin
        Op.Register;

        Assert (Op, not Is_Quoted(""));
        Assert (Op, not Is_Quoted ("not quoted"));

        -- Unbalanced "
        Assert (Op, not Is_Quoted (Quotation & "some text"));
        Assert (Op, not Is_Quoted ("some text" & Quotation));

        -- Unbalanced '
        Assert (Op, not Is_Quoted (Apostrophe & "some text"));
        Assert (Op, not Is_Quoted ("some text" & Apostrophe));

        -- Mismatched ' and "
        Assert (Op, not Is_Quoted (Quotation & "some text" & Apostrophe));
        Assert (Op, not Is_Quoted (Apostrophe & "some text" & Quotation));

        -- Matched " and '
        Assert (Op, Is_Quoted (Apostrophe & "some text" & Apostrophe));
        Assert (Op, Is_Quoted (Quotation & "some text" & Quotation));

        -- Internal " or '
        Assert (Op, Is_Quoted (Apostrophe & Quotation & "some text" & Quotation & Apostrophe));
        Assert (Op, Is_Quoted (Apostrophe & Quotation & "some text" & Quotation & Apostrophe));
    end Test_Is_Quoted;

    procedure Test_Common_Prefix_Length (Op : in out Trendy_Test.Operation'Class) is
        package Trendy_TestI renames Trendy_Test.Assertions.Integer_Assertions;
    begin
        Op.Register;

        Trendy_TestI.Assert_EQ (Op, Common_Prefix_Length(+"", +"SP.Strings"), 0);
        Assert_EQ (Op, Common_Prefix_Length(+"SP.Strings", +""), 0);
        Assert_EQ (Op, Common_Prefix_Length(+"", +""), 0);

        Assert_EQ (Op, Common_Prefix_Length(+"SP.Searches", +"SP.Strings"), 4);
        Assert_EQ (Op, Common_Prefix_Length(+"SP.Strings", +"SP.Strings"), ASU.Length (+"SP.Strings"));
    end Test_Common_Prefix_Length;

    ---------------------------------------------------------------------------
    -- Test Registry
    ---------------------------------------------------------------------------
    function All_Tests return Trendy_Test.Test_Group is (
        Test_String_Split'Access,
        Test_Is_Quoted'Access,
        Test_Common_Prefix_Length'Access
        );

end SP.Strings.Tests;