codify string
retval for invalid arguments
This is the first, tiny, step in addressing issue #3985.
This commit is contained in:
parent
fddd5fd045
commit
23978aee81
@ -34,8 +34,6 @@ class parser_t;
|
||||
|
||||
#define STRING_ERR_MISSING _(L"%ls: Expected argument\n")
|
||||
|
||||
enum { BUILTIN_STRING_OK = 0, BUILTIN_STRING_NONE = 1, BUILTIN_STRING_ERROR = 2 };
|
||||
|
||||
static void string_error(io_streams_t &streams, const wchar_t *fmt, ...) {
|
||||
streams.err.append(L"string ");
|
||||
va_list va;
|
||||
@ -118,7 +116,7 @@ static int string_escape(parser_t &parser, io_streams_t &streams, int argc, wcha
|
||||
}
|
||||
case '?': {
|
||||
string_unknown_option(parser, streams, argv[0], argv[w.woptind - 1]);
|
||||
return BUILTIN_STRING_ERROR;
|
||||
return STATUS_INVALID_ARGS;
|
||||
}
|
||||
default: {
|
||||
DIE("unexpected opt");
|
||||
@ -130,7 +128,7 @@ static int string_escape(parser_t &parser, io_streams_t &streams, int argc, wcha
|
||||
int i = w.woptind;
|
||||
if (string_args_from_stdin(streams) && argc > i) {
|
||||
string_error(streams, BUILTIN_ERR_TOO_MANY_ARGUMENTS, argv[0]);
|
||||
return BUILTIN_STRING_ERROR;
|
||||
return STATUS_INVALID_ARGS;
|
||||
}
|
||||
|
||||
int nesc = 0;
|
||||
@ -142,7 +140,7 @@ static int string_escape(parser_t &parser, io_streams_t &streams, int argc, wcha
|
||||
nesc++;
|
||||
}
|
||||
|
||||
return nesc > 0 ? BUILTIN_STRING_OK : BUILTIN_STRING_NONE;
|
||||
return nesc > 0 ? STATUS_BUILTIN_OK : STATUS_BUILTIN_ERROR;
|
||||
}
|
||||
|
||||
static int string_join(parser_t &parser, io_streams_t &streams, int argc, wchar_t **argv) {
|
||||
@ -168,7 +166,7 @@ static int string_join(parser_t &parser, io_streams_t &streams, int argc, wchar_
|
||||
}
|
||||
case '?': {
|
||||
string_unknown_option(parser, streams, argv[0], argv[w.woptind - 1]);
|
||||
return BUILTIN_STRING_ERROR;
|
||||
return STATUS_INVALID_ARGS;
|
||||
}
|
||||
default: {
|
||||
DIE("unexpected opt");
|
||||
@ -181,12 +179,12 @@ static int string_join(parser_t &parser, io_streams_t &streams, int argc, wchar_
|
||||
const wchar_t *sep;
|
||||
if ((sep = string_get_arg_argv(&i, argv)) == 0) {
|
||||
string_error(streams, STRING_ERR_MISSING, argv[0]);
|
||||
return BUILTIN_STRING_ERROR;
|
||||
return STATUS_INVALID_ARGS;
|
||||
}
|
||||
|
||||
if (string_args_from_stdin(streams) && argc > i) {
|
||||
string_error(streams, BUILTIN_ERR_TOO_MANY_ARGUMENTS, argv[0]);
|
||||
return BUILTIN_STRING_ERROR;
|
||||
return STATUS_INVALID_ARGS;
|
||||
}
|
||||
|
||||
int nargs = 0;
|
||||
@ -205,7 +203,7 @@ static int string_join(parser_t &parser, io_streams_t &streams, int argc, wchar_
|
||||
streams.out.push_back(L'\n');
|
||||
}
|
||||
|
||||
return nargs > 1 ? BUILTIN_STRING_OK : BUILTIN_STRING_NONE;
|
||||
return nargs > 1 ? STATUS_BUILTIN_OK : STATUS_BUILTIN_ERROR;
|
||||
}
|
||||
|
||||
static int string_length(parser_t &parser, io_streams_t &streams, int argc, wchar_t **argv) {
|
||||
@ -230,7 +228,7 @@ static int string_length(parser_t &parser, io_streams_t &streams, int argc, wcha
|
||||
}
|
||||
case '?': {
|
||||
string_unknown_option(parser, streams, argv[0], argv[w.woptind - 1]);
|
||||
return BUILTIN_STRING_ERROR;
|
||||
return STATUS_INVALID_ARGS;
|
||||
}
|
||||
default: {
|
||||
DIE("unexpected opt");
|
||||
@ -242,7 +240,7 @@ static int string_length(parser_t &parser, io_streams_t &streams, int argc, wcha
|
||||
int i = w.woptind;
|
||||
if (string_args_from_stdin(streams) && argc > i) {
|
||||
string_error(streams, BUILTIN_ERR_TOO_MANY_ARGUMENTS, argv[0]);
|
||||
return BUILTIN_STRING_ERROR;
|
||||
return STATUS_INVALID_ARGS;
|
||||
}
|
||||
|
||||
const wchar_t *arg;
|
||||
@ -259,7 +257,7 @@ static int string_length(parser_t &parser, io_streams_t &streams, int argc, wcha
|
||||
}
|
||||
}
|
||||
|
||||
return nnonempty > 0 ? BUILTIN_STRING_OK : BUILTIN_STRING_NONE;
|
||||
return nnonempty > 0 ? STATUS_BUILTIN_OK : STATUS_BUILTIN_ERROR;
|
||||
}
|
||||
|
||||
struct match_options_t {
|
||||
@ -558,7 +556,7 @@ static int string_match(parser_t &parser, io_streams_t &streams, int argc, wchar
|
||||
}
|
||||
case '?': {
|
||||
string_unknown_option(parser, streams, cmd, argv[w.woptind - 1]);
|
||||
return BUILTIN_STRING_ERROR;
|
||||
return STATUS_INVALID_ARGS;
|
||||
}
|
||||
default: {
|
||||
DIE("unexpected retval from wgetopt_long");
|
||||
@ -570,19 +568,19 @@ static int string_match(parser_t &parser, io_streams_t &streams, int argc, wchar
|
||||
if (opts.entire && opts.index) {
|
||||
streams.err.append_format(BUILTIN_ERR_COMBO2, cmd,
|
||||
_(L"--enter and --index are mutually exclusive"));
|
||||
return BUILTIN_STRING_ERROR;
|
||||
return STATUS_INVALID_ARGS;
|
||||
}
|
||||
|
||||
int i = w.woptind;
|
||||
const wchar_t *pattern;
|
||||
if ((pattern = string_get_arg_argv(&i, argv)) == 0) {
|
||||
string_error(streams, STRING_ERR_MISSING, argv[0]);
|
||||
return BUILTIN_STRING_ERROR;
|
||||
return STATUS_INVALID_ARGS;
|
||||
}
|
||||
|
||||
if (string_args_from_stdin(streams) && argc > i) {
|
||||
string_error(streams, BUILTIN_ERR_TOO_MANY_ARGUMENTS, argv[0]);
|
||||
return BUILTIN_STRING_ERROR;
|
||||
return STATUS_INVALID_ARGS;
|
||||
}
|
||||
|
||||
std::unique_ptr<string_matcher_t> matcher;
|
||||
@ -596,11 +594,11 @@ static int string_match(parser_t &parser, io_streams_t &streams, int argc, wchar
|
||||
wcstring storage;
|
||||
while ((arg = string_get_arg(&i, argv, &storage, streams)) != 0) {
|
||||
if (!matcher->report_matches(arg)) {
|
||||
return BUILTIN_STRING_ERROR;
|
||||
return STATUS_INVALID_ARGS;
|
||||
}
|
||||
}
|
||||
|
||||
return matcher->match_count() > 0 ? BUILTIN_STRING_OK : BUILTIN_STRING_NONE;
|
||||
return matcher->match_count() > 0 ? STATUS_BUILTIN_OK : STATUS_BUILTIN_ERROR;
|
||||
}
|
||||
|
||||
struct replace_options_t {
|
||||
@ -793,7 +791,7 @@ static int string_replace(parser_t &parser, io_streams_t &streams, int argc, wch
|
||||
}
|
||||
case '?': {
|
||||
string_unknown_option(parser, streams, argv[0], argv[w.woptind - 1]);
|
||||
return BUILTIN_STRING_ERROR;
|
||||
return STATUS_INVALID_ARGS;
|
||||
}
|
||||
default: {
|
||||
DIE("unexpected retval from wgetopt_long");
|
||||
@ -806,16 +804,16 @@ static int string_replace(parser_t &parser, io_streams_t &streams, int argc, wch
|
||||
const wchar_t *pattern, *replacement;
|
||||
if ((pattern = string_get_arg_argv(&i, argv)) == 0) {
|
||||
string_error(streams, STRING_ERR_MISSING, argv[0]);
|
||||
return BUILTIN_STRING_ERROR;
|
||||
return STATUS_INVALID_ARGS;
|
||||
}
|
||||
if ((replacement = string_get_arg_argv(&i, argv)) == 0) {
|
||||
string_error(streams, STRING_ERR_MISSING, argv[0]);
|
||||
return BUILTIN_STRING_ERROR;
|
||||
return STATUS_INVALID_ARGS;
|
||||
}
|
||||
|
||||
if (string_args_from_stdin(streams) && argc > i) {
|
||||
string_error(streams, BUILTIN_ERR_TOO_MANY_ARGUMENTS, argv[0]);
|
||||
return BUILTIN_STRING_ERROR;
|
||||
return STATUS_INVALID_ARGS;
|
||||
}
|
||||
|
||||
std::unique_ptr<string_replacer_t> replacer;
|
||||
@ -829,11 +827,11 @@ static int string_replace(parser_t &parser, io_streams_t &streams, int argc, wch
|
||||
wcstring storage;
|
||||
while ((arg = string_get_arg(&i, argv, &storage, streams)) != 0) {
|
||||
if (!replacer->replace_matches(arg)) {
|
||||
return BUILTIN_STRING_ERROR;
|
||||
return STATUS_INVALID_ARGS;
|
||||
}
|
||||
}
|
||||
|
||||
return replacer->replace_count() > 0 ? BUILTIN_STRING_OK : BUILTIN_STRING_NONE;
|
||||
return replacer->replace_count() > 0 ? STATUS_BUILTIN_OK : STATUS_BUILTIN_ERROR;
|
||||
}
|
||||
|
||||
/// Given iterators into a string (forward or reverse), splits the haystack iterators
|
||||
@ -890,7 +888,7 @@ static int string_split(parser_t &parser, io_streams_t &streams, int argc, wchar
|
||||
max = fish_wcstol(w.woptarg);
|
||||
if (errno) {
|
||||
string_error(streams, BUILTIN_ERR_NOT_NUMBER, argv[0], w.woptarg);
|
||||
return BUILTIN_STRING_ERROR;
|
||||
return STATUS_INVALID_ARGS;
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -904,11 +902,11 @@ static int string_split(parser_t &parser, io_streams_t &streams, int argc, wchar
|
||||
}
|
||||
case ':': {
|
||||
string_error(streams, STRING_ERR_MISSING, argv[0]);
|
||||
return BUILTIN_STRING_ERROR;
|
||||
return STATUS_INVALID_ARGS;
|
||||
}
|
||||
case '?': {
|
||||
string_unknown_option(parser, streams, argv[0], argv[w.woptind - 1]);
|
||||
return BUILTIN_STRING_ERROR;
|
||||
return STATUS_INVALID_ARGS;
|
||||
}
|
||||
default: {
|
||||
DIE("unexpected opt");
|
||||
@ -921,13 +919,13 @@ static int string_split(parser_t &parser, io_streams_t &streams, int argc, wchar
|
||||
const wchar_t *sep;
|
||||
if ((sep = string_get_arg_argv(&i, argv)) == NULL) {
|
||||
string_error(streams, STRING_ERR_MISSING, argv[0]);
|
||||
return BUILTIN_STRING_ERROR;
|
||||
return STATUS_INVALID_ARGS;
|
||||
}
|
||||
const wchar_t *sep_end = sep + wcslen(sep);
|
||||
|
||||
if (string_args_from_stdin(streams) && argc > i) {
|
||||
string_error(streams, BUILTIN_ERR_TOO_MANY_ARGUMENTS, argv[0]);
|
||||
return BUILTIN_STRING_ERROR;
|
||||
return STATUS_INVALID_ARGS;
|
||||
}
|
||||
|
||||
wcstring_list_t splits;
|
||||
@ -962,7 +960,7 @@ static int string_split(parser_t &parser, io_streams_t &streams, int argc, wchar
|
||||
}
|
||||
|
||||
// We split something if we have more split values than args.
|
||||
return splits.size() > arg_count ? BUILTIN_STRING_OK : BUILTIN_STRING_NONE;
|
||||
return splits.size() > arg_count ? STATUS_BUILTIN_OK : STATUS_BUILTIN_ERROR;
|
||||
}
|
||||
|
||||
// Helper function to abstract the repeat logic from string_repeat
|
||||
@ -1009,10 +1007,10 @@ static int string_repeat(parser_t &parser, io_streams_t &streams, int argc, wcha
|
||||
if (lcount < 0 || errno == ERANGE) {
|
||||
string_error(streams, _(L"%ls: Invalid count value '%ls'\n"), argv[0],
|
||||
w.woptarg);
|
||||
return BUILTIN_STRING_ERROR;
|
||||
return STATUS_INVALID_ARGS;
|
||||
} else if (errno) {
|
||||
string_error(streams, BUILTIN_ERR_NOT_NUMBER, argv[0], w.woptarg);
|
||||
return BUILTIN_STRING_ERROR;
|
||||
return STATUS_INVALID_ARGS;
|
||||
}
|
||||
count = static_cast<size_t>(lcount);
|
||||
break;
|
||||
@ -1021,10 +1019,10 @@ static int string_repeat(parser_t &parser, io_streams_t &streams, int argc, wcha
|
||||
long lmax = fish_wcstol(w.woptarg);
|
||||
if (lmax < 0 || errno == ERANGE) {
|
||||
string_error(streams, _(L"%ls: Invalid max value '%ls'\n"), argv[0], w.woptarg);
|
||||
return BUILTIN_STRING_ERROR;
|
||||
return STATUS_INVALID_ARGS;
|
||||
} else if (errno) {
|
||||
string_error(streams, BUILTIN_ERR_NOT_NUMBER, argv[0], w.woptarg);
|
||||
return BUILTIN_STRING_ERROR;
|
||||
return STATUS_INVALID_ARGS;
|
||||
}
|
||||
max = static_cast<size_t>(lmax);
|
||||
break;
|
||||
@ -1039,11 +1037,11 @@ static int string_repeat(parser_t &parser, io_streams_t &streams, int argc, wcha
|
||||
}
|
||||
case ':': {
|
||||
string_error(streams, STRING_ERR_MISSING, argv[0]);
|
||||
return BUILTIN_STRING_ERROR;
|
||||
return STATUS_INVALID_ARGS;
|
||||
}
|
||||
case '?': {
|
||||
string_unknown_option(parser, streams, argv[0], argv[w.woptind - 1]);
|
||||
return BUILTIN_STRING_ERROR;
|
||||
return STATUS_INVALID_ARGS;
|
||||
}
|
||||
default: {
|
||||
DIE("unexpected opt");
|
||||
@ -1056,7 +1054,7 @@ static int string_repeat(parser_t &parser, io_streams_t &streams, int argc, wcha
|
||||
|
||||
if (string_args_from_stdin(streams) && argc > i) {
|
||||
string_error(streams, BUILTIN_ERR_TOO_MANY_ARGUMENTS, argv[0]);
|
||||
return BUILTIN_STRING_ERROR;
|
||||
return STATUS_INVALID_ARGS;
|
||||
}
|
||||
|
||||
const wchar_t *to_repeat;
|
||||
@ -1075,7 +1073,7 @@ static int string_repeat(parser_t &parser, io_streams_t &streams, int argc, wcha
|
||||
}
|
||||
}
|
||||
|
||||
return !is_empty ? BUILTIN_STRING_OK : BUILTIN_STRING_NONE;
|
||||
return !is_empty ? STATUS_BUILTIN_OK : STATUS_BUILTIN_ERROR;
|
||||
}
|
||||
|
||||
static int string_sub(parser_t &parser, io_streams_t &streams, int argc, wchar_t **argv) {
|
||||
@ -1105,10 +1103,10 @@ static int string_sub(parser_t &parser, io_streams_t &streams, int argc, wchar_t
|
||||
if (length < 0 || errno == ERANGE) {
|
||||
string_error(streams, _(L"%ls: Invalid length value '%ls'\n"), argv[0],
|
||||
w.woptarg);
|
||||
return BUILTIN_STRING_ERROR;
|
||||
return STATUS_INVALID_ARGS;
|
||||
} else if (errno) {
|
||||
string_error(streams, BUILTIN_ERR_NOT_NUMBER, argv[0], w.woptarg);
|
||||
return BUILTIN_STRING_ERROR;
|
||||
return STATUS_INVALID_ARGS;
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -1121,20 +1119,20 @@ static int string_sub(parser_t &parser, io_streams_t &streams, int argc, wchar_t
|
||||
if (start == 0 || start == LONG_MIN || errno == ERANGE) {
|
||||
string_error(streams, _(L"%ls: Invalid start value '%ls'\n"), argv[0],
|
||||
w.woptarg);
|
||||
return BUILTIN_STRING_ERROR;
|
||||
return STATUS_INVALID_ARGS;
|
||||
} else if (errno) {
|
||||
string_error(streams, BUILTIN_ERR_NOT_NUMBER, argv[0], w.woptarg);
|
||||
return BUILTIN_STRING_ERROR;
|
||||
return STATUS_INVALID_ARGS;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ':': {
|
||||
string_error(streams, STRING_ERR_MISSING, argv[0]);
|
||||
return BUILTIN_STRING_ERROR;
|
||||
return STATUS_INVALID_ARGS;
|
||||
}
|
||||
case '?': {
|
||||
string_unknown_option(parser, streams, argv[0], argv[w.woptind - 1]);
|
||||
return BUILTIN_STRING_ERROR;
|
||||
return STATUS_INVALID_ARGS;
|
||||
}
|
||||
default: {
|
||||
DIE("unexpected opt");
|
||||
@ -1146,7 +1144,7 @@ static int string_sub(parser_t &parser, io_streams_t &streams, int argc, wchar_t
|
||||
int i = w.woptind;
|
||||
if (string_args_from_stdin(streams) && argc > i) {
|
||||
string_error(streams, BUILTIN_ERR_TOO_MANY_ARGUMENTS, argv[0]);
|
||||
return BUILTIN_STRING_ERROR;
|
||||
return STATUS_INVALID_ARGS;
|
||||
}
|
||||
|
||||
int nsub = 0;
|
||||
@ -1180,7 +1178,7 @@ static int string_sub(parser_t &parser, io_streams_t &streams, int argc, wchar_t
|
||||
nsub++;
|
||||
}
|
||||
|
||||
return nsub > 0 ? BUILTIN_STRING_OK : BUILTIN_STRING_NONE;
|
||||
return nsub > 0 ? STATUS_BUILTIN_OK : STATUS_BUILTIN_ERROR;
|
||||
}
|
||||
|
||||
static int string_trim(parser_t &parser, io_streams_t &streams, int argc, wchar_t **argv) {
|
||||
@ -1223,11 +1221,11 @@ static int string_trim(parser_t &parser, io_streams_t &streams, int argc, wchar_
|
||||
}
|
||||
case ':': {
|
||||
string_error(streams, STRING_ERR_MISSING, argv[0]);
|
||||
return BUILTIN_STRING_ERROR;
|
||||
return STATUS_INVALID_ARGS;
|
||||
}
|
||||
case '?': {
|
||||
string_unknown_option(parser, streams, argv[0], argv[w.woptind - 1]);
|
||||
return BUILTIN_STRING_ERROR;
|
||||
return STATUS_INVALID_ARGS;
|
||||
}
|
||||
default: {
|
||||
DIE("unexpected opt");
|
||||
@ -1239,7 +1237,7 @@ static int string_trim(parser_t &parser, io_streams_t &streams, int argc, wchar_
|
||||
int i = w.woptind;
|
||||
if (string_args_from_stdin(streams) && argc > i) {
|
||||
string_error(streams, BUILTIN_ERR_TOO_MANY_ARGUMENTS, argv[0]);
|
||||
return BUILTIN_STRING_ERROR;
|
||||
return STATUS_INVALID_ARGS;
|
||||
}
|
||||
|
||||
// If neither left or right is specified, we do both.
|
||||
@ -1274,7 +1272,7 @@ static int string_trim(parser_t &parser, io_streams_t &streams, int argc, wchar_
|
||||
}
|
||||
}
|
||||
|
||||
return ntrim > 0 ? BUILTIN_STRING_OK : BUILTIN_STRING_NONE;
|
||||
return ntrim > 0 ? STATUS_BUILTIN_OK : STATUS_BUILTIN_ERROR;
|
||||
}
|
||||
|
||||
static const struct string_subcommand {
|
||||
@ -1295,12 +1293,12 @@ int builtin_string(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
||||
if (argc <= 1) {
|
||||
streams.err.append_format(_(L"string: Expected subcommand\n"));
|
||||
builtin_print_help(parser, streams, L"string", streams.err);
|
||||
return BUILTIN_STRING_ERROR;
|
||||
return STATUS_INVALID_ARGS;
|
||||
}
|
||||
|
||||
if (wcscmp(argv[1], L"-h") == 0 || wcscmp(argv[1], L"--help") == 0) {
|
||||
builtin_print_help(parser, streams, L"string", streams.err);
|
||||
return BUILTIN_STRING_OK;
|
||||
return STATUS_BUILTIN_OK;
|
||||
}
|
||||
|
||||
const string_subcommand *subcmd = &string_subcommands[0];
|
||||
@ -1310,7 +1308,7 @@ int builtin_string(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
||||
if (subcmd->handler == 0) {
|
||||
streams.err.append_format(_(L"string: Unknown subcommand '%ls'\n"), argv[1]);
|
||||
builtin_print_help(parser, streams, L"string", streams.err);
|
||||
return BUILTIN_STRING_ERROR;
|
||||
return STATUS_INVALID_ARGS;
|
||||
}
|
||||
|
||||
argc--;
|
||||
|
27
src/common.h
27
src/common.h
@ -850,4 +850,31 @@ bool valid_var_name_char(wchar_t chr);
|
||||
bool valid_var_name(const wchar_t *str);
|
||||
bool valid_var_name(const wcstring &str);
|
||||
bool valid_func_name(const wcstring &str);
|
||||
|
||||
// Return values (`$status` values for fish scripts) for various situations.
|
||||
enum {
|
||||
/// The status code used for normal exit in a command.
|
||||
STATUS_BUILTIN_OK = 0,
|
||||
/// The status code used for failure exit in a command (but not if the args were invalid).
|
||||
STATUS_BUILTIN_ERROR = 1,
|
||||
/// The status code used when a command was not found.
|
||||
STATUS_UNKNOWN_COMMAND = 127,
|
||||
|
||||
/// TODO: Figure out why we have two distinct failure codes for when an external command cannot
|
||||
/// be run.
|
||||
///
|
||||
/// The status code used when an external command can not be run.
|
||||
STATUS_NOT_EXECUTABLE = 126,
|
||||
/// The status code used when an external command can not be run.
|
||||
STATUS_EXEC_FAIL = 125,
|
||||
|
||||
/// The status code used when a wildcard had no matches.
|
||||
STATUS_UNMATCHED_WILDCARD = 124,
|
||||
/// The status code used when illegal command name is encountered.
|
||||
STATUS_ILLEGAL_CMD = 123,
|
||||
/// The status code used when `read` is asked to consume too much data.
|
||||
STATUS_READ_TOO_MUCH = 122,
|
||||
/// The status code used for erroneous argument combinations in a command.
|
||||
STATUS_INVALID_ARGS = 121,
|
||||
};
|
||||
#endif
|
||||
|
@ -3818,253 +3818,311 @@ static void test_string(void) {
|
||||
int expected_rc;
|
||||
const wchar_t *expected_out;
|
||||
} string_tests[] = {
|
||||
{{L"string", L"escape", 0}, 1, L""},
|
||||
{{L"string", L"escape", L"", 0}, 0, L"''\n"},
|
||||
{{L"string", L"escape", L"-n", L"", 0}, 0, L"\n"},
|
||||
{{L"string", L"escape", L"a", 0}, 0, L"a\n"},
|
||||
{{L"string", L"escape", L"\x07", 0}, 0, L"\\cg\n"},
|
||||
{{L"string", L"escape", L"\"x\"", 0}, 0, L"'\"x\"'\n"},
|
||||
{{L"string", L"escape", L"hello world", 0}, 0, L"'hello world'\n"},
|
||||
{{L"string", L"escape", L"-n", L"hello world", 0}, 0, L"hello\\ world\n"},
|
||||
{{L"string", L"escape", L"hello", L"world", 0}, 0, L"hello\nworld\n"},
|
||||
{{L"string", L"escape", L"-n", L"~", 0}, 0, L"\\~\n"},
|
||||
{{L"string", L"escape", 0}, STATUS_BUILTIN_ERROR, L""},
|
||||
{{L"string", L"escape", L"", 0}, STATUS_BUILTIN_OK, L"''\n"},
|
||||
{{L"string", L"escape", L"-n", L"", 0}, STATUS_BUILTIN_OK, L"\n"},
|
||||
{{L"string", L"escape", L"a", 0}, STATUS_BUILTIN_OK, L"a\n"},
|
||||
{{L"string", L"escape", L"\x07", 0}, STATUS_BUILTIN_OK, L"\\cg\n"},
|
||||
{{L"string", L"escape", L"\"x\"", 0}, STATUS_BUILTIN_OK, L"'\"x\"'\n"},
|
||||
{{L"string", L"escape", L"hello world", 0}, STATUS_BUILTIN_OK, L"'hello world'\n"},
|
||||
{{L"string", L"escape", L"-n", L"hello world", 0}, STATUS_BUILTIN_OK, L"hello\\ world\n"},
|
||||
{{L"string", L"escape", L"hello", L"world", 0}, STATUS_BUILTIN_OK, L"hello\nworld\n"},
|
||||
{{L"string", L"escape", L"-n", L"~", 0}, STATUS_BUILTIN_OK, L"\\~\n"},
|
||||
|
||||
{{L"string", L"join", 0}, 2, L""},
|
||||
{{L"string", L"join", L"", 0}, 1, L""},
|
||||
{{L"string", L"join", L"", L"", L"", L"", 0}, 0, L"\n"},
|
||||
{{L"string", L"join", L"", L"a", L"b", L"c", 0}, 0, L"abc\n"},
|
||||
{{L"string", L"join", L".", L"fishshell", L"com", 0}, 0, L"fishshell.com\n"},
|
||||
{{L"string", L"join", L"/", L"usr", 0}, 1, L"usr\n"},
|
||||
{{L"string", L"join", L"/", L"usr", L"local", L"bin", 0}, 0, L"usr/local/bin\n"},
|
||||
{{L"string", L"join", L"...", L"3", L"2", L"1", 0}, 0, L"3...2...1\n"},
|
||||
{{L"string", L"join", L"-q", 0}, 2, L""},
|
||||
{{L"string", L"join", L"-q", L".", 0}, 1, L""},
|
||||
{{L"string", L"join", L"-q", L".", L".", 0}, 1, L""},
|
||||
{{L"string", L"join", 0}, STATUS_INVALID_ARGS, L""},
|
||||
{{L"string", L"join", L"", 0}, STATUS_BUILTIN_ERROR, L""},
|
||||
{{L"string", L"join", L"", L"", L"", L"", 0}, STATUS_BUILTIN_OK, L"\n"},
|
||||
{{L"string", L"join", L"", L"a", L"b", L"c", 0}, STATUS_BUILTIN_OK, L"abc\n"},
|
||||
{{L"string", L"join", L".", L"fishshell", L"com", 0},
|
||||
STATUS_BUILTIN_OK,
|
||||
L"fishshell.com\n"},
|
||||
{{L"string", L"join", L"/", L"usr", 0}, STATUS_BUILTIN_ERROR, L"usr\n"},
|
||||
{{L"string", L"join", L"/", L"usr", L"local", L"bin", 0},
|
||||
STATUS_BUILTIN_OK,
|
||||
L"usr/local/bin\n"},
|
||||
{{L"string", L"join", L"...", L"3", L"2", L"1", 0}, STATUS_BUILTIN_OK, L"3...2...1\n"},
|
||||
{{L"string", L"join", L"-q", 0}, STATUS_INVALID_ARGS, L""},
|
||||
{{L"string", L"join", L"-q", L".", 0}, STATUS_BUILTIN_ERROR, L""},
|
||||
{{L"string", L"join", L"-q", L".", L".", 0}, STATUS_BUILTIN_ERROR, L""},
|
||||
|
||||
{{L"string", L"length", 0}, 1, L""},
|
||||
{{L"string", L"length", L"", 0}, 1, L"0\n"},
|
||||
{{L"string", L"length", L"", L"", L"", 0}, 1, L"0\n0\n0\n"},
|
||||
{{L"string", L"length", L"a", 0}, 0, L"1\n"},
|
||||
{{L"string", L"length", L"\U0002008A", 0}, 0, L"1\n"},
|
||||
{{L"string", L"length", L"um", L"dois", L"três", 0}, 0, L"2\n4\n4\n"},
|
||||
{{L"string", L"length", L"um", L"dois", L"três", 0}, 0, L"2\n4\n4\n"},
|
||||
{{L"string", L"length", L"-q", 0}, 1, L""},
|
||||
{{L"string", L"length", L"-q", L"", 0}, 1, L""},
|
||||
{{L"string", L"length", L"-q", L"a", 0}, 0, L""},
|
||||
{{L"string", L"length", 0}, STATUS_BUILTIN_ERROR, L""},
|
||||
{{L"string", L"length", L"", 0}, STATUS_BUILTIN_ERROR, L"0\n"},
|
||||
{{L"string", L"length", L"", L"", L"", 0}, STATUS_BUILTIN_ERROR, L"0\n0\n0\n"},
|
||||
{{L"string", L"length", L"a", 0}, STATUS_BUILTIN_OK, L"1\n"},
|
||||
{{L"string", L"length", L"\U0002008A", 0}, STATUS_BUILTIN_OK, L"1\n"},
|
||||
{{L"string", L"length", L"um", L"dois", L"três", 0}, STATUS_BUILTIN_OK, L"2\n4\n4\n"},
|
||||
{{L"string", L"length", L"um", L"dois", L"três", 0}, STATUS_BUILTIN_OK, L"2\n4\n4\n"},
|
||||
{{L"string", L"length", L"-q", 0}, STATUS_BUILTIN_ERROR, L""},
|
||||
{{L"string", L"length", L"-q", L"", 0}, STATUS_BUILTIN_ERROR, L""},
|
||||
{{L"string", L"length", L"-q", L"a", 0}, STATUS_BUILTIN_OK, L""},
|
||||
|
||||
{{L"string", L"match", 0}, 2, L""},
|
||||
{{L"string", L"match", L"", 0}, 1, L""},
|
||||
{{L"string", L"match", L"", L"", 0}, 0, L"\n"},
|
||||
{{L"string", L"match", L"?", L"a", 0}, 0, L"a\n"},
|
||||
{{L"string", L"match", L"*", L"", 0}, 0, L"\n"},
|
||||
{{L"string", L"match", L"**", L"", 0}, 0, L"\n"},
|
||||
{{L"string", L"match", L"*", L"xyzzy", 0}, 0, L"xyzzy\n"},
|
||||
{{L"string", L"match", L"**", L"plugh", 0}, 0, L"plugh\n"},
|
||||
{{L"string", L"match", L"a*b", L"axxb", 0}, 0, L"axxb\n"},
|
||||
{{L"string", L"match", L"a??b", L"axxb", 0}, 0, L"axxb\n"},
|
||||
{{L"string", L"match", L"-i", L"a??B", L"axxb", 0}, 0, L"axxb\n"},
|
||||
{{L"string", L"match", L"-i", L"a??b", L"Axxb", 0}, 0, L"Axxb\n"},
|
||||
{{L"string", L"match", L"a*", L"axxb", 0}, 0, L"axxb\n"},
|
||||
{{L"string", L"match", L"*a", L"xxa", 0}, 0, L"xxa\n"},
|
||||
{{L"string", L"match", L"*a*", L"axa", 0}, 0, L"axa\n"},
|
||||
{{L"string", L"match", L"*a*", L"xax", 0}, 0, L"xax\n"},
|
||||
{{L"string", L"match", L"*a*", L"bxa", 0}, 0, L"bxa\n"},
|
||||
{{L"string", L"match", L"*a", L"a", 0}, 0, L"a\n"},
|
||||
{{L"string", L"match", L"a*", L"a", 0}, 0, L"a\n"},
|
||||
{{L"string", L"match", L"a*b*c", L"axxbyyc", 0}, 0, L"axxbyyc\n"},
|
||||
{{L"string", L"match", L"a*b?c", L"axxbyc", 0}, 0, L"axxbyc\n"},
|
||||
{{L"string", L"match", L"*?", L"a", 0}, 0, L"a\n"},
|
||||
{{L"string", L"match", L"*?", L"ab", 0}, 0, L"ab\n"},
|
||||
{{L"string", L"match", L"?*", L"a", 0}, 0, L"a\n"},
|
||||
{{L"string", L"match", L"?*", L"ab", 0}, 0, L"ab\n"},
|
||||
{{L"string", L"match", L"\\*", L"*", 0}, 0, L"*\n"},
|
||||
{{L"string", L"match", L"a*\\", L"abc\\", 0}, 0, L"abc\\\n"},
|
||||
{{L"string", L"match", L"a*\\?", L"abc?", 0}, 0, L"abc?\n"},
|
||||
{{L"string", L"match", 0}, STATUS_INVALID_ARGS, L""},
|
||||
{{L"string", L"match", L"", 0}, STATUS_BUILTIN_ERROR, L""},
|
||||
{{L"string", L"match", L"", L"", 0}, STATUS_BUILTIN_OK, L"\n"},
|
||||
{{L"string", L"match", L"?", L"a", 0}, STATUS_BUILTIN_OK, L"a\n"},
|
||||
{{L"string", L"match", L"*", L"", 0}, STATUS_BUILTIN_OK, L"\n"},
|
||||
{{L"string", L"match", L"**", L"", 0}, STATUS_BUILTIN_OK, L"\n"},
|
||||
{{L"string", L"match", L"*", L"xyzzy", 0}, STATUS_BUILTIN_OK, L"xyzzy\n"},
|
||||
{{L"string", L"match", L"**", L"plugh", 0}, STATUS_BUILTIN_OK, L"plugh\n"},
|
||||
{{L"string", L"match", L"a*b", L"axxb", 0}, STATUS_BUILTIN_OK, L"axxb\n"},
|
||||
{{L"string", L"match", L"a??b", L"axxb", 0}, STATUS_BUILTIN_OK, L"axxb\n"},
|
||||
{{L"string", L"match", L"-i", L"a??B", L"axxb", 0}, STATUS_BUILTIN_OK, L"axxb\n"},
|
||||
{{L"string", L"match", L"-i", L"a??b", L"Axxb", 0}, STATUS_BUILTIN_OK, L"Axxb\n"},
|
||||
{{L"string", L"match", L"a*", L"axxb", 0}, STATUS_BUILTIN_OK, L"axxb\n"},
|
||||
{{L"string", L"match", L"*a", L"xxa", 0}, STATUS_BUILTIN_OK, L"xxa\n"},
|
||||
{{L"string", L"match", L"*a*", L"axa", 0}, STATUS_BUILTIN_OK, L"axa\n"},
|
||||
{{L"string", L"match", L"*a*", L"xax", 0}, STATUS_BUILTIN_OK, L"xax\n"},
|
||||
{{L"string", L"match", L"*a*", L"bxa", 0}, STATUS_BUILTIN_OK, L"bxa\n"},
|
||||
{{L"string", L"match", L"*a", L"a", 0}, STATUS_BUILTIN_OK, L"a\n"},
|
||||
{{L"string", L"match", L"a*", L"a", 0}, STATUS_BUILTIN_OK, L"a\n"},
|
||||
{{L"string", L"match", L"a*b*c", L"axxbyyc", 0}, STATUS_BUILTIN_OK, L"axxbyyc\n"},
|
||||
{{L"string", L"match", L"a*b?c", L"axxbyc", 0}, STATUS_BUILTIN_OK, L"axxbyc\n"},
|
||||
{{L"string", L"match", L"*?", L"a", 0}, STATUS_BUILTIN_OK, L"a\n"},
|
||||
{{L"string", L"match", L"*?", L"ab", 0}, STATUS_BUILTIN_OK, L"ab\n"},
|
||||
{{L"string", L"match", L"?*", L"a", 0}, STATUS_BUILTIN_OK, L"a\n"},
|
||||
{{L"string", L"match", L"?*", L"ab", 0}, STATUS_BUILTIN_OK, L"ab\n"},
|
||||
{{L"string", L"match", L"\\*", L"*", 0}, STATUS_BUILTIN_OK, L"*\n"},
|
||||
{{L"string", L"match", L"a*\\", L"abc\\", 0}, STATUS_BUILTIN_OK, L"abc\\\n"},
|
||||
{{L"string", L"match", L"a*\\?", L"abc?", 0}, STATUS_BUILTIN_OK, L"abc?\n"},
|
||||
|
||||
{{L"string", L"match", L"?", L"", 0}, 1, L""},
|
||||
{{L"string", L"match", L"?", L"ab", 0}, 1, L""},
|
||||
{{L"string", L"match", L"??", L"a", 0}, 1, L""},
|
||||
{{L"string", L"match", L"?a", L"a", 0}, 1, L""},
|
||||
{{L"string", L"match", L"a?", L"a", 0}, 1, L""},
|
||||
{{L"string", L"match", L"a??B", L"axxb", 0}, 1, L""},
|
||||
{{L"string", L"match", L"a*b", L"axxbc", 0}, 1, L""},
|
||||
{{L"string", L"match", L"*b", L"bbba", 0}, 1, L""},
|
||||
{{L"string", L"match", L"0x[0-9a-fA-F][0-9a-fA-F]", L"0xbad", 0}, 1, L""},
|
||||
{{L"string", L"match", L"?", L"", 0}, STATUS_BUILTIN_ERROR, L""},
|
||||
{{L"string", L"match", L"?", L"ab", 0}, STATUS_BUILTIN_ERROR, L""},
|
||||
{{L"string", L"match", L"??", L"a", 0}, STATUS_BUILTIN_ERROR, L""},
|
||||
{{L"string", L"match", L"?a", L"a", 0}, STATUS_BUILTIN_ERROR, L""},
|
||||
{{L"string", L"match", L"a?", L"a", 0}, STATUS_BUILTIN_ERROR, L""},
|
||||
{{L"string", L"match", L"a??B", L"axxb", 0}, STATUS_BUILTIN_ERROR, L""},
|
||||
{{L"string", L"match", L"a*b", L"axxbc", 0}, STATUS_BUILTIN_ERROR, L""},
|
||||
{{L"string", L"match", L"*b", L"bbba", 0}, STATUS_BUILTIN_ERROR, L""},
|
||||
{{L"string", L"match", L"0x[0-9a-fA-F][0-9a-fA-F]", L"0xbad", 0},
|
||||
STATUS_BUILTIN_ERROR,
|
||||
L""},
|
||||
|
||||
{{L"string", L"match", L"-a", L"*", L"ab", L"cde", 0}, 0, L"ab\ncde\n"},
|
||||
{{L"string", L"match", L"*", L"ab", L"cde", 0}, 0, L"ab\ncde\n"},
|
||||
{{L"string", L"match", L"-n", L"*d*", L"cde", 0}, 0, L"1 3\n"},
|
||||
{{L"string", L"match", L"-n", L"*x*", L"cde", 0}, 1, L""},
|
||||
{{L"string", L"match", L"-q", L"a*", L"b", L"c", 0}, 1, L""},
|
||||
{{L"string", L"match", L"-q", L"a*", L"b", L"a", 0}, 0, L""},
|
||||
{{L"string", L"match", L"-a", L"*", L"ab", L"cde", 0}, STATUS_BUILTIN_OK, L"ab\ncde\n"},
|
||||
{{L"string", L"match", L"*", L"ab", L"cde", 0}, STATUS_BUILTIN_OK, L"ab\ncde\n"},
|
||||
{{L"string", L"match", L"-n", L"*d*", L"cde", 0}, STATUS_BUILTIN_OK, L"1 3\n"},
|
||||
{{L"string", L"match", L"-n", L"*x*", L"cde", 0}, STATUS_BUILTIN_ERROR, L""},
|
||||
{{L"string", L"match", L"-q", L"a*", L"b", L"c", 0}, STATUS_BUILTIN_ERROR, L""},
|
||||
{{L"string", L"match", L"-q", L"a*", L"b", L"a", 0}, STATUS_BUILTIN_OK, L""},
|
||||
|
||||
{{L"string", L"match", L"-r", 0}, 2, L""},
|
||||
{{L"string", L"match", L"-r", L"", 0}, 1, L""},
|
||||
{{L"string", L"match", L"-r", L"", L"", 0}, 0, L"\n"},
|
||||
{{L"string", L"match", L"-r", L".", L"a", 0}, 0, L"a\n"},
|
||||
{{L"string", L"match", L"-r", L".*", L"", 0}, 0, L"\n"},
|
||||
{{L"string", L"match", L"-r", L"a*b", L"b", 0}, 0, L"b\n"},
|
||||
{{L"string", L"match", L"-r", L"a*b", L"aab", 0}, 0, L"aab\n"},
|
||||
{{L"string", L"match", L"-r", L"-i", L"a*b", L"Aab", 0}, 0, L"Aab\n"},
|
||||
{{L"string", L"match", L"-r", L"-a", L"a[bc]", L"abadac", 0}, 0, L"ab\nac\n"},
|
||||
{{L"string", L"match", L"-r", L"a", L"xaxa", L"axax", 0}, 0, L"a\na\n"},
|
||||
{{L"string", L"match", L"-r", L"-a", L"a", L"xaxa", L"axax", 0}, 0, L"a\na\na\na\n"},
|
||||
{{L"string", L"match", L"-r", L"a[bc]", L"abadac", 0}, 0, L"ab\n"},
|
||||
{{L"string", L"match", L"-r", L"-q", L"a[bc]", L"abadac", 0}, 0, L""},
|
||||
{{L"string", L"match", L"-r", L"-q", L"a[bc]", L"ad", 0}, 1, L""},
|
||||
{{L"string", L"match", L"-r", L"(a+)b(c)", L"aabc", 0}, 0, L"aabc\naa\nc\n"},
|
||||
{{L"string", L"match", L"-r", 0}, STATUS_INVALID_ARGS, L""},
|
||||
{{L"string", L"match", L"-r", L"", 0}, STATUS_BUILTIN_ERROR, L""},
|
||||
{{L"string", L"match", L"-r", L"", L"", 0}, STATUS_BUILTIN_OK, L"\n"},
|
||||
{{L"string", L"match", L"-r", L".", L"a", 0}, STATUS_BUILTIN_OK, L"a\n"},
|
||||
{{L"string", L"match", L"-r", L".*", L"", 0}, STATUS_BUILTIN_OK, L"\n"},
|
||||
{{L"string", L"match", L"-r", L"a*b", L"b", 0}, STATUS_BUILTIN_OK, L"b\n"},
|
||||
{{L"string", L"match", L"-r", L"a*b", L"aab", 0}, STATUS_BUILTIN_OK, L"aab\n"},
|
||||
{{L"string", L"match", L"-r", L"-i", L"a*b", L"Aab", 0}, STATUS_BUILTIN_OK, L"Aab\n"},
|
||||
{{L"string", L"match", L"-r", L"-a", L"a[bc]", L"abadac", 0},
|
||||
STATUS_BUILTIN_OK,
|
||||
L"ab\nac\n"},
|
||||
{{L"string", L"match", L"-r", L"a", L"xaxa", L"axax", 0}, STATUS_BUILTIN_OK, L"a\na\n"},
|
||||
{{L"string", L"match", L"-r", L"-a", L"a", L"xaxa", L"axax", 0},
|
||||
STATUS_BUILTIN_OK,
|
||||
L"a\na\na\na\n"},
|
||||
{{L"string", L"match", L"-r", L"a[bc]", L"abadac", 0}, STATUS_BUILTIN_OK, L"ab\n"},
|
||||
{{L"string", L"match", L"-r", L"-q", L"a[bc]", L"abadac", 0}, STATUS_BUILTIN_OK, L""},
|
||||
{{L"string", L"match", L"-r", L"-q", L"a[bc]", L"ad", 0}, STATUS_BUILTIN_ERROR, L""},
|
||||
{{L"string", L"match", L"-r", L"(a+)b(c)", L"aabc", 0},
|
||||
STATUS_BUILTIN_OK,
|
||||
L"aabc\naa\nc\n"},
|
||||
{{L"string", L"match", L"-r", L"-a", L"(a)b(c)", L"abcabc", 0},
|
||||
0,
|
||||
STATUS_BUILTIN_OK,
|
||||
L"abc\na\nc\nabc\na\nc\n"},
|
||||
{{L"string", L"match", L"-r", L"(a)b(c)", L"abcabc", 0}, 0, L"abc\na\nc\n"},
|
||||
{{L"string", L"match", L"-r", L"(a|(z))(bc)", L"abc", 0}, 0, L"abc\na\nbc\n"},
|
||||
{{L"string", L"match", L"-r", L"-n", L"a", L"ada", L"dad", 0}, 0, L"1 1\n2 1\n"},
|
||||
{{L"string", L"match", L"-r", L"-n", L"-a", L"a", L"bacadae", 0}, 0, L"2 1\n4 1\n6 1\n"},
|
||||
{{L"string", L"match", L"-r", L"-n", L"(a).*(b)", L"a---b", 0}, 0, L"1 5\n1 1\n5 1\n"},
|
||||
{{L"string", L"match", L"-r", L"-n", L"(a)(b)", L"ab", 0}, 0, L"1 2\n1 1\n2 1\n"},
|
||||
{{L"string", L"match", L"-r", L"-n", L"(a)(b)", L"abab", 0}, 0, L"1 2\n1 1\n2 1\n"},
|
||||
{{L"string", L"match", L"-r", L"(a)b(c)", L"abcabc", 0}, STATUS_BUILTIN_OK, L"abc\na\nc\n"},
|
||||
{{L"string", L"match", L"-r", L"(a|(z))(bc)", L"abc", 0},
|
||||
STATUS_BUILTIN_OK,
|
||||
L"abc\na\nbc\n"},
|
||||
{{L"string", L"match", L"-r", L"-n", L"a", L"ada", L"dad", 0},
|
||||
STATUS_BUILTIN_OK,
|
||||
L"1 1\n2 1\n"},
|
||||
{{L"string", L"match", L"-r", L"-n", L"-a", L"a", L"bacadae", 0},
|
||||
STATUS_BUILTIN_OK,
|
||||
L"2 1\n4 1\n6 1\n"},
|
||||
{{L"string", L"match", L"-r", L"-n", L"(a).*(b)", L"a---b", 0},
|
||||
STATUS_BUILTIN_OK,
|
||||
L"1 5\n1 1\n5 1\n"},
|
||||
{{L"string", L"match", L"-r", L"-n", L"(a)(b)", L"ab", 0},
|
||||
STATUS_BUILTIN_OK,
|
||||
L"1 2\n1 1\n2 1\n"},
|
||||
{{L"string", L"match", L"-r", L"-n", L"(a)(b)", L"abab", 0},
|
||||
STATUS_BUILTIN_OK,
|
||||
L"1 2\n1 1\n2 1\n"},
|
||||
{{L"string", L"match", L"-r", L"-n", L"-a", L"(a)(b)", L"abab", 0},
|
||||
0,
|
||||
STATUS_BUILTIN_OK,
|
||||
L"1 2\n1 1\n2 1\n3 2\n3 1\n4 1\n"},
|
||||
{{L"string", L"match", L"-r", L"*", L"", 0}, 2, L""},
|
||||
{{L"string", L"match", L"-r", L"-a", L"a*", L"b", 0}, 0, L"\n\n"},
|
||||
{{L"string", L"match", L"-r", L"foo\\Kbar", L"foobar", 0}, 0, L"bar\n"},
|
||||
{{L"string", L"match", L"-r", L"(foo)\\Kbar", L"foobar", 0}, 0, L"bar\nfoo\n"},
|
||||
{{L"string", L"match", L"-r", L"(?=ab\\K)", L"ab", 0}, 0, L"\n"},
|
||||
{{L"string", L"match", L"-r", L"(?=ab\\K)..(?=cd\\K)", L"abcd", 0}, 0, L"\n"},
|
||||
{{L"string", L"match", L"-r", L"*", L"", 0}, STATUS_INVALID_ARGS, L""},
|
||||
{{L"string", L"match", L"-r", L"-a", L"a*", L"b", 0}, STATUS_BUILTIN_OK, L"\n\n"},
|
||||
{{L"string", L"match", L"-r", L"foo\\Kbar", L"foobar", 0}, STATUS_BUILTIN_OK, L"bar\n"},
|
||||
{{L"string", L"match", L"-r", L"(foo)\\Kbar", L"foobar", 0},
|
||||
STATUS_BUILTIN_OK,
|
||||
L"bar\nfoo\n"},
|
||||
{{L"string", L"match", L"-r", L"(?=ab\\K)", L"ab", 0}, STATUS_BUILTIN_OK, L"\n"},
|
||||
{{L"string", L"match", L"-r", L"(?=ab\\K)..(?=cd\\K)", L"abcd", 0},
|
||||
STATUS_BUILTIN_OK,
|
||||
L"\n"},
|
||||
|
||||
{{L"string", L"replace", 0}, 2, L""},
|
||||
{{L"string", L"replace", L"", 0}, 2, L""},
|
||||
{{L"string", L"replace", L"", L"", 0}, 1, L""},
|
||||
{{L"string", L"replace", L"", L"", L"", 0}, 1, L"\n"},
|
||||
{{L"string", L"replace", L"", L"", L" ", 0}, 1, L" \n"},
|
||||
{{L"string", L"replace", L"a", L"b", L"", 0}, 1, L"\n"},
|
||||
{{L"string", L"replace", L"a", L"b", L"a", 0}, 0, L"b\n"},
|
||||
{{L"string", L"replace", L"a", L"b", L"xax", 0}, 0, L"xbx\n"},
|
||||
{{L"string", L"replace", L"a", L"b", L"xax", L"axa", 0}, 0, L"xbx\nbxa\n"},
|
||||
{{L"string", L"replace", L"bar", L"x", L"red barn", 0}, 0, L"red xn\n"},
|
||||
{{L"string", L"replace", L"x", L"bar", L"red xn", 0}, 0, L"red barn\n"},
|
||||
{{L"string", L"replace", L"--", L"x", L"-", L"xyz", 0}, 0, L"-yz\n"},
|
||||
{{L"string", L"replace", L"--", L"y", L"-", L"xyz", 0}, 0, L"x-z\n"},
|
||||
{{L"string", L"replace", L"--", L"z", L"-", L"xyz", 0}, 0, L"xy-\n"},
|
||||
{{L"string", L"replace", L"-i", L"z", L"X", L"_Z_", 0}, 0, L"_X_\n"},
|
||||
{{L"string", L"replace", L"-a", L"a", L"A", L"aaa", 0}, 0, L"AAA\n"},
|
||||
{{L"string", L"replace", L"-i", L"a", L"z", L"AAA", 0}, 0, L"zAA\n"},
|
||||
{{L"string", L"replace", L"-q", L"x", L">x<", L"x", 0}, 0, L""},
|
||||
{{L"string", L"replace", L"-a", L"x", L"", L"xxx", 0}, 0, L"\n"},
|
||||
{{L"string", L"replace", L"-a", L"***", L"_", L"*****", 0}, 0, L"_**\n"},
|
||||
{{L"string", L"replace", L"-a", L"***", L"***", L"******", 0}, 0, L"******\n"},
|
||||
{{L"string", L"replace", L"-a", L"a", L"b", L"xax", L"axa", 0}, 0, L"xbx\nbxb\n"},
|
||||
{{L"string", L"replace", 0}, STATUS_INVALID_ARGS, L""},
|
||||
{{L"string", L"replace", L"", 0}, STATUS_INVALID_ARGS, L""},
|
||||
{{L"string", L"replace", L"", L"", 0}, STATUS_BUILTIN_ERROR, L""},
|
||||
{{L"string", L"replace", L"", L"", L"", 0}, STATUS_BUILTIN_ERROR, L"\n"},
|
||||
{{L"string", L"replace", L"", L"", L" ", 0}, STATUS_BUILTIN_ERROR, L" \n"},
|
||||
{{L"string", L"replace", L"a", L"b", L"", 0}, STATUS_BUILTIN_ERROR, L"\n"},
|
||||
{{L"string", L"replace", L"a", L"b", L"a", 0}, STATUS_BUILTIN_OK, L"b\n"},
|
||||
{{L"string", L"replace", L"a", L"b", L"xax", 0}, STATUS_BUILTIN_OK, L"xbx\n"},
|
||||
{{L"string", L"replace", L"a", L"b", L"xax", L"axa", 0}, STATUS_BUILTIN_OK, L"xbx\nbxa\n"},
|
||||
{{L"string", L"replace", L"bar", L"x", L"red barn", 0}, STATUS_BUILTIN_OK, L"red xn\n"},
|
||||
{{L"string", L"replace", L"x", L"bar", L"red xn", 0}, STATUS_BUILTIN_OK, L"red barn\n"},
|
||||
{{L"string", L"replace", L"--", L"x", L"-", L"xyz", 0}, STATUS_BUILTIN_OK, L"-yz\n"},
|
||||
{{L"string", L"replace", L"--", L"y", L"-", L"xyz", 0}, STATUS_BUILTIN_OK, L"x-z\n"},
|
||||
{{L"string", L"replace", L"--", L"z", L"-", L"xyz", 0}, STATUS_BUILTIN_OK, L"xy-\n"},
|
||||
{{L"string", L"replace", L"-i", L"z", L"X", L"_Z_", 0}, STATUS_BUILTIN_OK, L"_X_\n"},
|
||||
{{L"string", L"replace", L"-a", L"a", L"A", L"aaa", 0}, STATUS_BUILTIN_OK, L"AAA\n"},
|
||||
{{L"string", L"replace", L"-i", L"a", L"z", L"AAA", 0}, STATUS_BUILTIN_OK, L"zAA\n"},
|
||||
{{L"string", L"replace", L"-q", L"x", L">x<", L"x", 0}, STATUS_BUILTIN_OK, L""},
|
||||
{{L"string", L"replace", L"-a", L"x", L"", L"xxx", 0}, STATUS_BUILTIN_OK, L"\n"},
|
||||
{{L"string", L"replace", L"-a", L"***", L"_", L"*****", 0}, STATUS_BUILTIN_OK, L"_**\n"},
|
||||
{{L"string", L"replace", L"-a", L"***", L"***", L"******", 0},
|
||||
STATUS_BUILTIN_OK,
|
||||
L"******\n"},
|
||||
{{L"string", L"replace", L"-a", L"a", L"b", L"xax", L"axa", 0},
|
||||
STATUS_BUILTIN_OK,
|
||||
L"xbx\nbxb\n"},
|
||||
|
||||
{{L"string", L"replace", L"-r", 0}, 2, L""},
|
||||
{{L"string", L"replace", L"-r", L"", 0}, 2, L""},
|
||||
{{L"string", L"replace", L"-r", L"", L"", 0}, 1, L""},
|
||||
{{L"string", L"replace", L"-r", L"", L"", L"", 0}, 0, L"\n"}, // pcre2 behavior
|
||||
{{L"string", L"replace", L"-r", L"", L"", L" ", 0}, 0, L" \n"}, // pcre2 behavior
|
||||
{{L"string", L"replace", L"-r", L"a", L"b", L"", 0}, 1, L"\n"},
|
||||
{{L"string", L"replace", L"-r", L"a", L"b", L"a", 0}, 0, L"b\n"},
|
||||
{{L"string", L"replace", L"-r", L".", L"x", L"abc", 0}, 0, L"xbc\n"},
|
||||
{{L"string", L"replace", L"-r", L".", L"", L"abc", 0}, 0, L"bc\n"},
|
||||
{{L"string", L"replace", L"-r", L"(\\w)(\\w)", L"$2$1", L"ab", 0}, 0, L"ba\n"},
|
||||
{{L"string", L"replace", L"-r", L"(\\w)", L"$1$1", L"ab", 0}, 0, L"aab\n"},
|
||||
{{L"string", L"replace", L"-r", L"-a", L".", L"x", L"abc", 0}, 0, L"xxx\n"},
|
||||
{{L"string", L"replace", L"-r", L"-a", L"(\\w)", L"$1$1", L"ab", 0}, 0, L"aabb\n"},
|
||||
{{L"string", L"replace", L"-r", L"-a", L".", L"", L"abc", 0}, 0, L"\n"},
|
||||
{{L"string", L"replace", L"-r", L"a", L"x", L"bc", L"cd", L"de", 0}, 1, L"bc\ncd\nde\n"},
|
||||
{{L"string", L"replace", L"-r", L"a", L"x", L"aba", L"caa", 0}, 0, L"xba\ncxa\n"},
|
||||
{{L"string", L"replace", L"-r", L"-a", L"a", L"x", L"aba", L"caa", 0}, 0, L"xbx\ncxx\n"},
|
||||
{{L"string", L"replace", L"-r", L"-i", L"A", L"b", L"xax", 0}, 0, L"xbx\n"},
|
||||
{{L"string", L"replace", L"-r", L"-i", L"[a-z]", L".", L"1A2B", 0}, 0, L"1.2B\n"},
|
||||
{{L"string", L"replace", L"-r", L"A", L"b", L"xax", 0}, 1, L"xax\n"},
|
||||
{{L"string", L"replace", L"-r", L"a", L"$1", L"a", 0}, 2, L""},
|
||||
{{L"string", L"replace", L"-r", L"(a)", L"$2", L"a", 0}, 2, L""},
|
||||
{{L"string", L"replace", L"-r", L"*", L".", L"a", 0}, 2, L""},
|
||||
{{L"string", L"replace", L"-r", L"^(.)", L"\t$1", L"abc", L"x", 0}, 0, L"\tabc\n\tx\n"},
|
||||
{{L"string", L"replace", L"-r", 0}, STATUS_INVALID_ARGS, L""},
|
||||
{{L"string", L"replace", L"-r", L"", 0}, STATUS_INVALID_ARGS, L""},
|
||||
{{L"string", L"replace", L"-r", L"", L"", 0}, STATUS_BUILTIN_ERROR, L""},
|
||||
{{L"string", L"replace", L"-r", L"", L"", L"", 0},
|
||||
STATUS_BUILTIN_OK,
|
||||
L"\n"}, // pcre2 behavior
|
||||
{{L"string", L"replace", L"-r", L"", L"", L" ", 0},
|
||||
STATUS_BUILTIN_OK,
|
||||
L" \n"}, // pcre2 behavior
|
||||
{{L"string", L"replace", L"-r", L"a", L"b", L"", 0}, STATUS_BUILTIN_ERROR, L"\n"},
|
||||
{{L"string", L"replace", L"-r", L"a", L"b", L"a", 0}, STATUS_BUILTIN_OK, L"b\n"},
|
||||
{{L"string", L"replace", L"-r", L".", L"x", L"abc", 0}, STATUS_BUILTIN_OK, L"xbc\n"},
|
||||
{{L"string", L"replace", L"-r", L".", L"", L"abc", 0}, STATUS_BUILTIN_OK, L"bc\n"},
|
||||
{{L"string", L"replace", L"-r", L"(\\w)(\\w)", L"$2$1", L"ab", 0},
|
||||
STATUS_BUILTIN_OK,
|
||||
L"ba\n"},
|
||||
{{L"string", L"replace", L"-r", L"(\\w)", L"$1$1", L"ab", 0}, STATUS_BUILTIN_OK, L"aab\n"},
|
||||
{{L"string", L"replace", L"-r", L"-a", L".", L"x", L"abc", 0}, STATUS_BUILTIN_OK, L"xxx\n"},
|
||||
{{L"string", L"replace", L"-r", L"-a", L"(\\w)", L"$1$1", L"ab", 0},
|
||||
STATUS_BUILTIN_OK,
|
||||
L"aabb\n"},
|
||||
{{L"string", L"replace", L"-r", L"-a", L".", L"", L"abc", 0}, STATUS_BUILTIN_OK, L"\n"},
|
||||
{{L"string", L"replace", L"-r", L"a", L"x", L"bc", L"cd", L"de", 0},
|
||||
STATUS_BUILTIN_ERROR,
|
||||
L"bc\ncd\nde\n"},
|
||||
{{L"string", L"replace", L"-r", L"a", L"x", L"aba", L"caa", 0},
|
||||
STATUS_BUILTIN_OK,
|
||||
L"xba\ncxa\n"},
|
||||
{{L"string", L"replace", L"-r", L"-a", L"a", L"x", L"aba", L"caa", 0},
|
||||
STATUS_BUILTIN_OK,
|
||||
L"xbx\ncxx\n"},
|
||||
{{L"string", L"replace", L"-r", L"-i", L"A", L"b", L"xax", 0}, STATUS_BUILTIN_OK, L"xbx\n"},
|
||||
{{L"string", L"replace", L"-r", L"-i", L"[a-z]", L".", L"1A2B", 0},
|
||||
STATUS_BUILTIN_OK,
|
||||
L"1.2B\n"},
|
||||
{{L"string", L"replace", L"-r", L"A", L"b", L"xax", 0}, STATUS_BUILTIN_ERROR, L"xax\n"},
|
||||
{{L"string", L"replace", L"-r", L"a", L"$1", L"a", 0}, STATUS_INVALID_ARGS, L""},
|
||||
{{L"string", L"replace", L"-r", L"(a)", L"$2", L"a", 0}, STATUS_INVALID_ARGS, L""},
|
||||
{{L"string", L"replace", L"-r", L"*", L".", L"a", 0}, STATUS_INVALID_ARGS, L""},
|
||||
{{L"string", L"replace", L"-r", L"^(.)", L"\t$1", L"abc", L"x", 0},
|
||||
STATUS_BUILTIN_OK,
|
||||
L"\tabc\n\tx\n"},
|
||||
|
||||
{{L"string", L"split", 0}, 2, L""},
|
||||
{{L"string", L"split", L":", 0}, 1, L""},
|
||||
{{L"string", L"split", L".", L"www.ch.ic.ac.uk", 0}, 0, L"www\nch\nic\nac\nuk\n"},
|
||||
{{L"string", L"split", L"..", L"....", 0}, 0, L"\n\n\n"},
|
||||
{{L"string", L"split", L"-m", L"x", L"..", L"....", 0}, 2, L""},
|
||||
{{L"string", L"split", L"-m1", L"..", L"....", 0}, 0, L"\n..\n"},
|
||||
{{L"string", L"split", 0}, STATUS_INVALID_ARGS, L""},
|
||||
{{L"string", L"split", L":", 0}, STATUS_BUILTIN_ERROR, L""},
|
||||
{{L"string", L"split", L".", L"www.ch.ic.ac.uk", 0},
|
||||
STATUS_BUILTIN_OK,
|
||||
L"www\nch\nic\nac\nuk\n"},
|
||||
{{L"string", L"split", L"..", L"....", 0}, STATUS_BUILTIN_OK, L"\n\n\n"},
|
||||
{{L"string", L"split", L"-m", L"x", L"..", L"....", 0}, STATUS_INVALID_ARGS, L""},
|
||||
{{L"string", L"split", L"-m1", L"..", L"....", 0}, STATUS_BUILTIN_OK, L"\n..\n"},
|
||||
{{L"string", L"split", L"-m0", L"/", L"/usr/local/bin/fish", 0},
|
||||
1,
|
||||
STATUS_BUILTIN_ERROR,
|
||||
L"/usr/local/bin/fish\n"},
|
||||
{{L"string", L"split", L"-m2", L":", L"a:b:c:d", L"e:f:g:h", 0},
|
||||
0,
|
||||
STATUS_BUILTIN_OK,
|
||||
L"a\nb\nc:d\ne\nf\ng:h\n"},
|
||||
{{L"string", L"split", L"-m1", L"-r", L"/", L"/usr/local/bin/fish", 0},
|
||||
0,
|
||||
STATUS_BUILTIN_OK,
|
||||
L"/usr/local/bin\nfish\n"},
|
||||
{{L"string", L"split", L"-r", L".", L"www.ch.ic.ac.uk", 0}, 0, L"www\nch\nic\nac\nuk\n"},
|
||||
{{L"string", L"split", L"--", L"--", L"a--b---c----d", 0}, 0, L"a\nb\n-c\n\nd\n"},
|
||||
{{L"string", L"split", L"-r", L"..", L"....", 0}, 0, L"\n\n\n"},
|
||||
{{L"string", L"split", L"-r", L"--", L"--", L"a--b---c----d", 0}, 0, L"a\nb-\nc\n\nd\n"},
|
||||
{{L"string", L"split", L"", L"", 0}, 1, L"\n"},
|
||||
{{L"string", L"split", L"", L"a", 0}, 1, L"a\n"},
|
||||
{{L"string", L"split", L"", L"ab", 0}, 0, L"a\nb\n"},
|
||||
{{L"string", L"split", L"", L"abc", 0}, 0, L"a\nb\nc\n"},
|
||||
{{L"string", L"split", L"-m1", L"", L"abc", 0}, 0, L"a\nbc\n"},
|
||||
{{L"string", L"split", L"-r", L"", L"", 0}, 1, L"\n"},
|
||||
{{L"string", L"split", L"-r", L"", L"a", 0}, 1, L"a\n"},
|
||||
{{L"string", L"split", L"-r", L"", L"ab", 0}, 0, L"a\nb\n"},
|
||||
{{L"string", L"split", L"-r", L"", L"abc", 0}, 0, L"a\nb\nc\n"},
|
||||
{{L"string", L"split", L"-r", L"-m1", L"", L"abc", 0}, 0, L"ab\nc\n"},
|
||||
{{L"string", L"split", L"-q", 0}, 2, L""},
|
||||
{{L"string", L"split", L"-q", L":", 0}, 1, L""},
|
||||
{{L"string", L"split", L"-q", L"x", L"axbxc", 0}, 0, L""},
|
||||
{{L"string", L"split", L"-r", L".", L"www.ch.ic.ac.uk", 0},
|
||||
STATUS_BUILTIN_OK,
|
||||
L"www\nch\nic\nac\nuk\n"},
|
||||
{{L"string", L"split", L"--", L"--", L"a--b---c----d", 0},
|
||||
STATUS_BUILTIN_OK,
|
||||
L"a\nb\n-c\n\nd\n"},
|
||||
{{L"string", L"split", L"-r", L"..", L"....", 0}, STATUS_BUILTIN_OK, L"\n\n\n"},
|
||||
{{L"string", L"split", L"-r", L"--", L"--", L"a--b---c----d", 0},
|
||||
STATUS_BUILTIN_OK,
|
||||
L"a\nb-\nc\n\nd\n"},
|
||||
{{L"string", L"split", L"", L"", 0}, STATUS_BUILTIN_ERROR, L"\n"},
|
||||
{{L"string", L"split", L"", L"a", 0}, STATUS_BUILTIN_ERROR, L"a\n"},
|
||||
{{L"string", L"split", L"", L"ab", 0}, STATUS_BUILTIN_OK, L"a\nb\n"},
|
||||
{{L"string", L"split", L"", L"abc", 0}, STATUS_BUILTIN_OK, L"a\nb\nc\n"},
|
||||
{{L"string", L"split", L"-m1", L"", L"abc", 0}, STATUS_BUILTIN_OK, L"a\nbc\n"},
|
||||
{{L"string", L"split", L"-r", L"", L"", 0}, STATUS_BUILTIN_ERROR, L"\n"},
|
||||
{{L"string", L"split", L"-r", L"", L"a", 0}, STATUS_BUILTIN_ERROR, L"a\n"},
|
||||
{{L"string", L"split", L"-r", L"", L"ab", 0}, STATUS_BUILTIN_OK, L"a\nb\n"},
|
||||
{{L"string", L"split", L"-r", L"", L"abc", 0}, STATUS_BUILTIN_OK, L"a\nb\nc\n"},
|
||||
{{L"string", L"split", L"-r", L"-m1", L"", L"abc", 0}, STATUS_BUILTIN_OK, L"ab\nc\n"},
|
||||
{{L"string", L"split", L"-q", 0}, STATUS_INVALID_ARGS, L""},
|
||||
{{L"string", L"split", L"-q", L":", 0}, STATUS_BUILTIN_ERROR, L""},
|
||||
{{L"string", L"split", L"-q", L"x", L"axbxc", 0}, STATUS_BUILTIN_OK, L""},
|
||||
|
||||
{{L"string", L"sub", 0}, 1, L""},
|
||||
{{L"string", L"sub", L"abcde", 0}, 0, L"abcde\n"},
|
||||
{{L"string", L"sub", L"-l", L"x", L"abcde", 0}, 2, L""},
|
||||
{{L"string", L"sub", L"-s", L"x", L"abcde", 0}, 2, L""},
|
||||
{{L"string", L"sub", L"-l0", L"abcde", 0}, 0, L"\n"},
|
||||
{{L"string", L"sub", L"-l2", L"abcde", 0}, 0, L"ab\n"},
|
||||
{{L"string", L"sub", L"-l5", L"abcde", 0}, 0, L"abcde\n"},
|
||||
{{L"string", L"sub", L"-l6", L"abcde", 0}, 0, L"abcde\n"},
|
||||
{{L"string", L"sub", L"-l-1", L"abcde", 0}, 2, L""},
|
||||
{{L"string", L"sub", L"-s0", L"abcde", 0}, 2, L""},
|
||||
{{L"string", L"sub", L"-s1", L"abcde", 0}, 0, L"abcde\n"},
|
||||
{{L"string", L"sub", L"-s5", L"abcde", 0}, 0, L"e\n"},
|
||||
{{L"string", L"sub", L"-s6", L"abcde", 0}, 0, L"\n"},
|
||||
{{L"string", L"sub", L"-s-1", L"abcde", 0}, 0, L"e\n"},
|
||||
{{L"string", L"sub", L"-s-5", L"abcde", 0}, 0, L"abcde\n"},
|
||||
{{L"string", L"sub", L"-s-6", L"abcde", 0}, 0, L"abcde\n"},
|
||||
{{L"string", L"sub", L"-s1", L"-l0", L"abcde", 0}, 0, L"\n"},
|
||||
{{L"string", L"sub", L"-s1", L"-l1", L"abcde", 0}, 0, L"a\n"},
|
||||
{{L"string", L"sub", L"-s2", L"-l2", L"abcde", 0}, 0, L"bc\n"},
|
||||
{{L"string", L"sub", L"-s-1", L"-l1", L"abcde", 0}, 0, L"e\n"},
|
||||
{{L"string", L"sub", L"-s-1", L"-l2", L"abcde", 0}, 0, L"e\n"},
|
||||
{{L"string", L"sub", L"-s-3", L"-l2", L"abcde", 0}, 0, L"cd\n"},
|
||||
{{L"string", L"sub", L"-s-3", L"-l4", L"abcde", 0}, 0, L"cde\n"},
|
||||
{{L"string", L"sub", L"-q", 0}, 1, L""},
|
||||
{{L"string", L"sub", L"-q", L"abcde", 0}, 0, L""},
|
||||
{{L"string", L"sub", 0}, STATUS_BUILTIN_ERROR, L""},
|
||||
{{L"string", L"sub", L"abcde", 0}, STATUS_BUILTIN_OK, L"abcde\n"},
|
||||
{{L"string", L"sub", L"-l", L"x", L"abcde", 0}, STATUS_INVALID_ARGS, L""},
|
||||
{{L"string", L"sub", L"-s", L"x", L"abcde", 0}, STATUS_INVALID_ARGS, L""},
|
||||
{{L"string", L"sub", L"-l0", L"abcde", 0}, STATUS_BUILTIN_OK, L"\n"},
|
||||
{{L"string", L"sub", L"-l2", L"abcde", 0}, STATUS_BUILTIN_OK, L"ab\n"},
|
||||
{{L"string", L"sub", L"-l5", L"abcde", 0}, STATUS_BUILTIN_OK, L"abcde\n"},
|
||||
{{L"string", L"sub", L"-l6", L"abcde", 0}, STATUS_BUILTIN_OK, L"abcde\n"},
|
||||
{{L"string", L"sub", L"-l-1", L"abcde", 0}, STATUS_INVALID_ARGS, L""},
|
||||
{{L"string", L"sub", L"-s0", L"abcde", 0}, STATUS_INVALID_ARGS, L""},
|
||||
{{L"string", L"sub", L"-s1", L"abcde", 0}, STATUS_BUILTIN_OK, L"abcde\n"},
|
||||
{{L"string", L"sub", L"-s5", L"abcde", 0}, STATUS_BUILTIN_OK, L"e\n"},
|
||||
{{L"string", L"sub", L"-s6", L"abcde", 0}, STATUS_BUILTIN_OK, L"\n"},
|
||||
{{L"string", L"sub", L"-s-1", L"abcde", 0}, STATUS_BUILTIN_OK, L"e\n"},
|
||||
{{L"string", L"sub", L"-s-5", L"abcde", 0}, STATUS_BUILTIN_OK, L"abcde\n"},
|
||||
{{L"string", L"sub", L"-s-6", L"abcde", 0}, STATUS_BUILTIN_OK, L"abcde\n"},
|
||||
{{L"string", L"sub", L"-s1", L"-l0", L"abcde", 0}, STATUS_BUILTIN_OK, L"\n"},
|
||||
{{L"string", L"sub", L"-s1", L"-l1", L"abcde", 0}, STATUS_BUILTIN_OK, L"a\n"},
|
||||
{{L"string", L"sub", L"-s2", L"-l2", L"abcde", 0}, STATUS_BUILTIN_OK, L"bc\n"},
|
||||
{{L"string", L"sub", L"-s-1", L"-l1", L"abcde", 0}, STATUS_BUILTIN_OK, L"e\n"},
|
||||
{{L"string", L"sub", L"-s-1", L"-l2", L"abcde", 0}, STATUS_BUILTIN_OK, L"e\n"},
|
||||
{{L"string", L"sub", L"-s-3", L"-l2", L"abcde", 0}, STATUS_BUILTIN_OK, L"cd\n"},
|
||||
{{L"string", L"sub", L"-s-3", L"-l4", L"abcde", 0}, STATUS_BUILTIN_OK, L"cde\n"},
|
||||
{{L"string", L"sub", L"-q", 0}, STATUS_BUILTIN_ERROR, L""},
|
||||
{{L"string", L"sub", L"-q", L"abcde", 0}, STATUS_BUILTIN_OK, L""},
|
||||
|
||||
{{L"string", L"trim", 0}, 1, L""},
|
||||
{{L"string", L"trim", L""}, 1, L"\n"},
|
||||
{{L"string", L"trim", L" "}, 0, L"\n"},
|
||||
{{L"string", L"trim", L" \f\n\r\t"}, 0, L"\n"},
|
||||
{{L"string", L"trim", L" a"}, 0, L"a\n"},
|
||||
{{L"string", L"trim", L"a "}, 0, L"a\n"},
|
||||
{{L"string", L"trim", L" a "}, 0, L"a\n"},
|
||||
{{L"string", L"trim", L"-l", L" a"}, 0, L"a\n"},
|
||||
{{L"string", L"trim", L"-l", L"a "}, 1, L"a \n"},
|
||||
{{L"string", L"trim", L"-l", L" a "}, 0, L"a \n"},
|
||||
{{L"string", L"trim", L"-r", L" a"}, 1, L" a\n"},
|
||||
{{L"string", L"trim", L"-r", L"a "}, 0, L"a\n"},
|
||||
{{L"string", L"trim", L"-r", L" a "}, 0, L" a\n"},
|
||||
{{L"string", L"trim", L"-c", L".", L" a"}, 1, L" a\n"},
|
||||
{{L"string", L"trim", L"-c", L".", L"a "}, 1, L"a \n"},
|
||||
{{L"string", L"trim", L"-c", L".", L" a "}, 1, L" a \n"},
|
||||
{{L"string", L"trim", L"-c", L".", L".a"}, 0, L"a\n"},
|
||||
{{L"string", L"trim", L"-c", L".", L"a."}, 0, L"a\n"},
|
||||
{{L"string", L"trim", L"-c", L".", L".a."}, 0, L"a\n"},
|
||||
{{L"string", L"trim", L"-c", L"\\/", L"/a\\"}, 0, L"a\n"},
|
||||
{{L"string", L"trim", L"-c", L"\\/", L"a/"}, 0, L"a\n"},
|
||||
{{L"string", L"trim", L"-c", L"\\/", L"\\a/"}, 0, L"a\n"},
|
||||
{{L"string", L"trim", L"-c", L"", L".a."}, 1, L".a.\n"},
|
||||
{{L"string", L"trim", 0}, STATUS_BUILTIN_ERROR, L""},
|
||||
{{L"string", L"trim", L""}, STATUS_BUILTIN_ERROR, L"\n"},
|
||||
{{L"string", L"trim", L" "}, STATUS_BUILTIN_OK, L"\n"},
|
||||
{{L"string", L"trim", L" \f\n\r\t"}, STATUS_BUILTIN_OK, L"\n"},
|
||||
{{L"string", L"trim", L" a"}, STATUS_BUILTIN_OK, L"a\n"},
|
||||
{{L"string", L"trim", L"a "}, STATUS_BUILTIN_OK, L"a\n"},
|
||||
{{L"string", L"trim", L" a "}, STATUS_BUILTIN_OK, L"a\n"},
|
||||
{{L"string", L"trim", L"-l", L" a"}, STATUS_BUILTIN_OK, L"a\n"},
|
||||
{{L"string", L"trim", L"-l", L"a "}, STATUS_BUILTIN_ERROR, L"a \n"},
|
||||
{{L"string", L"trim", L"-l", L" a "}, STATUS_BUILTIN_OK, L"a \n"},
|
||||
{{L"string", L"trim", L"-r", L" a"}, STATUS_BUILTIN_ERROR, L" a\n"},
|
||||
{{L"string", L"trim", L"-r", L"a "}, STATUS_BUILTIN_OK, L"a\n"},
|
||||
{{L"string", L"trim", L"-r", L" a "}, STATUS_BUILTIN_OK, L" a\n"},
|
||||
{{L"string", L"trim", L"-c", L".", L" a"}, STATUS_BUILTIN_ERROR, L" a\n"},
|
||||
{{L"string", L"trim", L"-c", L".", L"a "}, STATUS_BUILTIN_ERROR, L"a \n"},
|
||||
{{L"string", L"trim", L"-c", L".", L" a "}, STATUS_BUILTIN_ERROR, L" a \n"},
|
||||
{{L"string", L"trim", L"-c", L".", L".a"}, STATUS_BUILTIN_OK, L"a\n"},
|
||||
{{L"string", L"trim", L"-c", L".", L"a."}, STATUS_BUILTIN_OK, L"a\n"},
|
||||
{{L"string", L"trim", L"-c", L".", L".a."}, STATUS_BUILTIN_OK, L"a\n"},
|
||||
{{L"string", L"trim", L"-c", L"\\/", L"/a\\"}, STATUS_BUILTIN_OK, L"a\n"},
|
||||
{{L"string", L"trim", L"-c", L"\\/", L"a/"}, STATUS_BUILTIN_OK, L"a\n"},
|
||||
{{L"string", L"trim", L"-c", L"\\/", L"\\a/"}, STATUS_BUILTIN_OK, L"a\n"},
|
||||
{{L"string", L"trim", L"-c", L"", L".a."}, STATUS_BUILTIN_ERROR, L".a.\n"},
|
||||
|
||||
{{0}, 0, 0}};
|
||||
{{0}, STATUS_BUILTIN_ERROR, NULL}};
|
||||
|
||||
struct string_test *t = string_tests;
|
||||
while (t->argv[0] != 0) {
|
||||
|
24
src/proc.h
24
src/proc.h
@ -19,30 +19,6 @@
|
||||
#include "io.h"
|
||||
#include "parse_tree.h"
|
||||
|
||||
/// The status code use when a command was not found.
|
||||
#define STATUS_UNKNOWN_COMMAND 127
|
||||
|
||||
/// The status code used when an unknown error occured during execution of a command.
|
||||
#define STATUS_NOT_EXECUTABLE 126
|
||||
|
||||
/// The status code used when an unknown error occured during execution of a command.
|
||||
#define STATUS_EXEC_FAIL 125
|
||||
|
||||
/// The status code used when a wildcard had no matches.
|
||||
#define STATUS_UNMATCHED_WILDCARD 124
|
||||
|
||||
/// The status code used when illegal command name is encountered.
|
||||
#define STATUS_ILLEGAL_CMD 123
|
||||
|
||||
/// The status code used when `read` is asked to consume too much data.
|
||||
#define STATUS_READ_TOO_MUCH 122
|
||||
|
||||
/// The status code used for normal exit in a builtin.
|
||||
#define STATUS_BUILTIN_OK 0
|
||||
|
||||
/// The status code used for erroneous argument combinations in a builtin.
|
||||
#define STATUS_BUILTIN_ERROR 1
|
||||
|
||||
/// Types of processes.
|
||||
enum process_type_t {
|
||||
/// A regular external command.
|
||||
|
Loading…
x
Reference in New Issue
Block a user