summaryrefslogtreecommitdiff
path: root/bin/tests
diff options
context:
space:
mode:
authorBil Bas (Spooner) <bil.bagpuss@gmail.com>2015-01-10 20:44:20 +0000
committerBil Bas (Spooner) <bil.bagpuss@gmail.com>2015-01-10 20:44:20 +0000
commit7a41f8c604143eec16c232cffda122b095c5108f (patch)
treed75667bb5392db5dea502b0bfbb8e36f914a81e6 /bin/tests
parentd6d85a23c9061149c7996a3b434e6f9b25a81e49 (diff)
Added basic sprintf functionality (e.g. "fish %d %s" % [12, Vector2(1, 2)])
Diffstat (limited to 'bin/tests')
-rw-r--r--bin/tests/test_string.cpp79
1 files changed, 78 insertions, 1 deletions
diff --git a/bin/tests/test_string.cpp b/bin/tests/test_string.cpp
index 66238b066d..c932aeb3b4 100644
--- a/bin/tests/test_string.cpp
+++ b/bin/tests/test_string.cpp
@@ -487,7 +487,7 @@ struct test_27_data {
bool test_27() {
- OS::get_singleton()->print("\n\nTest 26: begins_with\n");
+ OS::get_singleton()->print("\n\nTest 27: begins_with\n");
test_27_data tc[] = {
{"res://foobar", "res://", true},
{"res", "res://", false},
@@ -504,11 +504,87 @@ bool test_27() {
}
if (!state) {
OS::get_singleton()->print("\n\t Failure on:\n\t\tstring: ", tc[i].data, "\n\t\tbegin: ", tc[i].begin, "\n\t\texpected: ", tc[i].expected ? "true" : "false", "\n");
+ break;
}
};
return state;
};
+
+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;
+
+ // %%
+ format = "fish %% frog";
+ args.clear();
+ output = format.sprintf(args);
+ success = (format.sprintf(args) == String("fish % frog"));
+ OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL");
+ if (!success) state = false;
+
+ // Int
+ format = "fish %d frog";
+ args.clear();
+ args.push_back(5);
+ output = format.sprintf(args);
+ success = (format.sprintf(args) == String("fish 5 frog"));
+ OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL");
+ if (!success) state = false;
+
+ // Hex (lower)
+ format = "fish %x frog";
+ args.clear();
+ args.push_back(45);
+ output = format.sprintf(args);
+ success = (format.sprintf(args) == String("fish 2d frog"));
+ OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL");
+ if (!success) state = false;
+
+ // Hex (upper)
+ format = "fish %X frog";
+ args.clear();
+ args.push_back(45);
+ output = format.sprintf(args);
+ success = (format.sprintf(args) == String("fish 2D frog"));
+ OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL");
+ if (!success) state = false;
+
+ // Octal
+ format = "fish %o frog";
+ args.clear();
+ args.push_back(99);
+ output = format.sprintf(args);
+ success = (format.sprintf(args) == String("fish 143 frog"));
+ OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL");
+ if (!success) state = false;
+
+ // Real
+ format = "fish %f frog";
+ args.clear();
+ args.push_back(99.99);
+ output = format.sprintf(args);
+ success = (format.sprintf(args) == String("fish 99.990000 frog"));
+ OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL");
+ if (!success) state = false;
+
+ // String
+ format = "fish %s frog";
+ args.clear();
+ args.push_back("cheese");
+ output = format.sprintf(args);
+ success = (format.sprintf(args) == String("fish cheese frog"));
+ OS::get_singleton()->print(output_format , format.c_str(), output.c_str(), success ? "OK" : "FAIL");
+ if (!success) state = false;
+
+ return state;
+}
+
typedef bool (*TestFunc)(void);
TestFunc test_funcs[] = {
@@ -540,6 +616,7 @@ TestFunc test_funcs[] = {
test_25,
test_26,
test_27,
+ test_28,
0
};