aboutsummaryrefslogtreecommitdiffhomepage
path: root/fish_tests.cpp
diff options
context:
space:
mode:
authorGravatar Kevin Ballard <kevin@sb.org>2014-09-21 19:18:56 -0700
committerGravatar Kevin Ballard <kevin@sb.org>2014-09-21 19:27:26 -0700
commit8f8c4cdd176fda4d93a2d1d4b0ae6321d5706e5f (patch)
tree68c2f6d4eb2bbd7a4b975b7901cc0db95f83b740 /fish_tests.cpp
parentf889ad0fda9bf8d1f354cad37d508e0c4205af48 (diff)
Implement new `read --null` flag
The `--null` flag to `read` makes it split incoming lines on NUL instead of newlines. This is intended for processing the output of a command that uses NUL separators (such as `find -print0`). Fixes #1694.
Diffstat (limited to 'fish_tests.cpp')
-rw-r--r--fish_tests.cpp33
1 files changed, 33 insertions, 0 deletions
diff --git a/fish_tests.cpp b/fish_tests.cpp
index 744da79d..7222065f 100644
--- a/fish_tests.cpp
+++ b/fish_tests.cpp
@@ -65,6 +65,7 @@
#include "input.h"
#include "utf8.h"
#include "env_universal_common.h"
+#include "wcstringutil.h"
static const char * const * s_arguments;
static int s_test_run_count = 0;
@@ -3629,6 +3630,37 @@ static void test_highlighting(void)
}
}
+static void test_wcstring_tok(void)
+{
+ say(L"Testing wcstring_tok");
+ wcstring buff = L"hello world";
+ wcstring needle = L" \t\n";
+ wcstring_range loc = wcstring_tok(buff, needle);
+ if (loc.first == wcstring::npos || buff.substr(loc.first, loc.second) != L"hello")
+ {
+ err(L"Wrong results from first wcstring_tok(): {%zu, %zu}", loc.first, loc.second);
+ }
+ loc = wcstring_tok(buff, needle, loc);
+ if (loc.first == wcstring::npos || buff.substr(loc.first, loc.second) != L"world")
+ {
+ err(L"Wrong results from second wcstring_tok(): {%zu, %zu}", loc.first, loc.second);
+ }
+ loc = wcstring_tok(buff, needle, loc);
+ if (loc.first != wcstring::npos)
+ {
+ err(L"Wrong results from third wcstring_tok(): {%zu, %zu}", loc.first, loc.second);
+ }
+
+ buff = L"hello world";
+ loc = wcstring_tok(buff, needle);
+ // loc is "hello" again
+ loc = wcstring_tok(buff, L"", loc);
+ if (loc.first == wcstring::npos || buff.substr(loc.first, loc.second) != L"world")
+ {
+ err(L"Wrong results from wcstring_tok with empty needle: {%zu, %zu}", loc.first, loc.second);
+ }
+}
+
/**
Main test
*/
@@ -3709,6 +3741,7 @@ int main(int argc, char **argv)
if (should_test_function("autosuggestion_ignores")) test_autosuggestion_ignores();
if (should_test_function("autosuggestion_combining")) test_autosuggestion_combining();
if (should_test_function("autosuggest_suggest_special")) test_autosuggest_suggest_special();
+ if (should_test_function("wcstring_tok")) test_wcstring_tok();
if (should_test_function("history")) history_tests_t::test_history();
if (should_test_function("history_merge")) history_tests_t::test_history_merge();
if (should_test_function("history_races")) history_tests_t::test_history_races();