CoreUtils/testing/mstring_test.cpp

104 lines
3.4 KiB
C++

#include <iostream>
#include "../MString.h"
int main(int argc, char **argv) {
// Literal string assignment tests.
coreutils::MString test1 = "this is an assignment test.";
std::cout << "char * operator=: [" << test1 << "]." << std::endl;
test1 = "new value.";
std::cout << "char * operator=: [" << test1 << "]." << std::endl;
std::string test11 = "this is a test";
coreutils::MString test12 = test11;
std::cout << "assign from std::string: [" << test12 << "]." << std::endl;
coreutils::MString test2("this is another test.");
std::cout << "assign on constructor: [" << test2 << "]." << std::endl;
coreutils::MString xtest;
coreutils::MString ytest("this is a test");
xtest = ytest;
std::cout << "assign mstring to mstring: " << xtest << std::endl;
// Character assignment tests.
coreutils::MString test3;
test3 = 'a';
std::cout << "char operator=: [" << test3 << "]." << std::endl;
coreutils::ZString test7("zstring data");
coreutils::MString test4;
coreutils::MString test5 = test7;
std::cout << "coreutils::MString test5 = test7: [" << test5 << "]" << std::endl;
test4 << "this is a test." << test7;
std::cout << "char* operator<<: [" << test4 << "]." << std::endl;
test4 << "another test " << 75;
std::cout << "char* operator<<: [" << test4 << "]." << std::endl;
// Stream assignment capabilities.
coreutils::MString test6;
int number = 75;
test6 << "Will this work? " << number << test4 << " See how this works.";
std::cout << "streaming: [" << test6 << "]." << std::endl;
std::string test13 = "stream from string test";
coreutils::MString test14;
test14 << test13;
std::cout << "streaming from std::string: [" << test14 << "]." << std::endl;
coreutils::MString test9("XXXXXXXXXYYYYYYYYYY");
std::cout << "test insert: " << test9 << std::endl;
coreutils::MString test8("zzz");
test9.insert(test8, 9);
test9.insert("aaaaa", 9);
std::cout << "inserting: " << test9 << std::endl;
test9.remove(10, 7);
std::cout << "removing: " << test9 << std::endl;
// Reassignments.
coreutils::MString test10;
std::cout << ">" << test10 << "<" << std::endl;
test10 = "";
std::cout << ">" << test10 << "<" << std::endl;
// Assign from ZString tests.
coreutils::ZString test20("This is a zstring");
coreutils::MString test21;
test21 = test20;
std::cout << "mstring = zstring: [" << test21 << "]" << std::endl;
coreutils::MString test22;
test22 << test20;
std::cout << "mstring << zstring: [" << test22 << "]" << std::endl;
std::string test23 = "this is a string";
test22 = test23;
std::cout << "mstring = string: [" << test22 << "]" << std::endl;
test22 << test23;
std::cout << "mstring << string: [" << test22 << "]" << std::endl;
// coreutils::MString test24 = std::endl;
// std::cout << "mstring << endl: " << test24 << std::endl;
coreutils::MString test25 = 3.14159;
std::cout << "float: " << test25 << std::endl;
coreutils::MString test26;
double test27 = 4.0f;
test26 = test27;
std::cout << "float: " << test26 << std::endl;
coreutils::MString test28;
int test29 = 402;
test28 = test29;
std::cout << "int: " << test28 << std::endl;
coreutils::MString test30 = "ABCDEF";
std::cout << test30 << " to hex " << test30.toHex() << " from hex " << test30.toHex().fromHex() << std::endl;
return 0;
}