summaryrefslogtreecommitdiff
path: root/test/src/CharacterSetTests.cpp
diff options
context:
space:
mode:
authorRichard Walters <rwalters@digitalstirling.com>2018-07-04 00:02:10 -0700
committerRichard Walters <rwalters@digitalstirling.com>2018-07-04 00:02:10 -0700
commit82ffd3e718771d2bc635264c03f002372b34893a (patch)
tree043acbca682a0634e104b0b8fc015f49ede57634 /test/src/CharacterSetTests.cpp
parente1ba9b2e46f0d67b5b3483e28750e4a3c86d1c39 (diff)
Refactoring
Add unit tests for stand-alone modules that were formerly part of Uri and so were previously tested along with Uri.
Diffstat (limited to 'test/src/CharacterSetTests.cpp')
-rw-r--r--test/src/CharacterSetTests.cpp108
1 files changed, 108 insertions, 0 deletions
diff --git a/test/src/CharacterSetTests.cpp b/test/src/CharacterSetTests.cpp
new file mode 100644
index 0000000..7013127
--- /dev/null
+++ b/test/src/CharacterSetTests.cpp
@@ -0,0 +1,108 @@
+/**
+ * @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, 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));
+ }
+ }
+}