summaryrefslogtreecommitdiff
path: root/tests/basic-types
diff options
context:
space:
mode:
authorRico Tzschichholz <ricotz@ubuntu.com>2018-10-30 09:54:56 +0100
committerRico Tzschichholz <ricotz@ubuntu.com>2018-10-30 10:03:21 +0100
commitaadb830b68e86e12a7acc84657ca5de04976d93b (patch)
treee47218d08103311f32852ba5c14e2b9e11ec03b8 /tests/basic-types
parentdc5fcf016f63bf7967a2540118cdde0b9159247d (diff)
downloadvala-aadb830b68e86e12a7acc84657ca5de04976d93b.tar.gz
tests: Add more string method tests
Diffstat (limited to 'tests/basic-types')
-rw-r--r--tests/basic-types/strings.vala77
1 files changed, 77 insertions, 0 deletions
diff --git a/tests/basic-types/strings.vala b/tests/basic-types/strings.vala
index bb27a61e9..a4fcda4f7 100644
--- a/tests/basic-types/strings.vala
+++ b/tests/basic-types/strings.vala
@@ -35,6 +35,83 @@ void test_string () {
assert (t[1] == 'l');
}
+void test_string_joinv () {
+ string[] sa = { "hello", "my", "world" };
+
+ string s = string.joinv (" ", sa);
+ assert (s == "hello my world");
+
+ sa.length = -1;
+ s = string.joinv (":", sa);
+ assert (s == "hello:my:world");
+
+ s = string.joinv ("-", null);
+ assert (s == "");
+}
+
+void test_string_replace () {
+ string s = "hellomyworld";
+
+ s = s.replace ("my", "whole");
+ assert (s == "hellowholeworld");
+}
+
+void test_string_slice () {
+ string s = "hellomyworld";
+
+ string r = s.slice (5, 7);
+ assert (r == "my");
+
+ r = s.slice (-7, 7);
+ assert (r == "my");
+
+ r = s.slice (5, -5);
+ assert (r == "my");
+
+ r = s.slice (-7, -5);
+ assert (r == "my");
+}
+
+void test_string_splice () {
+ string s = "hellomyworld";
+
+ s = s.splice (5, 7);
+ assert (s == "helloworld");
+
+ s = s.splice (5, 5, "whole");
+ assert (s == "hellowholeworld");
+
+ s = s.splice (10, -5, "wide");
+ assert (s == "hellowholewideworld");
+
+ s = s.splice (-14, 5);
+ assert (s == "hellowholewideworld");
+
+ s = s.splice (-14, -5);
+ assert (s == "helloworld");
+}
+
+void test_string_substring () {
+ string s = "hellomyworld";
+
+ string r = s.substring (5, 2);
+ assert (r == "my");
+
+ r = s.substring (-7, 2);
+ assert (r == "my");
+
+ r = s.substring (5);
+ assert (r == "myworld");
+
+ r = s.substring (-7);
+ assert (r == "myworld");
+}
+
void main () {
test_string ();
+ test_string_joinv ();
+ test_string_replace ();
+ test_string_slice ();
+ test_string_splice ();
+ test_string_substring ();
}