Better directory structure naming
This commit is contained in:
10
Src/Exec/CMakeLists.txt
Normal file
10
Src/Exec/CMakeLists.txt
Normal file
@@ -0,0 +1,10 @@
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
project(Exec)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
|
||||
include_directories(..)
|
||||
link_directories(../StringTools/cmake-build-debug)
|
||||
|
||||
add_executable(Exec main.cpp)
|
||||
target_link_libraries(Exec Stringtools)
|
9
Src/Exec/main.cpp
Normal file
9
Src/Exec/main.cpp
Normal file
@@ -0,0 +1,9 @@
|
||||
#include <iostream>
|
||||
#include <StringTools/StringTools.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
std::cout << StringTools::Replace("Hello, ${where}!\n", "${where}", "World") << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
57
Src/StringTools.sln
Normal file
57
Src/StringTools.sln
Normal file
@@ -0,0 +1,57 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 16
|
||||
VisualStudioVersion = 16.0.30907.101
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "StringTools", "StringTools\StringTools.vcxproj", "{0270AC5E-EBA3-4D8F-8D50-995FD44959B4}"
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Test", "Test\Test.vcxproj", "{64EF270C-0A13-4AD8-8D50-23A1CEEBF98B}"
|
||||
ProjectSection(ProjectDependencies) = postProject
|
||||
{0270AC5E-EBA3-4D8F-8D50-995FD44959B4} = {0270AC5E-EBA3-4D8F-8D50-995FD44959B4}
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Exec", "Exec\Exec.vcxproj", "{02F9FA44-902F-4695-846B-0B45E952A962}"
|
||||
ProjectSection(ProjectDependencies) = postProject
|
||||
{0270AC5E-EBA3-4D8F-8D50-995FD44959B4} = {0270AC5E-EBA3-4D8F-8D50-995FD44959B4}
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|x64 = Debug|x64
|
||||
Debug|x86 = Debug|x86
|
||||
Release|x64 = Release|x64
|
||||
Release|x86 = Release|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{0270AC5E-EBA3-4D8F-8D50-995FD44959B4}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{0270AC5E-EBA3-4D8F-8D50-995FD44959B4}.Debug|x64.Build.0 = Debug|x64
|
||||
{0270AC5E-EBA3-4D8F-8D50-995FD44959B4}.Debug|x86.ActiveCfg = Debug|Win32
|
||||
{0270AC5E-EBA3-4D8F-8D50-995FD44959B4}.Debug|x86.Build.0 = Debug|Win32
|
||||
{0270AC5E-EBA3-4D8F-8D50-995FD44959B4}.Release|x64.ActiveCfg = Release|x64
|
||||
{0270AC5E-EBA3-4D8F-8D50-995FD44959B4}.Release|x64.Build.0 = Release|x64
|
||||
{0270AC5E-EBA3-4D8F-8D50-995FD44959B4}.Release|x86.ActiveCfg = Release|Win32
|
||||
{0270AC5E-EBA3-4D8F-8D50-995FD44959B4}.Release|x86.Build.0 = Release|Win32
|
||||
{64EF270C-0A13-4AD8-8D50-23A1CEEBF98B}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{64EF270C-0A13-4AD8-8D50-23A1CEEBF98B}.Debug|x64.Build.0 = Debug|x64
|
||||
{64EF270C-0A13-4AD8-8D50-23A1CEEBF98B}.Debug|x86.ActiveCfg = Debug|Win32
|
||||
{64EF270C-0A13-4AD8-8D50-23A1CEEBF98B}.Debug|x86.Build.0 = Debug|Win32
|
||||
{64EF270C-0A13-4AD8-8D50-23A1CEEBF98B}.Release|x64.ActiveCfg = Release|x64
|
||||
{64EF270C-0A13-4AD8-8D50-23A1CEEBF98B}.Release|x64.Build.0 = Release|x64
|
||||
{64EF270C-0A13-4AD8-8D50-23A1CEEBF98B}.Release|x86.ActiveCfg = Release|Win32
|
||||
{64EF270C-0A13-4AD8-8D50-23A1CEEBF98B}.Release|x86.Build.0 = Release|Win32
|
||||
{02F9FA44-902F-4695-846B-0B45E952A962}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{02F9FA44-902F-4695-846B-0B45E952A962}.Debug|x64.Build.0 = Debug|x64
|
||||
{02F9FA44-902F-4695-846B-0B45E952A962}.Debug|x86.ActiveCfg = Debug|Win32
|
||||
{02F9FA44-902F-4695-846B-0B45E952A962}.Debug|x86.Build.0 = Debug|Win32
|
||||
{02F9FA44-902F-4695-846B-0B45E952A962}.Release|x64.ActiveCfg = Release|x64
|
||||
{02F9FA44-902F-4695-846B-0B45E952A962}.Release|x64.Build.0 = Release|x64
|
||||
{02F9FA44-902F-4695-846B-0B45E952A962}.Release|x86.ActiveCfg = Release|Win32
|
||||
{02F9FA44-902F-4695-846B-0B45E952A962}.Release|x86.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {9F255CFD-0ECB-44F5-A3D8-3E3B2AE2C387}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
6
Src/StringTools/CMakeLists.txt
Normal file
6
Src/StringTools/CMakeLists.txt
Normal file
@@ -0,0 +1,6 @@
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
project(Stringtools)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
|
||||
add_library(Stringtools StringTools.cpp)
|
100
Src/StringTools/StringTools.cpp
Normal file
100
Src/StringTools/StringTools.cpp
Normal file
@@ -0,0 +1,100 @@
|
||||
#include "StringTools.h"
|
||||
#include <sstream>
|
||||
|
||||
std::string StringTools::Replace(const std::string& str, const char find, const std::string& subst)
|
||||
{
|
||||
std::stringstream ss;
|
||||
|
||||
for (std::size_t i = 0; i < str.length(); i++)
|
||||
{
|
||||
if (str[i] != find)
|
||||
ss << str[i];
|
||||
else
|
||||
ss << subst;
|
||||
}
|
||||
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
std::string StringTools::Replace(const std::string& str, const std::string& find, const std::string& subst)
|
||||
{
|
||||
if (find.length() == 0)
|
||||
return str;
|
||||
|
||||
std::stringstream ss;
|
||||
|
||||
std::size_t posFound = 0;
|
||||
std::size_t lastFound = 0;
|
||||
|
||||
while (posFound != std::string::npos)
|
||||
{
|
||||
lastFound = posFound;
|
||||
posFound = str.find(find, posFound);
|
||||
|
||||
if (posFound != std::string::npos)
|
||||
{
|
||||
ss << str.substr(lastFound, posFound - lastFound) << subst;
|
||||
posFound += find.length();
|
||||
}
|
||||
else
|
||||
{
|
||||
ss << str.substr(lastFound, (str.length()) - lastFound);
|
||||
}
|
||||
}
|
||||
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
std::string StringTools::Replace(const std::string& str, const char find, const char subst)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << subst;
|
||||
|
||||
return Replace(str, find, ss.str());
|
||||
}
|
||||
|
||||
std::string StringTools::Replace(const std::string& str, const std::string& find, const char subst)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << subst;
|
||||
|
||||
return Replace(str, find, ss.str());
|
||||
}
|
||||
|
||||
std::string StringTools::Lower(const std::string& str)
|
||||
{
|
||||
std::stringstream ss;
|
||||
|
||||
for (std::size_t i = 0; i < str.size(); i++)
|
||||
{
|
||||
const char c = str[i];
|
||||
|
||||
// Quick-accept: regular letters
|
||||
if ((c >= 'A') && (c <= 'Z'))
|
||||
ss << (char)(c | 32);
|
||||
|
||||
// Else: keep the character as is
|
||||
else ss << c;
|
||||
}
|
||||
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
std::string StringTools::Upper(const std::string& str)
|
||||
{
|
||||
std::stringstream ss;
|
||||
|
||||
for (std::size_t i = 0; i < str.size(); i++)
|
||||
{
|
||||
const char c = str[i];
|
||||
|
||||
// Quick-accept: regular letters
|
||||
if ((c >= 'a') && (c <= 'z'))
|
||||
ss << (char)(c & ~32);
|
||||
|
||||
// Else: keep the character as is
|
||||
else ss << c;
|
||||
}
|
||||
|
||||
return ss.str();
|
||||
}
|
29
Src/StringTools/StringTools.h
Normal file
29
Src/StringTools/StringTools.h
Normal file
@@ -0,0 +1,29 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
|
||||
/* Handy utensils to manipulate strings */
|
||||
class StringTools
|
||||
{
|
||||
public:
|
||||
//! Will replace every occurence of `find` in `str` by `subst`.
|
||||
static std::string Replace(const std::string& str, const char find, const std::string& subst);
|
||||
|
||||
//! Will replace every occurence of `find` in `str` by `subst`.
|
||||
static std::string Replace(const std::string& str, const std::string& find, const std::string& subst);
|
||||
|
||||
//! Will replace every occurence of `find` in `str` by `subst`.
|
||||
static std::string Replace(const std::string& str, const char find, const char subst);
|
||||
|
||||
//! Will replace every occurence of `find` in `str` by `subst`.
|
||||
static std::string Replace(const std::string& str, const std::string& find, const char subst);
|
||||
|
||||
//! Will make a string all-lowercase. Only works with latin and german umlautes, plus some extras.
|
||||
static std::string Lower(const std::string& str);
|
||||
|
||||
//! Will make a string all-uppercase. Only works with latin and german umlautes, plus some extras.
|
||||
static std::string Upper(const std::string& str);
|
||||
|
||||
private:
|
||||
// No instanciation! >:(
|
||||
StringTools();
|
||||
};
|
18
Src/Test/CMakeLists.txt
Normal file
18
Src/Test/CMakeLists.txt
Normal file
@@ -0,0 +1,18 @@
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
project(Tests)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
|
||||
include_directories(..)
|
||||
link_directories(../StringTools/cmake-build-debug)
|
||||
|
||||
add_executable(Tests
|
||||
Catch2.h
|
||||
main.cpp
|
||||
Lower.cpp
|
||||
Upper.cpp
|
||||
Replace_Char.cpp
|
||||
Replace_String.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(Tests Stringtools)
|
17965
Src/Test/Catch2.h
Normal file
17965
Src/Test/Catch2.h
Normal file
File diff suppressed because it is too large
Load Diff
72
Src/Test/Lower.cpp
Normal file
72
Src/Test/Lower.cpp
Normal file
@@ -0,0 +1,72 @@
|
||||
#include <StringTools/StringTools.h>
|
||||
#include "Catch2.h"
|
||||
|
||||
// Tests that lowering an empty string returns an empty string
|
||||
TEST_CASE(__FILE__"/EmptyString", "[Lower]")
|
||||
{
|
||||
// Setup
|
||||
const std::string in = "";
|
||||
|
||||
// Exercise
|
||||
const std::string out = StringTools::Lower(in);
|
||||
|
||||
// Verify
|
||||
REQUIRE(out == "");
|
||||
return;
|
||||
}
|
||||
|
||||
// Tests that lowering a string without any letters returns itself
|
||||
TEST_CASE(__FILE__"/Symbols", "[Lower]")
|
||||
{
|
||||
// Setup
|
||||
const std::string in = "66! _-\n*";
|
||||
|
||||
// Exercise
|
||||
const std::string out = StringTools::Lower(in);
|
||||
|
||||
// Verify
|
||||
REQUIRE(out == "66! _-\n*");
|
||||
return;
|
||||
}
|
||||
|
||||
// Tests that lowering a string of lowercase letters returns itself
|
||||
TEST_CASE(__FILE__"/AlreadyLowered", "[Lower]")
|
||||
{
|
||||
// Setup
|
||||
const std::string in = "ughareyouserious";
|
||||
|
||||
// Exercise
|
||||
const std::string out = StringTools::Lower(in);
|
||||
|
||||
// Verify
|
||||
REQUIRE(out == "ughareyouserious");
|
||||
return;
|
||||
}
|
||||
|
||||
// Tests that lowering a string of uppercase letters returns the lowercase version
|
||||
TEST_CASE(__FILE__"/Uppercase", "[Lower]")
|
||||
{
|
||||
// Setup
|
||||
const std::string in = "UGHAREYOUSERIOUS";
|
||||
|
||||
// Exercise
|
||||
const std::string out = StringTools::Lower(in);
|
||||
|
||||
// Verify
|
||||
REQUIRE(out == "ughareyouserious");
|
||||
return;
|
||||
}
|
||||
|
||||
// Tests that lowering a string of uppercase, lowercase letters and symbols returns the lowercase version
|
||||
TEST_CASE(__FILE__"/Mixed", "[Lower]")
|
||||
{
|
||||
// Setup
|
||||
const std::string in = "Ugh, Are You Serious?! DON'T DO THAT!!!";
|
||||
|
||||
// Exercise
|
||||
const std::string out = StringTools::Lower(in);
|
||||
|
||||
// Verify
|
||||
REQUIRE(out == "ugh, are you serious?! don't do that!!!");
|
||||
return;
|
||||
}
|
156
Src/Test/Replace_Char.cpp
Normal file
156
Src/Test/Replace_Char.cpp
Normal file
@@ -0,0 +1,156 @@
|
||||
#include <StringTools/StringTools.h>
|
||||
#include "Catch2.h"
|
||||
|
||||
// Tests that replacing something in an empty string returns an empty string
|
||||
TEST_CASE(__FILE__"/EmptyString", "[ReplaceChar]")
|
||||
{
|
||||
// Setup
|
||||
const std::string in = "";
|
||||
|
||||
// Exercise
|
||||
const std::string out = StringTools::Replace(in, 'a', "Subst");
|
||||
|
||||
// Verify
|
||||
REQUIRE(out == "");
|
||||
return;
|
||||
}
|
||||
|
||||
// Tests that replacing a char to an empty string works
|
||||
TEST_CASE(__FILE__"/Single_ReplaceToEmpty", "[ReplaceChar]")
|
||||
{
|
||||
// Setup
|
||||
const std::string in = "i";
|
||||
|
||||
// Exercise
|
||||
const std::string out = StringTools::Replace(in, 'i', "");
|
||||
|
||||
// Verify
|
||||
REQUIRE(out == "");
|
||||
return;
|
||||
}
|
||||
|
||||
// Tests that replacing to a single char works
|
||||
TEST_CASE(__FILE__"/Single_ReplaceToSingleChar", "[ReplaceChar]")
|
||||
{
|
||||
// Setup
|
||||
const std::string in = "a";
|
||||
|
||||
// Exercise
|
||||
const std::string out = StringTools::Replace(in, 'a', "i");
|
||||
|
||||
// Verify
|
||||
REQUIRE(out == "i");
|
||||
return;
|
||||
}
|
||||
|
||||
// Tests that replacing to a single char works, passing a char
|
||||
TEST_CASE(__FILE__"/Single_ReplaceToSingleChar_AsChar", "[ReplaceChar]")
|
||||
{
|
||||
// Setup
|
||||
const std::string in = "Oilbanger";
|
||||
|
||||
// Exercise
|
||||
const std::string out = StringTools::Replace(in, 'a', 'i');
|
||||
|
||||
// Verify
|
||||
REQUIRE(out == "Oilbinger");
|
||||
return;
|
||||
}
|
||||
|
||||
// Tests that replacing the find to something longer works
|
||||
TEST_CASE(__FILE__"/Single_ReplaceToLonger", "[ReplaceChar]")
|
||||
{
|
||||
// Setup
|
||||
const std::string in = "Littled";
|
||||
|
||||
// Exercise
|
||||
const std::string out = StringTools::Replace(in, 'd', "binger");
|
||||
|
||||
// Verify
|
||||
REQUIRE(out == "Littlebinger");
|
||||
return;
|
||||
}
|
||||
|
||||
// Tests that replacing a char to an empty string works
|
||||
TEST_CASE(__FILE__"/Multiple_ReplaceToEmpty", "[ReplaceChar]")
|
||||
{
|
||||
// Setup
|
||||
const std::string in = "dirty dogs dig dirt daringly";
|
||||
|
||||
// Exercise
|
||||
const std::string out = StringTools::Replace(in, 'd', "");
|
||||
|
||||
// Verify
|
||||
REQUIRE(out == "irty ogs ig irt aringly");
|
||||
return;
|
||||
}
|
||||
|
||||
// Tests that replacing to a single char works
|
||||
TEST_CASE(__FILE__"/Multiple_ReplaceToSingleChar", "[ReplaceChar]")
|
||||
{
|
||||
// Setup
|
||||
const std::string in = "Oilbanger, Bangerfanger, Lattle brattle oaly skattle.";
|
||||
|
||||
// Exercise
|
||||
const std::string out = StringTools::Replace(in, 'a', "i");
|
||||
|
||||
// Verify
|
||||
REQUIRE(out == "Oilbinger, Bingerfinger, Little brittle oily skittle.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Tests that replacing to a single char works, passing a char
|
||||
TEST_CASE(__FILE__"/Multiple_ReplaceToSingleChar_AsChar", "[ReplaceChar]")
|
||||
{
|
||||
// Setup
|
||||
const std::string in = "Oilbanger, Bangerfanger, Lattle brattle oaly skattle.";
|
||||
|
||||
// Exercise
|
||||
const std::string out = StringTools::Replace(in, 'a', 'i');
|
||||
|
||||
// Verify
|
||||
REQUIRE(out == "Oilbinger, Bingerfinger, Little brittle oily skittle.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Tests that replacing the find to something longer works
|
||||
TEST_CASE(__FILE__"/Multiple_ReplaceToLonger", "[ReplaceChar]")
|
||||
{
|
||||
// Setup
|
||||
const std::string in = "d d d d d d d d";
|
||||
|
||||
// Exercise
|
||||
const std::string out = StringTools::Replace(in, 'd', "bla");
|
||||
|
||||
// Verify
|
||||
REQUIRE(out == "bla bla bla bla bla bla bla bla");
|
||||
return;
|
||||
}
|
||||
|
||||
// Tests that the replacer ignores chars put in by the replacer
|
||||
TEST_CASE(__FILE__"/ReplacerIgnoresReplaced", "[ReplaceChar]")
|
||||
{
|
||||
// Setup
|
||||
const std::string in = "b b b b b b b b";
|
||||
|
||||
// Exercise
|
||||
const std::string out = StringTools::Replace(in, 'b', "bla");
|
||||
|
||||
// Verify
|
||||
REQUIRE(out == "bla bla bla bla bla bla bla bla");
|
||||
return;
|
||||
}
|
||||
|
||||
// Tests that replacing succesive findings works
|
||||
TEST_CASE(__FILE__"/Replace_Successive", "[ReplaceChar]")
|
||||
{
|
||||
// Setup
|
||||
const std::string in = "bbbbbbbb";
|
||||
|
||||
// Exercise
|
||||
const std::string out = StringTools::Replace(in, 'b', "bla");
|
||||
|
||||
// Verify
|
||||
REQUIRE(out == "blablablablablablablabla");
|
||||
return;
|
||||
}
|
170
Src/Test/Replace_String.cpp
Normal file
170
Src/Test/Replace_String.cpp
Normal file
@@ -0,0 +1,170 @@
|
||||
#include <StringTools/StringTools.h>
|
||||
#include "Catch2.h"
|
||||
|
||||
// Tests that replacing something in an empty string returns an empty string
|
||||
TEST_CASE(__FILE__"/EmptyString", "[ReplaceString]")
|
||||
{
|
||||
// Setup
|
||||
const std::string in = "";
|
||||
|
||||
// Exercise
|
||||
const std::string out = StringTools::Replace(in, "burger", "Subst");
|
||||
|
||||
// Verify
|
||||
REQUIRE(out == "");
|
||||
return;
|
||||
}
|
||||
|
||||
// Tests that replacing a string to an empty string works
|
||||
TEST_CASE(__FILE__"/Single_ReplaceToEmpty", "[ReplaceString]")
|
||||
{
|
||||
// Setup
|
||||
const std::string in = "Squarepants";
|
||||
|
||||
// Exercise
|
||||
const std::string out = StringTools::Replace(in, "Squarepants", "");
|
||||
|
||||
// Verify
|
||||
REQUIRE(out == "");
|
||||
return;
|
||||
}
|
||||
|
||||
// Tests that replacing to a single char works
|
||||
TEST_CASE(__FILE__"/Single_ReplaceToSingleChar", "[ReplaceString]")
|
||||
{
|
||||
// Setup
|
||||
const std::string in = "Squarepants";
|
||||
|
||||
// Exercise
|
||||
const std::string out = StringTools::Replace(in, "Squarepants", "i");
|
||||
|
||||
// Verify
|
||||
REQUIRE(out == "i");
|
||||
return;
|
||||
}
|
||||
|
||||
// Tests that replacing to a single char works, passing a char
|
||||
TEST_CASE(__FILE__"/Single_ReplaceToSingleChar_AsChar", "[ReplaceString]")
|
||||
{
|
||||
// Setup
|
||||
const std::string in = "Oilbanger";
|
||||
|
||||
// Exercise
|
||||
const std::string out = StringTools::Replace(in, "Oilbanger", 'i');
|
||||
|
||||
// Verify
|
||||
REQUIRE(out == "i");
|
||||
return;
|
||||
}
|
||||
|
||||
// Tests that replacing the find to something longer works
|
||||
TEST_CASE(__FILE__"/Single_ReplaceToLonger", "[ReplaceString]")
|
||||
{
|
||||
// Setup
|
||||
const std::string in = "LittleDong";
|
||||
|
||||
// Exercise
|
||||
const std::string out = StringTools::Replace(in, "Dong", "Binger");
|
||||
|
||||
// Verify
|
||||
REQUIRE(out == "LittleBinger");
|
||||
return;
|
||||
}
|
||||
|
||||
// Tests that replacing a string to an empty string works
|
||||
TEST_CASE(__FILE__"/Multiple_ReplaceToEmpty", "[ReplaceString]")
|
||||
{
|
||||
// Setup
|
||||
const std::string in = "The fucking dogs are fucking eating the fucking chicken.";
|
||||
|
||||
// Exercise
|
||||
const std::string out = StringTools::Replace(in, "fucking ", "");
|
||||
|
||||
// Verify
|
||||
REQUIRE(out == "The dogs are eating the chicken.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Tests that replacing to a single char works
|
||||
TEST_CASE(__FILE__"/Multiple_ReplaceToSingleChar", "[ReplaceString]")
|
||||
{
|
||||
// Setup
|
||||
const std::string in = "Oilbsmearynger, Bsmearyngerfsmearynger, Lsmearyttle brsmearyttle osmearyly sksmearyttle.";
|
||||
|
||||
// Exercise
|
||||
const std::string out = StringTools::Replace(in, "smeary", "i");
|
||||
|
||||
// Verify
|
||||
REQUIRE(out == "Oilbinger, Bingerfinger, Little brittle oily skittle.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Tests that replacing to a single char works, passing a char
|
||||
TEST_CASE(__FILE__"/Multiple_ReplaceToSingleChar_AsChar", "[ReplaceString]")
|
||||
{
|
||||
// Setup
|
||||
const std::string in = "Oilbsmearynger, Bsmearyngerfsmearynger, Lsmearyttle brsmearyttle osmearyly sksmearyttle.";
|
||||
|
||||
// Exercise
|
||||
const std::string out = StringTools::Replace(in, "smeary", 'i');
|
||||
|
||||
// Verify
|
||||
REQUIRE(out == "Oilbinger, Bingerfinger, Little brittle oily skittle.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Tests that replacing the find to something longer works
|
||||
TEST_CASE(__FILE__"/Multiple_ReplaceToLonger", "[ReplaceString]")
|
||||
{
|
||||
// Setup
|
||||
const std::string in = "honk honk honk honk honk honk honk honk";
|
||||
|
||||
// Exercise
|
||||
const std::string out = StringTools::Replace(in, "honk", "hallery");
|
||||
|
||||
// Verify
|
||||
REQUIRE(out == "hallery hallery hallery hallery hallery hallery hallery hallery");
|
||||
return;
|
||||
}
|
||||
|
||||
// Tests that the replacer ignores chars put in by the replacer
|
||||
TEST_CASE(__FILE__"/ReplacerIgnoresReplaced", "[ReplaceString]")
|
||||
{
|
||||
// Setup
|
||||
const std::string in = "honk honk honk honk honk honk honk honk";
|
||||
|
||||
// Exercise
|
||||
const std::string out = StringTools::Replace(in, "honk", "honka");
|
||||
|
||||
// Verify
|
||||
REQUIRE(out == "honka honka honka honka honka honka honka honka");
|
||||
return;
|
||||
}
|
||||
|
||||
// Tests that replacing successive findings works
|
||||
TEST_CASE(__FILE__"/Replace_Successive", "[ReplaceString]")
|
||||
{
|
||||
// Setup
|
||||
const std::string in = "honkhonkhonkhonkhonkhonkhonkhonk";
|
||||
|
||||
// Exercise
|
||||
const std::string out = StringTools::Replace(in, "honk", "hallery");
|
||||
|
||||
// Verify
|
||||
REQUIRE(out == "halleryhalleryhalleryhalleryhalleryhalleryhalleryhallery");
|
||||
return;
|
||||
}
|
||||
|
||||
// Tests that if find.length() == 0, it returns just the input
|
||||
TEST_CASE(__FILE__"/Find_Length0_Returns_Input", "[ReplaceString]")
|
||||
{
|
||||
// Setup
|
||||
const std::string in = "Littled";
|
||||
|
||||
// Exercise
|
||||
const std::string out = StringTools::Replace(in, "", "binger");
|
||||
|
||||
// Verify
|
||||
REQUIRE(out == "Littled");
|
||||
return;
|
||||
}
|
72
Src/Test/Upper.cpp
Normal file
72
Src/Test/Upper.cpp
Normal file
@@ -0,0 +1,72 @@
|
||||
#include <StringTools/StringTools.h>
|
||||
#include "Catch2.h"
|
||||
|
||||
// Tests that uppering an empty string returns an empty string
|
||||
TEST_CASE(__FILE__"/EmptyString", "[Upper]")
|
||||
{
|
||||
// Setup
|
||||
const std::string in = "";
|
||||
|
||||
// Exercise
|
||||
const std::string out = StringTools::Upper(in);
|
||||
|
||||
// Verify
|
||||
REQUIRE(out == "");
|
||||
return;
|
||||
}
|
||||
|
||||
// Tests that uppering a string without any letters returns itself
|
||||
TEST_CASE(__FILE__"/Symbols", "[Upper]")
|
||||
{
|
||||
// Setup
|
||||
const std::string in = "66! _-\n*";
|
||||
|
||||
// Exercise
|
||||
const std::string out = StringTools::Upper(in);
|
||||
|
||||
// Verify
|
||||
REQUIRE(out == "66! _-\n*");
|
||||
return;
|
||||
}
|
||||
|
||||
// Tests that uppering a string of uppercase letters returns itself
|
||||
TEST_CASE(__FILE__"/AlreadyUppered", "[Upper]")
|
||||
{
|
||||
// Setup
|
||||
const std::string in = "UGHAREYOUSERIOUS";
|
||||
|
||||
// Exercise
|
||||
const std::string out = StringTools::Upper(in);
|
||||
|
||||
// Verify
|
||||
REQUIRE(out == "UGHAREYOUSERIOUS");
|
||||
return;
|
||||
}
|
||||
|
||||
// Tests that uppering a string of lowercase letters returns the uppercase version
|
||||
TEST_CASE(__FILE__"/Lowercase", "[Upper]")
|
||||
{
|
||||
// Setup
|
||||
const std::string in = "ughareyouserious";
|
||||
|
||||
// Exercise
|
||||
const std::string out = StringTools::Upper(in);
|
||||
|
||||
// Verify
|
||||
REQUIRE(out == "UGHAREYOUSERIOUS");
|
||||
return;
|
||||
}
|
||||
|
||||
// Tests that uppering a string of uppercase, lowercase letters and symbols returns the uppercase version
|
||||
TEST_CASE(__FILE__"/Mixed", "[Upper]")
|
||||
{
|
||||
// Setup
|
||||
const std::string in = "Ugh, Are You Serious?! DON'T do that!!!";
|
||||
|
||||
// Exercise
|
||||
const std::string out = StringTools::Upper(in);
|
||||
|
||||
// Verify
|
||||
REQUIRE(out == "UGH, ARE YOU SERIOUS?! DON'T DO THAT!!!");
|
||||
return;
|
||||
}
|
2
Src/Test/main.cpp
Normal file
2
Src/Test/main.cpp
Normal file
@@ -0,0 +1,2 @@
|
||||
#define CATCH_CONFIG_MAIN
|
||||
#include "Catch2.h"
|
Reference in New Issue
Block a user