From dd25dcc36185a890194d09e4d0430567e76bf722 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Fri, 22 May 2015 13:58:56 +0100 Subject: Move unit test functions in next to the code they are testing --- src/string.cc | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'src/string.cc') diff --git a/src/string.cc b/src/string.cc index 2735f087..642b668c 100644 --- a/src/string.cc +++ b/src/string.cc @@ -3,6 +3,7 @@ #include "exception.hh" #include "containers.hh" #include "utf8_iterator.hh" +#include "unit_tests.hh" #include @@ -291,4 +292,49 @@ String format(StringView fmt, ArrayView params) return res; } +UnitTest test_string{[]() +{ + kak_assert(String("youpi ") + "matin" == "youpi matin"); + + Vector splited = split("youpi:matin::tchou\\:kanaky:hihi\\:", ':', '\\'); + kak_assert(splited[0] == "youpi"); + kak_assert(splited[1] == "matin"); + kak_assert(splited[2] == ""); + kak_assert(splited[3] == "tchou:kanaky"); + kak_assert(splited[4] == "hihi:"); + + Vector splitedview = split("youpi:matin::tchou\\:kanaky:hihi\\:", ':'); + kak_assert(splitedview[0] == "youpi"); + kak_assert(splitedview[1] == "matin"); + kak_assert(splitedview[2] == ""); + kak_assert(splitedview[3] == "tchou\\"); + kak_assert(splitedview[4] == "kanaky"); + kak_assert(splitedview[5] == "hihi\\"); + kak_assert(splitedview[6] == ""); + + String escaped = escape("youpi:matin:tchou:", ':', '\\'); + kak_assert(escaped == "youpi\\:matin\\:tchou\\:"); + + kak_assert(prefix_match("tchou kanaky", "tchou")); + kak_assert(prefix_match("tchou kanaky", "tchou kanaky")); + kak_assert(prefix_match("tchou kanaky", "t")); + kak_assert(not prefix_match("tchou kanaky", "c")); + + kak_assert(subsequence_match("tchou kanaky", "tknky")); + kak_assert(subsequence_match("tchou kanaky", "knk")); + kak_assert(subsequence_match("tchou kanaky", "tchou kanaky")); + kak_assert(not subsequence_match("tchou kanaky", "tchou kanaky")); + + kak_assert(format("Youhou {1} {} {0} \\{}", 10, "hehe", 5) == "Youhou hehe 5 10 {}"); + + char buffer[20]; + kak_assert(format_to(buffer, "Hey {}", 15) == "Hey 15"); + + kak_assert(str_to_int("5") == 5); + kak_assert(str_to_int(to_string(INT_MAX)) == INT_MAX); + kak_assert(str_to_int(to_string(INT_MIN)) == INT_MIN); + kak_assert(str_to_int("00") == 0); + kak_assert(str_to_int("-0") == 0); +}}; + } -- cgit v1.2.3