Updated regex examples and Jamfiles so that they are run as tests.

[SVN r12149]
This commit is contained in:
John Maddock
2001-12-26 11:21:24 +00:00
parent 0cda8c8a2e
commit b2dd7877da
6 changed files with 93 additions and 37 deletions

View File

@ -1,24 +1,28 @@
subproject libs/regex/example ; subproject libs/regex/example ;
exe timer : timer/regex_timer.cpp unit-test timer : timer/regex_timer.cpp
<lib>../build/libboost_regex$(SUFLIB) <lib>../build/libboost_regex$(SUFLIB)
: :
<include>../../../ <include>../../../
<define>BOOST_REGEX_NO_LIB=1 <define>BOOST_REGEX_NO_LIB=1
<define>BOOST_REGEX_STATIC_LINK=1 <define>BOOST_REGEX_STATIC_LINK=1
: :
debug release
:
timer/input_script.txt
; ;
exe jgrep : jgrep/jgrep.cpp jgrep/main.cpp unit-test jgrep : jgrep/jgrep.cpp jgrep/main.cpp
<lib>../build/libboost_regex$(SUFLIB) <lib>../build/libboost_regex$(SUFLIB)
: :
<include>../../../ <include>../../../
<define>BOOST_REGEX_NO_LIB=1 <define>BOOST_REGEX_NO_LIB=1
<define>BOOST_REGEX_STATIC_LINK=1 <define>BOOST_REGEX_STATIC_LINK=1
: :
debug release
:
-n boost/ ../../../boost/regex.hpp
; ;
unit-test credit_card_example : snippets/credit_card_example.cpp unit-test credit_card_example : snippets/credit_card_example.cpp
@ -44,7 +48,7 @@ unit-test partial_regex_grep : snippets/partial_regex_grep.cpp
../index.htm ../index.htm
; ;
exe partial_regex_match : snippets/partial_regex_match.cpp unit-test partial_regex_match : snippets/partial_regex_match.cpp
<lib>../build/libboost_regex$(SUFLIB) <lib>../build/libboost_regex$(SUFLIB)
: :
<include>../../../ <include>../../../
@ -52,6 +56,8 @@ exe partial_regex_match : snippets/partial_regex_match.cpp
<define>BOOST_REGEX_STATIC_LINK=1 <define>BOOST_REGEX_STATIC_LINK=1
: :
debug debug
:
1234-5678-8765-4
; ;
unit-test regex_grep_example_1 : snippets/regex_grep_example_1.cpp unit-test regex_grep_example_1 : snippets/regex_grep_example_1.cpp
@ -102,7 +108,7 @@ unit-test regex_grep_example_4 : snippets/regex_grep_example_4.cpp
../../../boost/smart_ptr.hpp ../../../boost/smart_ptr.hpp
; ;
exe regex_match_example : snippets/regex_match_example.cpp unit-test regex_match_example : snippets/regex_match_example.cpp
<lib>../build/libboost_regex$(SUFLIB) <lib>../build/libboost_regex$(SUFLIB)
: :
<include>../../../ <include>../../../
@ -110,6 +116,8 @@ exe regex_match_example : snippets/regex_match_example.cpp
<define>BOOST_REGEX_STATIC_LINK=1 <define>BOOST_REGEX_STATIC_LINK=1
: :
debug debug
:
-auto
; ;
unit-test regex_merge_example : snippets/regex_merge_example.cpp unit-test regex_merge_example : snippets/regex_merge_example.cpp
@ -136,7 +144,7 @@ unit-test regex_search_example : snippets/regex_search_example.cpp
../../../boost/smart_ptr.hpp ../../../boost/smart_ptr.hpp
; ;
exe regex_split_example_1 : snippets/regex_split_example_1.cpp unit-test regex_split_example_1 : snippets/regex_split_example_1.cpp
<lib>../build/libboost_regex$(SUFLIB) <lib>../build/libboost_regex$(SUFLIB)
: :
<include>../../../ <include>../../../
@ -144,6 +152,8 @@ exe regex_split_example_1 : snippets/regex_split_example_1.cpp
<define>BOOST_REGEX_STATIC_LINK=1 <define>BOOST_REGEX_STATIC_LINK=1
: :
debug debug
:
-auto
; ;
unit-test regex_split_example_2 : snippets/regex_split_example_2.cpp unit-test regex_split_example_2 : snippets/regex_split_example_2.cpp
@ -164,3 +174,4 @@ unit-test regex_split_example_2 : snippets/regex_split_example_2.cpp

View File

@ -29,6 +29,9 @@ int main(int argc, char* argv[])
{ {
try{ try{
std::string input; std::string input;
if(argc > 1)
input = argv[1];
else
std::cin >> input; std::cin >> input;
if(is_possible_card_number(input)) if(is_possible_card_number(input))
{ {

View File

@ -68,15 +68,20 @@ istream& getline(istream& is, std::string& s)
} }
#endif #endif
int main() int main(int argc)
{ {
std::string in, out; std::string in, out;
while(true) do
{
if(argc == 1)
{ {
cout << "enter test string" << endl; cout << "enter test string" << endl;
getline(cin, in); getline(cin, in);
if(in == "quit") if(in == "quit")
break; break;
}
else
in = "100 this is an ftp message text";
int result; int result;
result = process_ftp(in.c_str(), &out); result = process_ftp(in.c_str(), &out);
if(result != -1) if(result != -1)
@ -90,7 +95,7 @@ int main()
cout << "Match not found" << endl; cout << "Match not found" << endl;
} }
cout << endl; cout << endl;
} } while(argc == 1);
return 0; return 0;
} }

View File

@ -51,14 +51,19 @@ istream& getline(istream& is, std::string& s)
#endif #endif
int main() int main(int argc)
{ {
string s; string s;
list<string> l; list<string> l;
do{ do{
if(argc == 1)
{
cout << "Enter text to split (or \"quit\" to exit): "; cout << "Enter text to split (or \"quit\" to exit): ";
getline(cin, s); getline(cin, s);
if(s == "quit") break; if(s == "quit") break;
}
else
s = "This is a string of tokens";
unsigned result = tokenise(l, s); unsigned result = tokenise(l, s);
cout << result << " tokens found" << endl; cout << result << " tokens found" << endl;
cout << "The remaining text is: \"" << s << "\"" << endl; cout << "The remaining text is: \"" << s << "\"" << endl;
@ -68,6 +73,6 @@ int main()
l.pop_front(); l.pop_front();
cout << s << endl; cout << s << endl;
} }
}while(true); }while(argc == 1);
return 0; return 0;
} }

View File

@ -0,0 +1,7 @@
abc
aaaaaaaaaaabcccccccc
quit
^([0-9]+)(\-| |$)(.*)$
100- this is a line of ftp response which contains a message string
quit
quit

View File

@ -15,14 +15,18 @@
#ifdef BOOST_RE_OLD_IOSTREAM #ifdef BOOST_RE_OLD_IOSTREAM
#include <iostream.h> #include <iostream.h>
#include <fstream.h>
#else #else
#include <iostream> #include <iostream>
#include <fstream>
using std::cout; using std::cout;
using std::cin; using std::cin;
using std::cerr; using std::cerr;
using std::istream; using std::istream;
using std::ostream; using std::ostream;
using std::endl; using std::endl;
using std::ifstream;
using std::streambuf;
#endif #endif
#include <algorithm> #include <algorithm>
@ -87,8 +91,21 @@ istream& getline(istream& is, std::string& s)
#endif #endif
int main() int main(int argc, char**argv)
{ {
ifstream ifs;
streambuf* pbuf = 0;
if(argc == 2)
{
ifs.open(argv[1]);
if(ifs.bad())
{
cout << "Bad filename: " << argv[1] << endl;
return -1;
}
pbuf = cin.rdbuf(ifs.rdbuf());
}
boost::regex ex; boost::regex ex;
boost::match_results<std::string::const_iterator> sm; boost::match_results<std::string::const_iterator> sm;
#ifndef BOOST_NO_WREGEX #ifndef BOOST_NO_WREGEX
@ -111,6 +128,8 @@ int main()
{ {
cout << "Enter expression (or \"quit\" to exit): "; cout << "Enter expression (or \"quit\" to exit): ";
getline(cin, s1); getline(cin, s1);
if(argc == 2)
cout << endl << s1 << endl;
if(s1 == "quit") if(s1 == "quit")
break; break;
#ifndef BOOST_NO_WREGEX #ifndef BOOST_NO_WREGEX
@ -143,6 +162,8 @@ int main()
{ {
cout << "Enter string to search (or \"quit\" to exit): "; cout << "Enter string to search (or \"quit\" to exit): ";
getline(cin, s2); getline(cin, s2);
if(argc == 2)
cout << endl << s2 << endl;
if(s2 == "quit") if(s2 == "quit")
break; break;
@ -313,6 +334,10 @@ int main()
} }
regfree(&r); regfree(&r);
} }
if(pbuf)
cin.rdbuf(pbuf);
return 0; return 0;
} }