From 5efb356b845ea3829ead2e3521b0f1440fd48948 Mon Sep 17 00:00:00 2001 From: John Maddock Date: Wed, 18 Oct 2000 10:56:28 +0000 Subject: [PATCH] more regex regression tests [SVN r7997] --- .../posix_api_compiler_check.cpp | 64 ++++++++++++++++++ .../wide_posix_api_compiler_check.cpp | 67 +++++++++++++++++++ 2 files changed, 131 insertions(+) create mode 100644 demo/c_compiler_checks/posix_api_compiler_check.cpp create mode 100644 demo/c_compiler_checks/wide_posix_api_compiler_check.cpp diff --git a/demo/c_compiler_checks/posix_api_compiler_check.cpp b/demo/c_compiler_checks/posix_api_compiler_check.cpp new file mode 100644 index 00000000..c6731ef7 --- /dev/null +++ b/demo/c_compiler_checks/posix_api_compiler_check.cpp @@ -0,0 +1,64 @@ +/* + * + * Copyright (c) 1998-2000 + * Dr John Maddock + * + * Permission to use, copy, modify, distribute and sell this software + * and its documentation for any purpose is hereby granted without fee, + * provided that the above copyright notice appear in all copies and + * that both that copyright notice and this permission notice appear + * in supporting documentation. Dr John Maddock makes no representations + * about the suitability of this software for any purpose. + * It is provided "as is" without express or implied warranty. + * + */ + + /* + * LOCATION: see http://www.boost.org for most recent version. + * FILE posix_api_compiler_check.c + * VERSION 3.01 + * DESCRIPTION: Verify that POSIX API calls compile: note this is a compile + * time check only. + */ + +#include +#include +#include +#include + +const char* expression = "^"; +const char* text = "\n "; +regmatch_t matches[1]; +int flags = REG_EXTENDED | REG_BASIC | REG_NOSPEC | REG_ICASE | REG_NOSUB | + REG_NEWLINE | REG_PEND | REG_NOCOLLATE | REG_ESCAPE_IN_LISTS | + REG_NEWLINE_ALT | REG_PERL | REG_AWK | REG_GREP | REG_EGREP; + + +int main() +{ + regex_t re; + int result; + result = regcomp(&re, expression, REG_AWK); + if(result > REG_NOERROR) + { + char buf[256]; + regerror(result, &re, buf, sizeof(buf)); + printf(buf); + return result; + } + assert(re.re_nsub == 0); + matches[0].rm_so = 0; + matches[0].rm_eo = strlen(text); + result = regexec(&re, text, 1, matches, REG_NOTBOL | REG_NOTEOL | REG_STARTEND); + if(result > REG_NOERROR) + { + char buf[256]; + regerror(result, &re, buf, sizeof(buf)); + printf(buf); + regfree(&re); + return result; + } + assert(matches[0].rm_so == matches[0].rm_eo == 1); + regfree(&re); + return 0; +} diff --git a/demo/c_compiler_checks/wide_posix_api_compiler_check.cpp b/demo/c_compiler_checks/wide_posix_api_compiler_check.cpp new file mode 100644 index 00000000..c706f16f --- /dev/null +++ b/demo/c_compiler_checks/wide_posix_api_compiler_check.cpp @@ -0,0 +1,67 @@ +/* + * + * Copyright (c) 1998-2000 + * Dr John Maddock + * + * Permission to use, copy, modify, distribute and sell this software + * and its documentation for any purpose is hereby granted without fee, + * provided that the above copyright notice appear in all copies and + * that both that copyright notice and this permission notice appear + * in supporting documentation. Dr John Maddock makes no representations + * about the suitability of this software for any purpose. + * It is provided "as is" without express or implied warranty. + * + */ + + /* + * LOCATION: see http://www.boost.org for most recent version. + * FILE wide_posix_api_compiler_check.c + * VERSION 3.01 + * DESCRIPTION: Verify that POSIX API calls compile: note this is a compile + * time check only. + */ + +#include +#include +#include +#include +#define UNICODE +#include + +const wchar_t* expression = L"^"; +const wchar_t* text = L"\n "; +regmatch_t matches[1]; +int flags = REG_EXTENDED | REG_BASIC | REG_NOSPEC | REG_ICASE | REG_NOSUB | + REG_NEWLINE | REG_PEND | REG_NOCOLLATE | REG_ESCAPE_IN_LISTS | + REG_NEWLINE_ALT | REG_PERL | REG_AWK | REG_GREP | REG_EGREP; + + +int main() +{ + regex_t re; + int result; + result = regcomp(&re, expression, REG_AWK); + if(result > REG_NOERROR) + { + wchar_t buf[256]; + regerror(result, &re, buf, sizeof(buf)); + wprintf(buf); + return result; + } + assert(re.re_nsub == 0); + matches[0].rm_so = 0; + matches[0].rm_eo = wcslen(text); + result = regexec(&re, text, 1, matches, REG_NOTBOL | REG_NOTEOL | REG_STARTEND); + if(result > REG_NOERROR) + { + wchar_t buf[256]; + regerror(result, &re, buf, sizeof(buf)); + wprintf(buf); + regfree(&re); + return result; + } + assert(matches[0].rm_so == matches[0].rm_eo == 1); + regfree(&re); + return 0; +} +