summaryrefslogtreecommitdiff
path: root/test/src/CharacterSetTests.cpp
blob: 3663ee689ab02df5cef967a5ebc6d38c9955147f (plain)
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/**
 * @file CharacterSetTests.cpp
 *
 * This module contains the unit tests of the Uri::CharacterSet class.
 *
 * © 2018 by Richard Walters
 */

#include <gtest/gtest.h>
#include <src/CharacterSet.hpp>
#include <utility>
#include <vector>

TEST(CharacterSetTests, DefaultConstructor) {
    Uri::CharacterSet cs;
    for (char c = 0; c < 0x7F; ++c) {
        ASSERT_FALSE(cs.Contains(c));
    }
}

TEST(CharacterSetTests, SingleCharacterConstructor) {
    Uri::CharacterSet cs('X');
    for (char c = 0; c < 0x7F; ++c) {
        if (c == 'X') {
            ASSERT_TRUE(cs.Contains(c));
        } else {
            ASSERT_FALSE(cs.Contains(c));
        }
    }
}

TEST(CharacterSetTests, RangeConstructor) {
    Uri::CharacterSet cs('A', 'G');
    for (char c = 0; c < 0x7F; ++c) {
        if (
            (c >= 'A')
            && (c <= 'G')
        ) {
            ASSERT_TRUE(cs.Contains(c));
        } else {
            ASSERT_FALSE(cs.Contains(c));
        }
    }
}

TEST(CharacterSetTests, Range_Constructor_Reversed) {
    Uri::CharacterSet cs('G', 'A');
    for (char c = 0; c < 0x7F; ++c) {
        if (
            (c >= 'A')
            && (c <= 'G')
        ) {
            ASSERT_TRUE(cs.Contains(c));
        } else {
            ASSERT_FALSE(cs.Contains(c));
        }
    }
}

TEST(CharacterSetTests, InitializerListConstructor) {
    Uri::CharacterSet cs1{'X'};
    for (char c = 0; c < 0x7F; ++c) {
        if (c == 'X') {
            ASSERT_TRUE(cs1.Contains(c));
        } else {
            ASSERT_FALSE(cs1.Contains(c));
        }
    }
    Uri::CharacterSet cs2{'A', 'G'};
    for (char c = 0; c < 0x7F; ++c) {
        if (
            (c == 'A')
            || (c == 'G')
        ) {
            ASSERT_TRUE(cs2.Contains(c));
        } else {
            ASSERT_FALSE(cs2.Contains(c));
        }
    }
    Uri::CharacterSet cs3{Uri::CharacterSet('f', 'i')};
    for (char c = 0; c < 0x7F; ++c) {
        if (
            (c >= 'f')
            && (c <= 'i')
        ) {
            ASSERT_TRUE(cs3.Contains(c));
        } else {
            ASSERT_FALSE(cs3.Contains(c));
        }
    }
    Uri::CharacterSet cs4{Uri::CharacterSet('a', 'c'), Uri::CharacterSet('f', 'i')};
    for (char c = 0; c < 0x7F; ++c) {
        if (
            (
                (c >= 'a')
                && (c <= 'c')
            )
            || (
                (c >= 'f')
                && (c <= 'i')
            )
        ) {
            ASSERT_TRUE(cs4.Contains(c));
        } else {
            ASSERT_FALSE(cs4.Contains(c));
        }
    }
    Uri::CharacterSet cs5{Uri::CharacterSet('a', 'c'), Uri::CharacterSet('x')};
    for (char c = 0; c < 0x7F; ++c) {
        if (
            (
                (c >= 'a')
                && (c <= 'c')
            )
            || (c == 'x')
        ) {
            ASSERT_TRUE(cs5.Contains(c));
        } else {
            ASSERT_FALSE(cs5.Contains(c));
        }
    }
}