summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2024-03-12 01:08:39 +0100
committerAki <please@ignore.pl>2024-03-12 01:08:39 +0100
commitf43d32d6d2cc7ecd04f4f06f20d5a6fc2c87c9ae (patch)
tree0f82962432f9cd4fae60dd37c8935c1bc28f29e5
parent2914a714cebae7f30d47362dfe50c39cb6621163 (diff)
downloadstarshatter-f43d32d6d2cc7ecd04f4f06f20d5a6fc2c87c9ae.zip
starshatter-f43d32d6d2cc7ecd04f4f06f20d5a6fc2c87c9ae.tar.gz
starshatter-f43d32d6d2cc7ecd04f4f06f20d5a6fc2c87c9ae.tar.bz2
Another reorganization change that diverts me from crying unable to get rid off singleton madness
-rw-r--r--FoundationEx/CMakeLists.txt17
-rw-r--r--FoundationEx/include/Dictionary.h (renamed from FoundationEx/Dictionary.h)0
-rw-r--r--FoundationEx/include/Dictionary.inl.h (renamed from FoundationEx/Dictionary.inl.h)0
-rw-r--r--FoundationEx/include/List.h (renamed from FoundationEx/List.h)0
-rw-r--r--FoundationEx/include/List.inl.h (renamed from FoundationEx/List.inl.h)0
-rw-r--r--FoundationEx/include/Reader.h (renamed from FoundationEx/Reader.h)0
-rw-r--r--FoundationEx/include/Text.h (renamed from FoundationEx/Text.h)2
-rw-r--r--FoundationEx/include/Utils.h (renamed from FoundationEx/Utils.h)0
-rw-r--r--FoundationEx/src/Reader.cpp (renamed from FoundationEx/Reader.cpp)4
-rw-r--r--FoundationEx/src/Text.cpp (renamed from FoundationEx/Text.cpp)10
-rw-r--r--FoundationEx/src/Utils.cpp (renamed from FoundationEx/Utils.cpp)2
-rw-r--r--FoundationEx/test/Text.cpp47
12 files changed, 67 insertions, 15 deletions
diff --git a/FoundationEx/CMakeLists.txt b/FoundationEx/CMakeLists.txt
index 71dd25d..045b44e 100644
--- a/FoundationEx/CMakeLists.txt
+++ b/FoundationEx/CMakeLists.txt
@@ -1,12 +1,7 @@
project(FoundationEx)
-add_library(
- FoundationEx
- STATIC
- Reader.cpp
- Text.cpp
- Utils.cpp
- )
-target_include_directories(
- FoundationEx
- PUBLIC .
- )
+add_library(${PROJECT_NAME} STATIC src/Reader.cpp src/Text.cpp src/Utils.cpp)
+target_include_directories(${PROJECT_NAME} PUBLIC include)
+add_executable(${PROJECT_NAME}_test test/Text.cpp)
+target_link_libraries(${PROJECT_NAME}_test PRIVATE ${PROJECT_NAME} GTest::gtest_main)
+generate_emulator(${PROJECT_NAME}_test)
+gtest_discover_tests(${PROJECT_NAME}_test DISCOVERY_TIMEOUT 60)
diff --git a/FoundationEx/Dictionary.h b/FoundationEx/include/Dictionary.h
index bcb30ed..bcb30ed 100644
--- a/FoundationEx/Dictionary.h
+++ b/FoundationEx/include/Dictionary.h
diff --git a/FoundationEx/Dictionary.inl.h b/FoundationEx/include/Dictionary.inl.h
index cd58679..cd58679 100644
--- a/FoundationEx/Dictionary.inl.h
+++ b/FoundationEx/include/Dictionary.inl.h
diff --git a/FoundationEx/List.h b/FoundationEx/include/List.h
index 54dfcb1..54dfcb1 100644
--- a/FoundationEx/List.h
+++ b/FoundationEx/include/List.h
diff --git a/FoundationEx/List.inl.h b/FoundationEx/include/List.inl.h
index 9ccb796..9ccb796 100644
--- a/FoundationEx/List.inl.h
+++ b/FoundationEx/include/List.inl.h
diff --git a/FoundationEx/Reader.h b/FoundationEx/include/Reader.h
index ed6aebc..ed6aebc 100644
--- a/FoundationEx/Reader.h
+++ b/FoundationEx/include/Reader.h
diff --git a/FoundationEx/Text.h b/FoundationEx/include/Text.h
index 37e5842..4cf5cc4 100644
--- a/FoundationEx/Text.h
+++ b/FoundationEx/include/Text.h
@@ -109,6 +109,8 @@ public:
const char* data() const { return sym; }
operator const char* () const { return sym; }
+ bool empty() const;
+
bool contains(char c) const;
bool contains(const char* s) const;
diff --git a/FoundationEx/Utils.h b/FoundationEx/include/Utils.h
index 731bc01..731bc01 100644
--- a/FoundationEx/Utils.h
+++ b/FoundationEx/include/Utils.h
diff --git a/FoundationEx/Reader.cpp b/FoundationEx/src/Reader.cpp
index b39e9bc..0ca49aa 100644
--- a/FoundationEx/Reader.cpp
+++ b/FoundationEx/src/Reader.cpp
@@ -11,13 +11,13 @@
Implementation of the Reader class
*/
-#include "Reader.h"
+#include <Reader.h>
#include <cctype>
#include <cstdio>
#include <fstream>
-#include "Utils.h"
+#include <Utils.h>
Text
diff --git a/FoundationEx/Text.cpp b/FoundationEx/src/Text.cpp
index 442a048..1f46c2e 100644
--- a/FoundationEx/Text.cpp
+++ b/FoundationEx/src/Text.cpp
@@ -11,7 +11,7 @@
Implementation of the Text class
*/
-#include "Text.h"
+#include <Text.h>
#include <cctype>
#include <cstdarg>
@@ -451,6 +451,14 @@ Text::operator()(int start, int len) const
return Text();
}
+
+bool
+Text::empty() const
+{
+ return !rep || rep->length < 1;
+}
+
+
bool
Text::contains(char c) const
{
diff --git a/FoundationEx/Utils.cpp b/FoundationEx/src/Utils.cpp
index e3b1861..827ecba 100644
--- a/FoundationEx/Utils.cpp
+++ b/FoundationEx/src/Utils.cpp
@@ -4,7 +4,7 @@
Copyright (c) 1997-2006, Destroyer Studios LLC.
*/
-#include "Utils.h"
+#include <Utils.h>
#include <stdarg.h>
#include <stdio.h>
diff --git a/FoundationEx/test/Text.cpp b/FoundationEx/test/Text.cpp
new file mode 100644
index 0000000..7400eb1
--- /dev/null
+++ b/FoundationEx/test/Text.cpp
@@ -0,0 +1,47 @@
+#include <utility>
+
+#include <gtest/gtest.h>
+
+#include <Text.h>
+
+
+TEST(FoundationEx, DefaultConstructedTextIsEmpty)
+{
+ Text t;
+ ASSERT_EQ(0, t.length());
+ ASSERT_TRUE(t.empty());
+}
+
+
+TEST(FoundationEx, TextCanBeInitializedWithLiteral)
+{
+ Text t {"Hello, there"};
+ ASSERT_EQ("Hello, there", t);
+ ASSERT_EQ(12, t.length());
+}
+
+
+TEST(FoundationEx, TextCanBeCopied)
+{
+ Text a {"Hello, there"};
+ Text b(a);
+ ASSERT_EQ(a, b);
+}
+
+
+TEST(FoundationEx, ConcatenateTextWithLiteralWithoutSideEffects)
+{
+ const Text a {"Hello"};
+ const auto b = a + ", there";
+ ASSERT_EQ("Hello", a);
+ ASSERT_EQ("Hello, there", b);
+}
+
+
+TEST(FoundationEx, ReplaceInTextWithoutSideEffects)
+{
+ Text a {"Hello, all"};
+ const auto b = a.replace("Hello", "Goodbye"); // Test::replace should be const
+ ASSERT_EQ("Hello, all", a);
+ ASSERT_EQ("Goodbye, all", b);
+}