2014-02-10 01:10:30 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/* test_string.cpp */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 12:16:55 +00:00
|
|
|
/* https://godotengine.org */
|
2014-02-10 01:10:30 +00:00
|
|
|
/*************************************************************************/
|
2019-01-01 11:53:14 +00:00
|
|
|
/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
|
2014-02-10 01:10:30 +00:00
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/*************************************************************************/
|
2018-01-04 23:50:27 +00:00
|
|
|
|
2018-09-11 16:13:45 +00:00
|
|
|
#include "core/ustring.h"
|
2014-02-10 01:10:30 +00:00
|
|
|
#include <wchar.h>
|
2018-09-11 16:13:45 +00:00
|
|
|
//#include "core/math/math_funcs.h"
|
2016-10-19 21:32:36 +00:00
|
|
|
#include "core/io/ip_address.h"
|
2018-09-11 16:13:45 +00:00
|
|
|
#include "core/os/os.h"
|
2019-05-09 15:11:53 +00:00
|
|
|
#include "modules/regex/regex.h"
|
2017-03-05 15:44:50 +00:00
|
|
|
#include <stdio.h>
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
#include "test_string.h"
|
|
|
|
|
|
|
|
namespace TestString {
|
|
|
|
|
|
|
|
bool test_1() {
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
OS::get_singleton()->print("\n\nTest 1: Assign from cstr\n");
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
String s = "Hello";
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
OS::get_singleton()->print("\tExpected: Hello\n");
|
2017-03-05 15:44:50 +00:00
|
|
|
OS::get_singleton()->print("\tResulted: %ls\n", s.c_str());
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
return (wcscmp(s.c_str(), L"Hello") == 0);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool test_2() {
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
OS::get_singleton()->print("\n\nTest 2: Assign from string (operator=)\n");
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
String s = "Dolly";
|
2019-06-26 13:08:25 +00:00
|
|
|
const String &t = s;
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
OS::get_singleton()->print("\tExpected: Dolly\n");
|
2017-03-05 15:44:50 +00:00
|
|
|
OS::get_singleton()->print("\tResulted: %ls\n", t.c_str());
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
return (wcscmp(t.c_str(), L"Dolly") == 0);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool test_3() {
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
OS::get_singleton()->print("\n\nTest 3: Assign from c-string (copycon)\n");
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
String s("Sheep");
|
2019-06-26 13:08:25 +00:00
|
|
|
const String &t(s);
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
OS::get_singleton()->print("\tExpected: Sheep\n");
|
2017-03-05 15:44:50 +00:00
|
|
|
OS::get_singleton()->print("\tResulted: %ls\n", t.c_str());
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
return (wcscmp(t.c_str(), L"Sheep") == 0);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool test_4() {
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
OS::get_singleton()->print("\n\nTest 4: Assign from c-widechar (operator=)\n");
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
String s(L"Give me");
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
OS::get_singleton()->print("\tExpected: Give me\n");
|
2017-03-05 15:44:50 +00:00
|
|
|
OS::get_singleton()->print("\tResulted: %ls\n", s.c_str());
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
return (wcscmp(s.c_str(), L"Give me") == 0);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool test_5() {
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
OS::get_singleton()->print("\n\nTest 5: Assign from c-widechar (copycon)\n");
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
String s(L"Wool");
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
OS::get_singleton()->print("\tExpected: Wool\n");
|
2017-03-05 15:44:50 +00:00
|
|
|
OS::get_singleton()->print("\tResulted: %ls\n", s.c_str());
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
return (wcscmp(s.c_str(), L"Wool") == 0);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool test_6() {
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
OS::get_singleton()->print("\n\nTest 6: comparisons (equal)\n");
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
String s = "Test Compare";
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
OS::get_singleton()->print("\tComparing to \"Test Compare\"\n");
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (!(s == "Test Compare"))
|
2014-02-10 01:10:30 +00:00
|
|
|
return false;
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (!(s == L"Test Compare"))
|
2014-02-10 01:10:30 +00:00
|
|
|
return false;
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (!(s == String("Test Compare")))
|
2014-02-10 01:10:30 +00:00
|
|
|
return false;
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool test_7() {
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
OS::get_singleton()->print("\n\nTest 7: comparisons (unequal)\n");
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
String s = "Test Compare";
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
OS::get_singleton()->print("\tComparing to \"Test Compare\"\n");
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (!(s != "Peanut"))
|
2014-02-10 01:10:30 +00:00
|
|
|
return false;
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (!(s != L"Coconut"))
|
2014-02-10 01:10:30 +00:00
|
|
|
return false;
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (!(s != String("Butter")))
|
2014-02-10 01:10:30 +00:00
|
|
|
return false;
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool test_8() {
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
OS::get_singleton()->print("\n\nTest 8: comparisons (operator<)\n");
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
String s = "Bees";
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
OS::get_singleton()->print("\tComparing to \"Bees\"\n");
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (!(s < "Elephant"))
|
2014-02-10 01:10:30 +00:00
|
|
|
return false;
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (s < L"Amber")
|
2014-02-10 01:10:30 +00:00
|
|
|
return false;
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (s < String("Beatrix"))
|
2014-02-10 01:10:30 +00:00
|
|
|
return false;
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool test_9() {
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
OS::get_singleton()->print("\n\nTest 9: Concatenation\n");
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
String s;
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
s += "Have";
|
|
|
|
s += ' ';
|
|
|
|
s += 'a';
|
|
|
|
s += String(" ");
|
2014-02-10 01:10:30 +00:00
|
|
|
s = s + L"Nice";
|
|
|
|
s = s + " ";
|
|
|
|
s = s + String("Day");
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
OS::get_singleton()->print("\tComparing to \"Have a Nice Day\"\n");
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
return (s == "Have a Nice Day");
|
|
|
|
}
|
|
|
|
|
|
|
|
bool test_10() {
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
OS::get_singleton()->print("\n\nTest 10: Misc funcs (size/length/empty/etc)\n");
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (!String("").empty())
|
2014-02-10 01:10:30 +00:00
|
|
|
return false;
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
if (String("Mellon").size() != 7)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (String("Oranges").length() != 7)
|
|
|
|
return false;
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool test_11() {
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
OS::get_singleton()->print("\n\nTest 11: Operator[]\n");
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
String a = "Kugar Sane";
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
a[0] = 'S';
|
|
|
|
a[6] = 'C';
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
if (a != "Sugar Cane")
|
|
|
|
return false;
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (a[1] != 'u')
|
2014-02-10 01:10:30 +00:00
|
|
|
return false;
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool test_12() {
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
OS::get_singleton()->print("\n\nTest 12: case functions\n");
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
String a = "MoMoNgA";
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
if (a.to_upper() != "MOMONGA")
|
|
|
|
return false;
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (a.nocasecmp_to("momonga") != 0)
|
2014-02-10 01:10:30 +00:00
|
|
|
return false;
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool test_13() {
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
OS::get_singleton()->print("\n\nTest 13: UTF8\n");
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
/* how can i embed UTF in here? */
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
static const CharType ustr[] = { 0x304A, 0x360F, 0x3088, 0x3046, 0 };
|
2017-01-14 11:26:56 +00:00
|
|
|
//static const wchar_t ustr[] = { 'P', 0xCE, 'p',0xD3, 0 };
|
2017-03-05 15:44:50 +00:00
|
|
|
String s = ustr;
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
OS::get_singleton()->print("\tUnicode: %ls\n", ustr);
|
|
|
|
s.parse_utf8(s.utf8().get_data());
|
|
|
|
OS::get_singleton()->print("\tConvert/Parse UTF8: %ls\n", s.c_str());
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
return (s == ustr);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool test_14() {
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
OS::get_singleton()->print("\n\nTest 14: ASCII\n");
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
String s = L"Primero Leche";
|
2017-03-05 15:44:50 +00:00
|
|
|
OS::get_singleton()->print("\tAscii: %s\n", s.ascii().get_data());
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
String t = s.ascii().get_data();
|
|
|
|
return (s == t);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool test_15() {
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
OS::get_singleton()->print("\n\nTest 15: substr\n");
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
String s = "Killer Baby";
|
|
|
|
OS::get_singleton()->print("\tsubstr(3,4) of \"%ls\" is \"%ls\"\n", s.c_str(), s.substr(3, 4).c_str());
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
return (s.substr(3, 4) == "ler ");
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool test_16() {
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
OS::get_singleton()->print("\n\nTest 16: find\n");
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
String s = "Pretty Woman";
|
|
|
|
OS::get_singleton()->print("\tString: %ls\n", s.c_str());
|
|
|
|
OS::get_singleton()->print("\t\"tty\" is at %i pos.\n", s.find("tty"));
|
|
|
|
OS::get_singleton()->print("\t\"Revenge of the Monster Truck\" is at %i pos.\n", s.find("Revenge of the Monster Truck"));
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (s.find("tty") != 3)
|
2014-02-10 01:10:30 +00:00
|
|
|
return false;
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (s.find("Revenge of the Monster Truck") != -1)
|
2014-02-10 01:10:30 +00:00
|
|
|
return false;
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool test_17() {
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
OS::get_singleton()->print("\n\nTest 17: find no case\n");
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
String s = "Pretty Whale";
|
|
|
|
OS::get_singleton()->print("\tString: %ls\n", s.c_str());
|
|
|
|
OS::get_singleton()->print("\t\"WHA\" is at %i pos.\n", s.findn("WHA"));
|
|
|
|
OS::get_singleton()->print("\t\"Revenge of the Monster SawFish\" is at %i pos.\n", s.findn("Revenge of the Monster Truck"));
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (s.findn("WHA") != 7)
|
2014-02-10 01:10:30 +00:00
|
|
|
return false;
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (s.findn("Revenge of the Monster SawFish") != -1)
|
2014-02-10 01:10:30 +00:00
|
|
|
return false;
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool test_18() {
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
OS::get_singleton()->print("\n\nTest 18: find no case\n");
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
String s = "Pretty Whale";
|
|
|
|
OS::get_singleton()->print("\tString: %ls\n", s.c_str());
|
|
|
|
OS::get_singleton()->print("\t\"WHA\" is at %i pos.\n", s.findn("WHA"));
|
|
|
|
OS::get_singleton()->print("\t\"Revenge of the Monster SawFish\" is at %i pos.\n", s.findn("Revenge of the Monster Truck"));
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (s.findn("WHA") != 7)
|
2014-02-10 01:10:30 +00:00
|
|
|
return false;
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (s.findn("Revenge of the Monster SawFish") != -1)
|
2014-02-10 01:10:30 +00:00
|
|
|
return false;
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool test_19() {
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
OS::get_singleton()->print("\n\nTest 19: Search & replace\n");
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
String s = "Happy Birthday, Anna!";
|
|
|
|
OS::get_singleton()->print("\tString: %ls\n", s.c_str());
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
s = s.replace("Birthday", "Halloween");
|
|
|
|
OS::get_singleton()->print("\tReplaced Birthday/Halloween: %ls.\n", s.c_str());
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
return (s == "Happy Halloween, Anna!");
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool test_20() {
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
OS::get_singleton()->print("\n\nTest 20: Insertion\n");
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
String s = "Who is Frederic?";
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
OS::get_singleton()->print("\tString: %ls\n", s.c_str());
|
|
|
|
s = s.insert(s.find("?"), " Chopin");
|
|
|
|
OS::get_singleton()->print("\tInserted Chopin: %ls.\n", s.c_str());
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
return (s == "Who is Frederic Chopin?");
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool test_21() {
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
OS::get_singleton()->print("\n\nTest 21: Number -> String\n");
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
OS::get_singleton()->print("\tPi is %f\n", 33.141593);
|
|
|
|
OS::get_singleton()->print("\tPi String is %ls\n", String::num(3.141593).c_str());
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
return String::num(3.141593) == "3.141593";
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool test_22() {
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
OS::get_singleton()->print("\n\nTest 22: String -> Int\n");
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
static const char *nums[4] = { "1237461283", "- 22", "0", " - 1123412" };
|
|
|
|
static const int num[4] = { 1237461283, -22, 0, -1123412 };
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < 4; i++) {
|
|
|
|
OS::get_singleton()->print("\tString: \"%s\" as Int is %i\n", nums[i], String(nums[i]).to_int());
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (String(nums[i]).to_int() != num[i])
|
2014-02-10 01:10:30 +00:00
|
|
|
return false;
|
|
|
|
}
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool test_23() {
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
OS::get_singleton()->print("\n\nTest 23: String -> Float\n");
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
static const char *nums[4] = { "-12348298412.2", "0.05", "2.0002", " -0.0001" };
|
|
|
|
static const double num[4] = { -12348298412.2, 0.05, 2.0002, -0.0001 };
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < 4; i++) {
|
|
|
|
OS::get_singleton()->print("\tString: \"%s\" as Float is %f\n", nums[i], String(nums[i]).to_double());
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (ABS(String(nums[i]).to_double() - num[i]) > 0.00001)
|
2014-02-10 01:10:30 +00:00
|
|
|
return false;
|
|
|
|
}
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool test_24() {
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
OS::get_singleton()->print("\n\nTest 24: Slicing\n");
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
String s = "Mars,Jupiter,Saturn,Uranus";
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
const char *slices[4] = { "Mars", "Jupiter", "Saturn", "Uranus" };
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
OS::get_singleton()->print("\tSlicing \"%ls\" by \"%s\"..\n", s.c_str(), ",");
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < s.get_slice_count(","); i++) {
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
OS::get_singleton()->print("\t\t%i- %ls\n", i + 1, s.get_slice(",", i).c_str());
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (s.get_slice(",", i) != slices[i])
|
2014-02-10 01:10:30 +00:00
|
|
|
return false;
|
|
|
|
}
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool test_25() {
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
OS::get_singleton()->print("\n\nTest 25: Erasing\n");
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
String s = "Josephine is such a cute girl!";
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
OS::get_singleton()->print("\tString: %ls\n", s.c_str());
|
2014-02-10 01:10:30 +00:00
|
|
|
OS::get_singleton()->print("\tRemoving \"cute\"\n");
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
s.erase(s.find("cute "), String("cute ").length());
|
|
|
|
OS::get_singleton()->print("\tResult: %ls\n", s.c_str());
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
return (s == "Josephine is such a girl!");
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool test_26() {
|
|
|
|
|
2019-05-09 15:11:53 +00:00
|
|
|
OS::get_singleton()->print("\n\nTest 26: RegEx substitution\n");
|
|
|
|
|
|
|
|
String s = "Double all the vowels.";
|
|
|
|
|
|
|
|
OS::get_singleton()->print("\tString: %ls\n", s.c_str());
|
|
|
|
OS::get_singleton()->print("\tRepeating instances of 'aeiou' once\n");
|
|
|
|
|
|
|
|
RegEx re("(?<vowel>[aeiou])");
|
|
|
|
s = re.sub(s, "$0$vowel", true);
|
|
|
|
|
|
|
|
OS::get_singleton()->print("\tResult: %ls\n", s.c_str());
|
|
|
|
|
|
|
|
return (s == "Doouublee aall thee vooweels.");
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2014-02-26 15:18:05 +00:00
|
|
|
struct test_27_data {
|
2017-03-05 15:44:50 +00:00
|
|
|
char const *data;
|
|
|
|
char const *begin;
|
2014-02-26 15:18:05 +00:00
|
|
|
bool expected;
|
|
|
|
};
|
|
|
|
|
|
|
|
bool test_27() {
|
|
|
|
|
2015-01-10 20:44:20 +00:00
|
|
|
OS::get_singleton()->print("\n\nTest 27: begins_with\n");
|
2014-02-26 15:18:05 +00:00
|
|
|
test_27_data tc[] = {
|
2017-03-05 15:44:50 +00:00
|
|
|
{ "res://foobar", "res://", true },
|
|
|
|
{ "res", "res://", false },
|
|
|
|
{ "abc", "abc", true }
|
2014-02-26 15:18:05 +00:00
|
|
|
};
|
|
|
|
size_t count = sizeof(tc) / sizeof(tc[0]);
|
|
|
|
bool state = true;
|
2017-03-05 15:44:50 +00:00
|
|
|
for (size_t i = 0; state && i < count; ++i) {
|
2014-02-26 15:18:05 +00:00
|
|
|
String s = tc[i].data;
|
|
|
|
state = s.begins_with(tc[i].begin) == tc[i].expected;
|
|
|
|
if (state) {
|
|
|
|
String sb = tc[i].begin;
|
|
|
|
state = s.begins_with(sb) == tc[i].expected;
|
|
|
|
}
|
|
|
|
if (!state) {
|
2019-02-22 14:38:49 +00:00
|
|
|
OS::get_singleton()->print("\n\t Failure on:\n\t\tstring: %s\n\t\tbegin: %s\n\t\texpected: %s\n", tc[i].data, tc[i].begin, tc[i].expected ? "true" : "false");
|
2015-01-10 20:44:20 +00:00
|
|
|
break;
|
2014-02-26 15:18:05 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
return state;
|
|
|
|
};
|
|
|
|
|
2015-01-10 20:44:20 +00:00
|
|
|
bool test_28() {
|
|
|
|
|
|
|
|
OS::get_singleton()->print("\n\nTest 28: sprintf\n");
|
|
|
|
|
|
|
|
bool success, state = true;
|
|
|
|
char output_format[] = "\tTest:\t%ls => %ls (%s)\n";
|
|
|
|
String format, output;
|
|
|
|
Array args;
|
2015-02-19 15:45:49 +00:00
|
|
|
bool error;
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2015-01-10 20:44:20 +00:00
|
|
|
// %%
|
|
|
|
format = "fish %% frog";
|
|
|
|
args.clear();
|
2015-02-19 15:45:49 +00:00
|
|
|
output = format.sprintf(args, &error);
|
|
|
|
success = (output == String("fish % frog") && !error);
|
2015-01-10 20:44:20 +00:00
|
|
|
OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL");
|
2018-09-30 04:33:21 +00:00
|
|
|
state = state && success;
|
2015-01-10 20:44:20 +00:00
|
|
|
|
2015-02-01 20:18:38 +00:00
|
|
|
//////// INTS
|
|
|
|
|
2015-01-10 20:44:20 +00:00
|
|
|
// Int
|
|
|
|
format = "fish %d frog";
|
|
|
|
args.clear();
|
|
|
|
args.push_back(5);
|
2015-02-19 15:45:49 +00:00
|
|
|
output = format.sprintf(args, &error);
|
|
|
|
success = (output == String("fish 5 frog") && !error);
|
2015-02-01 20:18:38 +00:00
|
|
|
OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL");
|
2018-09-30 04:33:21 +00:00
|
|
|
state = state && success;
|
2015-02-01 20:18:38 +00:00
|
|
|
|
|
|
|
// Int left padded with zeroes.
|
|
|
|
format = "fish %05d frog";
|
|
|
|
args.clear();
|
|
|
|
args.push_back(5);
|
2015-02-19 15:45:49 +00:00
|
|
|
output = format.sprintf(args, &error);
|
|
|
|
success = (output == String("fish 00005 frog") && !error);
|
2015-02-01 20:18:38 +00:00
|
|
|
OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL");
|
2018-09-30 04:33:21 +00:00
|
|
|
state = state && success;
|
2015-02-01 20:18:38 +00:00
|
|
|
|
|
|
|
// Int left padded with spaces.
|
|
|
|
format = "fish %5d frog";
|
|
|
|
args.clear();
|
|
|
|
args.push_back(5);
|
2015-02-19 15:45:49 +00:00
|
|
|
output = format.sprintf(args, &error);
|
|
|
|
success = (output == String("fish 5 frog") && !error);
|
2015-02-01 20:18:38 +00:00
|
|
|
OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL");
|
2018-09-30 04:33:21 +00:00
|
|
|
state = state && success;
|
2015-02-01 20:18:38 +00:00
|
|
|
|
|
|
|
// Int right padded with spaces.
|
|
|
|
format = "fish %-5d frog";
|
|
|
|
args.clear();
|
|
|
|
args.push_back(5);
|
2015-02-19 15:45:49 +00:00
|
|
|
output = format.sprintf(args, &error);
|
|
|
|
success = (output == String("fish 5 frog") && !error);
|
2015-02-01 20:18:38 +00:00
|
|
|
OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL");
|
2018-09-30 04:33:21 +00:00
|
|
|
state = state && success;
|
2015-02-01 20:18:38 +00:00
|
|
|
|
|
|
|
// Int with sign (positive).
|
|
|
|
format = "fish %+d frog";
|
|
|
|
args.clear();
|
|
|
|
args.push_back(5);
|
2015-02-19 15:45:49 +00:00
|
|
|
output = format.sprintf(args, &error);
|
|
|
|
success = (output == String("fish +5 frog") && !error);
|
2015-02-01 20:18:38 +00:00
|
|
|
OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL");
|
2018-09-30 04:33:21 +00:00
|
|
|
state = state && success;
|
2015-02-01 20:18:38 +00:00
|
|
|
|
|
|
|
// Negative int.
|
|
|
|
format = "fish %d frog";
|
|
|
|
args.clear();
|
|
|
|
args.push_back(-5);
|
2015-02-19 15:45:49 +00:00
|
|
|
output = format.sprintf(args, &error);
|
|
|
|
success = (output == String("fish -5 frog") && !error);
|
2015-01-10 20:44:20 +00:00
|
|
|
OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL");
|
2018-09-30 04:33:21 +00:00
|
|
|
state = state && success;
|
2015-01-10 20:44:20 +00:00
|
|
|
|
|
|
|
// Hex (lower)
|
|
|
|
format = "fish %x frog";
|
|
|
|
args.clear();
|
|
|
|
args.push_back(45);
|
2015-02-19 15:45:49 +00:00
|
|
|
output = format.sprintf(args, &error);
|
|
|
|
success = (output == String("fish 2d frog") && !error);
|
2015-01-10 20:44:20 +00:00
|
|
|
OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL");
|
2018-09-30 04:33:21 +00:00
|
|
|
state = state && success;
|
2015-01-10 20:44:20 +00:00
|
|
|
|
|
|
|
// Hex (upper)
|
|
|
|
format = "fish %X frog";
|
|
|
|
args.clear();
|
|
|
|
args.push_back(45);
|
2015-02-19 15:45:49 +00:00
|
|
|
output = format.sprintf(args, &error);
|
|
|
|
success = (output == String("fish 2D frog") && !error);
|
2015-01-10 20:44:20 +00:00
|
|
|
OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL");
|
2018-09-30 04:33:21 +00:00
|
|
|
state = state && success;
|
2015-01-10 20:44:20 +00:00
|
|
|
|
|
|
|
// Octal
|
|
|
|
format = "fish %o frog";
|
|
|
|
args.clear();
|
|
|
|
args.push_back(99);
|
2015-02-19 15:45:49 +00:00
|
|
|
output = format.sprintf(args, &error);
|
|
|
|
success = (output == String("fish 143 frog") && !error);
|
2015-01-10 20:44:20 +00:00
|
|
|
OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL");
|
2018-09-30 04:33:21 +00:00
|
|
|
state = state && success;
|
2015-01-10 20:44:20 +00:00
|
|
|
|
2015-02-01 20:18:38 +00:00
|
|
|
////// REALS
|
|
|
|
|
2015-01-10 20:44:20 +00:00
|
|
|
// Real
|
|
|
|
format = "fish %f frog";
|
|
|
|
args.clear();
|
|
|
|
args.push_back(99.99);
|
2015-02-19 15:45:49 +00:00
|
|
|
output = format.sprintf(args, &error);
|
|
|
|
success = (output == String("fish 99.990000 frog") && !error);
|
2015-02-01 20:18:38 +00:00
|
|
|
OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL");
|
2018-09-30 04:33:21 +00:00
|
|
|
state = state && success;
|
2015-02-01 20:18:38 +00:00
|
|
|
|
|
|
|
// Real left-padded
|
|
|
|
format = "fish %11f frog";
|
|
|
|
args.clear();
|
|
|
|
args.push_back(99.99);
|
2015-02-19 15:45:49 +00:00
|
|
|
output = format.sprintf(args, &error);
|
|
|
|
success = (output == String("fish 99.990000 frog") && !error);
|
2015-02-01 20:18:38 +00:00
|
|
|
OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL");
|
2018-09-30 04:33:21 +00:00
|
|
|
state = state && success;
|
2015-02-01 20:18:38 +00:00
|
|
|
|
|
|
|
// Real right-padded
|
|
|
|
format = "fish %-11f frog";
|
|
|
|
args.clear();
|
|
|
|
args.push_back(99.99);
|
2015-02-19 15:45:49 +00:00
|
|
|
output = format.sprintf(args, &error);
|
|
|
|
success = (output == String("fish 99.990000 frog") && !error);
|
2015-02-01 20:18:38 +00:00
|
|
|
OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL");
|
2018-09-30 04:33:21 +00:00
|
|
|
state = state && success;
|
2015-02-01 20:18:38 +00:00
|
|
|
|
|
|
|
// Real given int.
|
|
|
|
format = "fish %f frog";
|
|
|
|
args.clear();
|
|
|
|
args.push_back(99);
|
2015-02-19 15:45:49 +00:00
|
|
|
output = format.sprintf(args, &error);
|
|
|
|
success = (output == String("fish 99.000000 frog") && !error);
|
2015-02-01 20:18:38 +00:00
|
|
|
OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL");
|
2018-09-30 04:33:21 +00:00
|
|
|
state = state && success;
|
2015-02-01 20:18:38 +00:00
|
|
|
|
|
|
|
// Real with sign (positive).
|
|
|
|
format = "fish %+f frog";
|
|
|
|
args.clear();
|
|
|
|
args.push_back(99.99);
|
2015-02-19 15:45:49 +00:00
|
|
|
output = format.sprintf(args, &error);
|
|
|
|
success = (output == String("fish +99.990000 frog") && !error);
|
2015-02-01 20:18:38 +00:00
|
|
|
OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL");
|
2018-09-30 04:33:21 +00:00
|
|
|
state = state && success;
|
2015-02-01 20:18:38 +00:00
|
|
|
|
|
|
|
// Real with 1 decimals.
|
|
|
|
format = "fish %.1f frog";
|
|
|
|
args.clear();
|
|
|
|
args.push_back(99.99);
|
2015-02-19 15:45:49 +00:00
|
|
|
output = format.sprintf(args, &error);
|
|
|
|
success = (output == String("fish 100.0 frog") && !error);
|
2015-01-10 20:44:20 +00:00
|
|
|
OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL");
|
2018-09-30 04:33:21 +00:00
|
|
|
state = state && success;
|
2015-01-10 20:44:20 +00:00
|
|
|
|
2015-02-01 20:18:38 +00:00
|
|
|
// Real with 12 decimals.
|
|
|
|
format = "fish %.12f frog";
|
|
|
|
args.clear();
|
|
|
|
args.push_back(99.99);
|
2015-02-19 15:45:49 +00:00
|
|
|
output = format.sprintf(args, &error);
|
|
|
|
success = (output == String("fish 99.990000000000 frog") && !error);
|
2015-02-01 20:18:38 +00:00
|
|
|
OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL");
|
2018-09-30 04:33:21 +00:00
|
|
|
state = state && success;
|
2015-02-01 20:18:38 +00:00
|
|
|
|
|
|
|
// Real with no decimals.
|
|
|
|
format = "fish %.f frog";
|
|
|
|
args.clear();
|
|
|
|
args.push_back(99.99);
|
2015-02-19 15:45:49 +00:00
|
|
|
output = format.sprintf(args, &error);
|
|
|
|
success = (output == String("fish 100 frog") && !error);
|
2015-02-01 20:18:38 +00:00
|
|
|
OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL");
|
2018-09-30 04:33:21 +00:00
|
|
|
state = state && success;
|
2015-02-01 20:18:38 +00:00
|
|
|
|
|
|
|
/////// Strings.
|
|
|
|
|
2015-01-10 20:44:20 +00:00
|
|
|
// String
|
|
|
|
format = "fish %s frog";
|
|
|
|
args.clear();
|
|
|
|
args.push_back("cheese");
|
2015-02-19 15:45:49 +00:00
|
|
|
output = format.sprintf(args, &error);
|
|
|
|
success = (output == String("fish cheese frog") && !error);
|
2015-02-01 20:18:38 +00:00
|
|
|
OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL");
|
2018-09-30 04:33:21 +00:00
|
|
|
state = state && success;
|
2015-02-01 20:18:38 +00:00
|
|
|
|
|
|
|
// String left-padded
|
|
|
|
format = "fish %10s frog";
|
|
|
|
args.clear();
|
|
|
|
args.push_back("cheese");
|
2015-02-19 15:45:49 +00:00
|
|
|
output = format.sprintf(args, &error);
|
|
|
|
success = (output == String("fish cheese frog") && !error);
|
2015-02-01 20:18:38 +00:00
|
|
|
OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL");
|
2018-09-30 04:33:21 +00:00
|
|
|
state = state && success;
|
2015-02-01 20:18:38 +00:00
|
|
|
|
|
|
|
// String right-padded
|
|
|
|
format = "fish %-10s frog";
|
|
|
|
args.clear();
|
|
|
|
args.push_back("cheese");
|
2015-02-19 15:45:49 +00:00
|
|
|
output = format.sprintf(args, &error);
|
|
|
|
success = (output == String("fish cheese frog") && !error);
|
2015-02-01 20:18:38 +00:00
|
|
|
OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL");
|
2018-09-30 04:33:21 +00:00
|
|
|
state = state && success;
|
2015-02-01 20:18:38 +00:00
|
|
|
|
|
|
|
///// Characters
|
|
|
|
|
|
|
|
// Character as string.
|
|
|
|
format = "fish %c frog";
|
|
|
|
args.clear();
|
|
|
|
args.push_back("A");
|
2015-02-19 15:45:49 +00:00
|
|
|
output = format.sprintf(args, &error);
|
|
|
|
success = (output == String("fish A frog") && !error);
|
2015-02-01 20:18:38 +00:00
|
|
|
OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL");
|
2018-09-30 04:33:21 +00:00
|
|
|
state = state && success;
|
2015-02-01 20:18:38 +00:00
|
|
|
|
|
|
|
// Character as int.
|
|
|
|
format = "fish %c frog";
|
|
|
|
args.clear();
|
|
|
|
args.push_back(65);
|
2015-02-19 15:45:49 +00:00
|
|
|
output = format.sprintf(args, &error);
|
|
|
|
success = (output == String("fish A frog") && !error);
|
2015-02-01 20:18:38 +00:00
|
|
|
OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL");
|
2018-09-30 04:33:21 +00:00
|
|
|
state = state && success;
|
2015-02-01 20:18:38 +00:00
|
|
|
|
|
|
|
///// Dynamic width
|
|
|
|
|
|
|
|
// String dynamic width
|
|
|
|
format = "fish %*s frog";
|
|
|
|
args.clear();
|
|
|
|
args.push_back(10);
|
|
|
|
args.push_back("cheese");
|
2015-02-19 15:45:49 +00:00
|
|
|
output = format.sprintf(args, &error);
|
|
|
|
success = (output == String("fish cheese frog") && !error);
|
2015-02-01 20:18:38 +00:00
|
|
|
OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL");
|
2018-09-30 04:33:21 +00:00
|
|
|
state = state && success;
|
2015-02-01 20:18:38 +00:00
|
|
|
|
|
|
|
// Int dynamic width
|
|
|
|
format = "fish %*d frog";
|
|
|
|
args.clear();
|
|
|
|
args.push_back(10);
|
|
|
|
args.push_back(99);
|
2015-02-19 15:45:49 +00:00
|
|
|
output = format.sprintf(args, &error);
|
|
|
|
success = (output == String("fish 99 frog") && !error);
|
2015-02-01 20:18:38 +00:00
|
|
|
OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL");
|
2018-09-30 04:33:21 +00:00
|
|
|
state = state && success;
|
2015-02-01 20:18:38 +00:00
|
|
|
|
|
|
|
// Float dynamic width
|
|
|
|
format = "fish %*.*f frog";
|
|
|
|
args.clear();
|
|
|
|
args.push_back(10);
|
|
|
|
args.push_back(3);
|
|
|
|
args.push_back(99.99);
|
2015-02-19 15:45:49 +00:00
|
|
|
output = format.sprintf(args, &error);
|
|
|
|
success = (output == String("fish 99.990 frog") && !error);
|
2015-02-01 20:18:38 +00:00
|
|
|
OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL");
|
2018-09-30 04:33:21 +00:00
|
|
|
state = state && success;
|
2015-02-01 20:18:38 +00:00
|
|
|
|
|
|
|
///// Errors
|
|
|
|
|
|
|
|
// More formats than arguments.
|
|
|
|
format = "fish %s %s frog";
|
|
|
|
args.clear();
|
|
|
|
args.push_back("cheese");
|
2015-02-19 15:45:49 +00:00
|
|
|
output = format.sprintf(args, &error);
|
|
|
|
success = (output == "not enough arguments for format string" && error);
|
2015-02-01 20:18:38 +00:00
|
|
|
OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL");
|
2018-09-30 04:33:21 +00:00
|
|
|
state = state && success;
|
2015-02-01 20:18:38 +00:00
|
|
|
|
|
|
|
// More arguments than formats.
|
|
|
|
format = "fish %s frog";
|
|
|
|
args.clear();
|
|
|
|
args.push_back("hello");
|
|
|
|
args.push_back("cheese");
|
2015-02-19 15:45:49 +00:00
|
|
|
output = format.sprintf(args, &error);
|
|
|
|
success = (output == "not all arguments converted during string formatting" && error);
|
2015-02-01 20:18:38 +00:00
|
|
|
OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL");
|
2018-09-30 04:33:21 +00:00
|
|
|
state = state && success;
|
2015-02-01 20:18:38 +00:00
|
|
|
|
|
|
|
// Incomplete format.
|
|
|
|
format = "fish %10";
|
|
|
|
args.clear();
|
|
|
|
args.push_back("cheese");
|
2015-02-19 15:45:49 +00:00
|
|
|
output = format.sprintf(args, &error);
|
|
|
|
success = (output == "incomplete format" && error);
|
2015-02-01 20:18:38 +00:00
|
|
|
OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL");
|
2018-09-30 04:33:21 +00:00
|
|
|
state = state && success;
|
2015-02-01 20:18:38 +00:00
|
|
|
|
|
|
|
// Bad character in format string
|
|
|
|
format = "fish %&f frog";
|
|
|
|
args.clear();
|
|
|
|
args.push_back("cheese");
|
2015-02-19 15:45:49 +00:00
|
|
|
output = format.sprintf(args, &error);
|
|
|
|
success = (output == "unsupported format character" && error);
|
2015-02-01 20:18:38 +00:00
|
|
|
OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL");
|
2018-09-30 04:33:21 +00:00
|
|
|
state = state && success;
|
2015-02-01 20:18:38 +00:00
|
|
|
|
|
|
|
// Too many decimals.
|
|
|
|
format = "fish %2.2.2f frog";
|
|
|
|
args.clear();
|
|
|
|
args.push_back(99.99);
|
2015-02-19 15:45:49 +00:00
|
|
|
output = format.sprintf(args, &error);
|
|
|
|
success = (output == "too many decimal points in format" && error);
|
2015-02-01 20:18:38 +00:00
|
|
|
OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL");
|
2018-09-30 04:33:21 +00:00
|
|
|
state = state && success;
|
2015-02-01 20:18:38 +00:00
|
|
|
|
|
|
|
// * not a number
|
|
|
|
format = "fish %*f frog";
|
|
|
|
args.clear();
|
|
|
|
args.push_back("cheese");
|
|
|
|
args.push_back(99.99);
|
2015-02-19 15:45:49 +00:00
|
|
|
output = format.sprintf(args, &error);
|
|
|
|
success = (output == "* wants number" && error);
|
2015-02-01 20:18:38 +00:00
|
|
|
OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL");
|
2018-09-30 04:33:21 +00:00
|
|
|
state = state && success;
|
2015-02-01 20:18:38 +00:00
|
|
|
|
|
|
|
// Character too long.
|
|
|
|
format = "fish %c frog";
|
|
|
|
args.clear();
|
|
|
|
args.push_back("sc");
|
2015-02-19 15:45:49 +00:00
|
|
|
output = format.sprintf(args, &error);
|
|
|
|
success = (output == "%c requires number or single-character string" && error);
|
2015-02-01 20:18:38 +00:00
|
|
|
OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL");
|
2018-09-30 04:33:21 +00:00
|
|
|
state = state && success;
|
2015-02-01 20:18:38 +00:00
|
|
|
|
|
|
|
// Character bad type.
|
|
|
|
format = "fish %c frog";
|
|
|
|
args.clear();
|
|
|
|
args.push_back(Array());
|
2015-02-19 15:45:49 +00:00
|
|
|
output = format.sprintf(args, &error);
|
|
|
|
success = (output == "%c requires number or single-character string" && error);
|
2015-02-01 20:18:38 +00:00
|
|
|
OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL");
|
2018-09-30 04:33:21 +00:00
|
|
|
state = state && success;
|
2015-01-10 20:44:20 +00:00
|
|
|
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
2016-10-19 21:32:36 +00:00
|
|
|
bool test_29() {
|
|
|
|
|
2016-10-20 12:58:00 +00:00
|
|
|
bool state = true;
|
|
|
|
|
2016-10-19 21:32:36 +00:00
|
|
|
IP_Address ip0("2001:0db8:85a3:0000:0000:8a2e:0370:7334");
|
2016-10-20 12:58:00 +00:00
|
|
|
OS::get_singleton()->print("ip0 is %ls\n", String(ip0).c_str());
|
2016-10-19 21:32:36 +00:00
|
|
|
|
2016-12-05 15:32:38 +00:00
|
|
|
IP_Address ip(0x0123, 0x4567, 0x89ab, 0xcdef, true);
|
2016-10-20 12:58:00 +00:00
|
|
|
OS::get_singleton()->print("ip6 is %ls\n", String(ip).c_str());
|
2016-10-19 21:32:36 +00:00
|
|
|
|
|
|
|
IP_Address ip2("fe80::52e5:49ff:fe93:1baf");
|
2016-10-20 12:58:00 +00:00
|
|
|
OS::get_singleton()->print("ip6 is %ls\n", String(ip2).c_str());
|
2016-10-19 21:32:36 +00:00
|
|
|
|
|
|
|
IP_Address ip3("::ffff:192.168.0.1");
|
2016-10-20 12:58:00 +00:00
|
|
|
OS::get_singleton()->print("ip6 is %ls\n", String(ip3).c_str());
|
2016-10-19 21:32:36 +00:00
|
|
|
|
2016-10-20 12:58:00 +00:00
|
|
|
String ip4 = "192.168.0.1";
|
2017-08-21 19:15:36 +00:00
|
|
|
bool success = ip4.is_valid_ip_address();
|
2016-10-20 12:58:00 +00:00
|
|
|
OS::get_singleton()->print("Is valid ipv4: %ls, %s\n", ip4.c_str(), success ? "OK" : "FAIL");
|
2018-09-30 04:33:21 +00:00
|
|
|
state = state && success;
|
2016-10-20 12:58:00 +00:00
|
|
|
|
|
|
|
ip4 = "192.368.0.1";
|
|
|
|
success = (!ip4.is_valid_ip_address());
|
|
|
|
OS::get_singleton()->print("Is invalid ipv4: %ls, %s\n", ip4.c_str(), success ? "OK" : "FAIL");
|
2018-09-30 04:33:21 +00:00
|
|
|
state = state && success;
|
2016-10-20 12:58:00 +00:00
|
|
|
|
|
|
|
String ip6 = "2001:0db8:85a3:0000:0000:8a2e:0370:7334";
|
|
|
|
success = ip6.is_valid_ip_address();
|
|
|
|
OS::get_singleton()->print("Is valid ipv6: %ls, %s\n", ip6.c_str(), success ? "OK" : "FAIL");
|
2018-09-30 04:33:21 +00:00
|
|
|
state = state && success;
|
2016-10-20 12:58:00 +00:00
|
|
|
|
|
|
|
ip6 = "2001:0db8:85j3:0000:0000:8a2e:0370:7334";
|
|
|
|
success = (!ip6.is_valid_ip_address());
|
|
|
|
OS::get_singleton()->print("Is invalid ipv6: %ls, %s\n", ip6.c_str(), success ? "OK" : "FAIL");
|
2018-09-30 04:33:21 +00:00
|
|
|
state = state && success;
|
2016-10-20 12:58:00 +00:00
|
|
|
|
|
|
|
ip6 = "2001:0db8:85f345:0000:0000:8a2e:0370:7334";
|
|
|
|
success = (!ip6.is_valid_ip_address());
|
|
|
|
OS::get_singleton()->print("Is invalid ipv6: %ls, %s\n", ip6.c_str(), success ? "OK" : "FAIL");
|
2018-09-30 04:33:21 +00:00
|
|
|
state = state && success;
|
2016-10-20 12:58:00 +00:00
|
|
|
|
|
|
|
ip6 = "2001:0db8::0:8a2e:370:7334";
|
|
|
|
success = (ip6.is_valid_ip_address());
|
|
|
|
OS::get_singleton()->print("Is valid ipv6: %ls, %s\n", ip6.c_str(), success ? "OK" : "FAIL");
|
2018-09-30 04:33:21 +00:00
|
|
|
state = state && success;
|
2016-10-20 12:58:00 +00:00
|
|
|
|
|
|
|
ip6 = "::ffff:192.168.0.1";
|
|
|
|
success = (ip6.is_valid_ip_address());
|
|
|
|
OS::get_singleton()->print("Is valid ipv6: %ls, %s\n", ip6.c_str(), success ? "OK" : "FAIL");
|
2018-09-30 04:33:21 +00:00
|
|
|
state = state && success;
|
|
|
|
|
|
|
|
return state;
|
|
|
|
};
|
|
|
|
|
|
|
|
bool test_30() {
|
|
|
|
bool state = true;
|
|
|
|
bool success = true;
|
|
|
|
String input = "bytes2var";
|
|
|
|
String output = "Bytes 2 Var";
|
|
|
|
success = (input.capitalize() == output);
|
|
|
|
state = state && success;
|
|
|
|
OS::get_singleton()->print("Capitalize %ls: %ls, %s\n", input.c_str(), output.c_str(), success ? "OK" : "FAIL");
|
|
|
|
|
|
|
|
input = "linear2db";
|
|
|
|
output = "Linear 2 Db";
|
|
|
|
success = (input.capitalize() == output);
|
|
|
|
state = state && success;
|
|
|
|
OS::get_singleton()->print("Capitalize %ls: %ls, %s\n", input.c_str(), output.c_str(), success ? "OK" : "FAIL");
|
|
|
|
|
|
|
|
input = "vector3";
|
|
|
|
output = "Vector 3";
|
|
|
|
success = (input.capitalize() == output);
|
|
|
|
state = state && success;
|
|
|
|
OS::get_singleton()->print("Capitalize %ls: %ls, %s\n", input.c_str(), output.c_str(), success ? "OK" : "FAIL");
|
|
|
|
|
|
|
|
input = "sha256";
|
|
|
|
output = "Sha 256";
|
|
|
|
success = (input.capitalize() == output);
|
|
|
|
state = state && success;
|
|
|
|
OS::get_singleton()->print("Capitalize %ls: %ls, %s\n", input.c_str(), output.c_str(), success ? "OK" : "FAIL");
|
|
|
|
|
|
|
|
input = "2db";
|
|
|
|
output = "2 Db";
|
|
|
|
success = (input.capitalize() == output);
|
|
|
|
state = state && success;
|
|
|
|
OS::get_singleton()->print("Capitalize %ls: %ls, %s\n", input.c_str(), output.c_str(), success ? "OK" : "FAIL");
|
|
|
|
|
|
|
|
input = "PascalCase";
|
|
|
|
output = "Pascal Case";
|
|
|
|
success = (input.capitalize() == output);
|
|
|
|
state = state && success;
|
|
|
|
OS::get_singleton()->print("Capitalize %ls: %ls, %s\n", input.c_str(), output.c_str(), success ? "OK" : "FAIL");
|
|
|
|
|
|
|
|
input = "PascalPascalCase";
|
|
|
|
output = "Pascal Pascal Case";
|
|
|
|
success = (input.capitalize() == output);
|
|
|
|
state = state && success;
|
|
|
|
OS::get_singleton()->print("Capitalize %ls: %ls, %s\n", input.c_str(), output.c_str(), success ? "OK" : "FAIL");
|
|
|
|
|
|
|
|
input = "snake_case";
|
|
|
|
output = "Snake Case";
|
|
|
|
success = (input.capitalize() == output);
|
|
|
|
state = state && success;
|
|
|
|
OS::get_singleton()->print("Capitalize %ls: %ls, %s\n", input.c_str(), output.c_str(), success ? "OK" : "FAIL");
|
|
|
|
|
|
|
|
input = "snake_snake_case";
|
|
|
|
output = "Snake Snake Case";
|
|
|
|
success = (input.capitalize() == output);
|
|
|
|
state = state && success;
|
|
|
|
OS::get_singleton()->print("Capitalize %ls: %ls, %s\n", input.c_str(), output.c_str(), success ? "OK" : "FAIL");
|
|
|
|
|
|
|
|
input = "sha256sum";
|
|
|
|
output = "Sha 256 Sum";
|
|
|
|
success = (input.capitalize() == output);
|
|
|
|
state = state && success;
|
|
|
|
OS::get_singleton()->print("Capitalize %ls: %ls, %s\n", input.c_str(), output.c_str(), success ? "OK" : "FAIL");
|
|
|
|
|
|
|
|
input = "cat2dog";
|
|
|
|
output = "Cat 2 Dog";
|
|
|
|
success = (input.capitalize() == output);
|
|
|
|
state = state && success;
|
|
|
|
OS::get_singleton()->print("Capitalize %ls: %ls, %s\n", input.c_str(), output.c_str(), success ? "OK" : "FAIL");
|
|
|
|
|
|
|
|
input = "function(name)";
|
|
|
|
output = "Function(name)";
|
|
|
|
success = (input.capitalize() == output);
|
|
|
|
state = state && success;
|
|
|
|
OS::get_singleton()->print("Capitalize %ls (existing incorrect behavior): %ls, %s\n", input.c_str(), output.c_str(), success ? "OK" : "FAIL");
|
|
|
|
|
|
|
|
input = "snake_case_function(snake_case_arg)";
|
|
|
|
output = "Snake Case Function(snake Case Arg)";
|
|
|
|
success = (input.capitalize() == output);
|
|
|
|
state = state && success;
|
|
|
|
OS::get_singleton()->print("Capitalize %ls (existing incorrect behavior): %ls, %s\n", input.c_str(), output.c_str(), success ? "OK" : "FAIL");
|
|
|
|
|
|
|
|
input = "snake_case_function( snake_case_arg )";
|
|
|
|
output = "Snake Case Function( Snake Case Arg )";
|
|
|
|
success = (input.capitalize() == output);
|
|
|
|
state = state && success;
|
|
|
|
OS::get_singleton()->print("Capitalize %ls: %ls, %s\n", input.c_str(), output.c_str(), success ? "OK" : "FAIL");
|
2016-10-20 12:58:00 +00:00
|
|
|
|
2019-01-04 16:01:54 +00:00
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool test_31() {
|
|
|
|
bool state = true;
|
|
|
|
bool success;
|
|
|
|
|
|
|
|
String a = "";
|
|
|
|
success = a[0] == 0;
|
|
|
|
OS::get_singleton()->print("Is 0 String[0]:, %s\n", success ? "OK" : "FAIL");
|
|
|
|
if (!success) state = false;
|
|
|
|
|
|
|
|
String b = "Godot";
|
|
|
|
success = b[b.size()] == 0;
|
|
|
|
OS::get_singleton()->print("Is 0 String[size()]:, %s\n", success ? "OK" : "FAIL");
|
|
|
|
if (!success) state = false;
|
|
|
|
|
|
|
|
const String c = "";
|
|
|
|
success = c[0] == 0;
|
|
|
|
OS::get_singleton()->print("Is 0 const String[0]:, %s\n", success ? "OK" : "FAIL");
|
|
|
|
if (!success) state = false;
|
|
|
|
|
|
|
|
const String d = "Godot";
|
|
|
|
success = d[d.size()] == 0;
|
|
|
|
OS::get_singleton()->print("Is 0 const String[size()]:, %s\n", success ? "OK" : "FAIL");
|
|
|
|
if (!success) state = false;
|
|
|
|
|
2016-10-20 12:58:00 +00:00
|
|
|
return state;
|
2016-10-19 21:32:36 +00:00
|
|
|
};
|
|
|
|
|
2019-01-07 17:02:55 +00:00
|
|
|
bool test_32() {
|
|
|
|
|
|
|
|
#define STRIP_TEST(x) \
|
|
|
|
{ \
|
|
|
|
bool success = x; \
|
|
|
|
state = state && success; \
|
|
|
|
if (!success) { \
|
|
|
|
OS::get_singleton()->print("\tfailed at: %s\n", #x); \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
|
|
|
OS::get_singleton()->print("\n\nTest 32: lstrip and rstrip\n");
|
|
|
|
bool state = true;
|
|
|
|
|
|
|
|
// strip none
|
|
|
|
STRIP_TEST(String("abc").lstrip("") == "abc");
|
|
|
|
STRIP_TEST(String("abc").rstrip("") == "abc");
|
|
|
|
// strip one
|
|
|
|
STRIP_TEST(String("abc").lstrip("a") == "bc");
|
|
|
|
STRIP_TEST(String("abc").rstrip("c") == "ab");
|
|
|
|
// strip lots
|
|
|
|
STRIP_TEST(String("bababbababccc").lstrip("ab") == "ccc");
|
|
|
|
STRIP_TEST(String("aaabcbcbcbbcbbc").rstrip("cb") == "aaa");
|
|
|
|
// strip empty string
|
|
|
|
STRIP_TEST(String("").lstrip("") == "");
|
|
|
|
STRIP_TEST(String("").rstrip("") == "");
|
|
|
|
// strip to empty string
|
|
|
|
STRIP_TEST(String("abcabcabc").lstrip("bca") == "");
|
|
|
|
STRIP_TEST(String("abcabcabc").rstrip("bca") == "");
|
|
|
|
// don't strip wrong end
|
|
|
|
STRIP_TEST(String("abc").lstrip("c") == "abc");
|
|
|
|
STRIP_TEST(String("abca").lstrip("a") == "bca");
|
|
|
|
STRIP_TEST(String("abc").rstrip("a") == "abc");
|
|
|
|
STRIP_TEST(String("abca").rstrip("a") == "abc");
|
2019-05-15 17:33:21 +00:00
|
|
|
// in utf-8 "¿" (\u00bf) has the same first byte as "µ" (\u00b5)
|
|
|
|
// and the same second as "ÿ" (\u00ff)
|
2019-01-07 17:02:55 +00:00
|
|
|
STRIP_TEST(String::utf8("¿").lstrip(String::utf8("µÿ")) == String::utf8("¿"));
|
|
|
|
STRIP_TEST(String::utf8("¿").rstrip(String::utf8("µÿ")) == String::utf8("¿"));
|
|
|
|
STRIP_TEST(String::utf8("µ¿ÿ").lstrip(String::utf8("µÿ")) == String::utf8("¿ÿ"));
|
|
|
|
STRIP_TEST(String::utf8("µ¿ÿ").rstrip(String::utf8("µÿ")) == String::utf8("µ¿"));
|
|
|
|
|
|
|
|
// the above tests repeated with additional superfluous strip chars
|
|
|
|
|
|
|
|
// strip none
|
|
|
|
STRIP_TEST(String("abc").lstrip("qwjkl") == "abc");
|
|
|
|
STRIP_TEST(String("abc").rstrip("qwjkl") == "abc");
|
|
|
|
// strip one
|
|
|
|
STRIP_TEST(String("abc").lstrip("qwajkl") == "bc");
|
|
|
|
STRIP_TEST(String("abc").rstrip("qwcjkl") == "ab");
|
|
|
|
// strip lots
|
|
|
|
STRIP_TEST(String("bababbababccc").lstrip("qwabjkl") == "ccc");
|
|
|
|
STRIP_TEST(String("aaabcbcbcbbcbbc").rstrip("qwcbjkl") == "aaa");
|
|
|
|
// strip empty string
|
|
|
|
STRIP_TEST(String("").lstrip("qwjkl") == "");
|
|
|
|
STRIP_TEST(String("").rstrip("qwjkl") == "");
|
|
|
|
// strip to empty string
|
|
|
|
STRIP_TEST(String("abcabcabc").lstrip("qwbcajkl") == "");
|
|
|
|
STRIP_TEST(String("abcabcabc").rstrip("qwbcajkl") == "");
|
|
|
|
// don't strip wrong end
|
|
|
|
STRIP_TEST(String("abc").lstrip("qwcjkl") == "abc");
|
|
|
|
STRIP_TEST(String("abca").lstrip("qwajkl") == "bca");
|
|
|
|
STRIP_TEST(String("abc").rstrip("qwajkl") == "abc");
|
|
|
|
STRIP_TEST(String("abca").rstrip("qwajkl") == "abc");
|
2019-05-15 17:33:21 +00:00
|
|
|
// in utf-8 "¿" (\u00bf) has the same first byte as "µ" (\u00b5)
|
|
|
|
// and the same second as "ÿ" (\u00ff)
|
2019-01-07 17:02:55 +00:00
|
|
|
STRIP_TEST(String::utf8("¿").lstrip(String::utf8("qwaµÿjkl")) == String::utf8("¿"));
|
|
|
|
STRIP_TEST(String::utf8("¿").rstrip(String::utf8("qwaµÿjkl")) == String::utf8("¿"));
|
|
|
|
STRIP_TEST(String::utf8("µ¿ÿ").lstrip(String::utf8("qwaµÿjkl")) == String::utf8("¿ÿ"));
|
|
|
|
STRIP_TEST(String::utf8("µ¿ÿ").rstrip(String::utf8("qwaµÿjkl")) == String::utf8("µ¿"));
|
|
|
|
|
|
|
|
return state;
|
|
|
|
|
|
|
|
#undef STRIP_TEST
|
|
|
|
}
|
|
|
|
|
2019-02-22 18:27:13 +00:00
|
|
|
bool test_33() {
|
|
|
|
OS::get_singleton()->print("\n\nTest 33: parse_utf8(null, -1)\n");
|
|
|
|
|
|
|
|
String empty;
|
2019-06-26 13:08:25 +00:00
|
|
|
return empty.parse_utf8(NULL, -1);
|
2019-02-22 18:27:13 +00:00
|
|
|
}
|
|
|
|
|
2019-03-07 15:51:59 +00:00
|
|
|
bool test_34() {
|
|
|
|
OS::get_singleton()->print("\n\nTest 34: Cyrillic to_lower()\n");
|
|
|
|
|
2019-05-15 17:33:21 +00:00
|
|
|
String upper = String::utf8("АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ");
|
|
|
|
String lower = String::utf8("абвгдеёжзийклмнопрстуфхцчшщъыьэюя");
|
2019-03-07 15:51:59 +00:00
|
|
|
|
|
|
|
String test = upper.to_lower();
|
|
|
|
|
|
|
|
bool state = test == lower;
|
|
|
|
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
typedef bool (*TestFunc)(void);
|
|
|
|
|
|
|
|
TestFunc test_funcs[] = {
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
test_1,
|
|
|
|
test_2,
|
|
|
|
test_3,
|
|
|
|
test_4,
|
|
|
|
test_5,
|
|
|
|
test_6,
|
|
|
|
test_7,
|
|
|
|
test_8,
|
|
|
|
test_9,
|
|
|
|
test_10,
|
|
|
|
test_11,
|
|
|
|
test_12,
|
|
|
|
test_13,
|
|
|
|
test_14,
|
|
|
|
test_15,
|
|
|
|
test_16,
|
|
|
|
test_17,
|
|
|
|
test_18,
|
|
|
|
test_19,
|
|
|
|
test_20,
|
|
|
|
test_21,
|
|
|
|
test_22,
|
|
|
|
test_23,
|
|
|
|
test_24,
|
|
|
|
test_25,
|
|
|
|
test_26,
|
2014-02-26 15:18:05 +00:00
|
|
|
test_27,
|
2015-01-10 20:44:20 +00:00
|
|
|
test_28,
|
2016-10-19 21:32:36 +00:00
|
|
|
test_29,
|
2018-09-30 04:33:21 +00:00
|
|
|
test_30,
|
2019-01-04 16:01:54 +00:00
|
|
|
test_31,
|
2019-01-07 17:02:55 +00:00
|
|
|
test_32,
|
2019-02-22 18:27:13 +00:00
|
|
|
test_33,
|
2019-03-07 15:51:59 +00:00
|
|
|
test_34,
|
2014-02-10 01:10:30 +00:00
|
|
|
0
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
};
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
MainLoop *test() {
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2018-01-18 20:37:17 +00:00
|
|
|
/** A character length != wchar_t may be forced, so the tests won't work */
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_COND_V(sizeof(CharType) != sizeof(wchar_t), NULL);
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
int count = 0;
|
|
|
|
int passed = 0;
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
while (true) {
|
2014-02-10 01:10:30 +00:00
|
|
|
if (!test_funcs[count])
|
|
|
|
break;
|
2017-03-05 15:44:50 +00:00
|
|
|
bool pass = test_funcs[count]();
|
2014-02-10 01:10:30 +00:00
|
|
|
if (pass)
|
|
|
|
passed++;
|
2017-03-05 15:44:50 +00:00
|
|
|
OS::get_singleton()->print("\t%s\n", pass ? "PASS" : "FAILED");
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
count++;
|
|
|
|
}
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
OS::get_singleton()->print("\n\n\n");
|
|
|
|
OS::get_singleton()->print("*************\n");
|
|
|
|
OS::get_singleton()->print("***TOTALS!***\n");
|
|
|
|
OS::get_singleton()->print("*************\n");
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2016-02-02 15:42:09 +00:00
|
|
|
OS::get_singleton()->print("Passed %i of %i tests\n", passed, count);
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2017-12-06 20:36:34 +00:00
|
|
|
} // namespace TestString
|