From 8f8c4cdd176fda4d93a2d1d4b0ae6321d5706e5f Mon Sep 17 00:00:00 2001 From: Kevin Ballard Date: Sun, 21 Sep 2014 19:18:56 -0700 Subject: 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. --- fish_tests.cpp | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'fish_tests.cpp') 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(); -- cgit v1.2.3