From 16a70ce9f8f2832c8ccbf16909050860b4468044 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Sat, 2 Jan 2016 22:50:15 +0100 Subject: [PATCH] some coverage for string prefix/suffix helper so I'll sleep better tonight... --- tests/library/format-helper-test.cpp | 47 ++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/tests/library/format-helper-test.cpp b/tests/library/format-helper-test.cpp index ac4258a38..b7c43824d 100644 --- a/tests/library/format-helper-test.cpp +++ b/tests/library/format-helper-test.cpp @@ -94,6 +94,7 @@ namespace test { { check2String(); checkStringJoin(); + checkPrefixSuffix(); } @@ -142,6 +143,52 @@ namespace test { cout << join(transformIterator(eachElm(dubious) ,justCount)) << endl; } + + + /** @test convenience helpers to deal with prefixes and suffixes */ + void + checkPrefixSuffix() + { + CHECK (startsWith ("abcdef", "abcdef")); + CHECK (startsWith ("abcdef", "abcde")); + CHECK (startsWith ("abcdef", "abcd")); + CHECK (startsWith ("abcdef", "abc")); + CHECK (startsWith ("abcdef", "ab")); + CHECK (startsWith ("abcdef", "a")); + CHECK (startsWith ("abcdef", "")); + CHECK (startsWith ("", "")); + + CHECK (not startsWith ("abc", "abcd")); + CHECK (not startsWith ("a", "ä")); + CHECK (not startsWith ("ä", "a")); + + CHECK (endsWith ("abcdef", "abcdef")); + CHECK (endsWith ("abcdef", "bcdef")); + CHECK (endsWith ("abcdef", "cdef")); + CHECK (endsWith ("abcdef", "def")); + CHECK (endsWith ("abcdef", "ef")); + CHECK (endsWith ("abcdef", "f")); + CHECK (endsWith ("abcdef", "")); + CHECK (endsWith ("", "")); + + CHECK (not endsWith ("abc", " abc")); + CHECK (not endsWith ("a", "ä")); + CHECK (not endsWith ("ä", "a")); + + string abc{"abcdef"}; + removePrefix(abc, "ab"); + CHECK ("cdef" == abc); + removeSuffix(abc, "ef"); + CHECK ("cd" == abc); + + abc = "bcdef"; + removePrefix(abc, "ab"); + CHECK ("bcdef" == abc); + removeSuffix(abc, "abcdef"); + CHECK ("bcdef" == abc); + removeSuffix(abc, "bcdef"); + CHECK (isnil (abc)); + } }; LAUNCHER (FormatHelper_test, "unit common");