/[pcre]/code/trunk/pcrecpp_unittest.cc
ViewVC logotype

Diff of /code/trunk/pcrecpp_unittest.cc

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 93 by nigel, Sat Feb 24 21:41:42 2007 UTC revision 256 by ph10, Wed Sep 19 08:57:53 2007 UTC
# Line 33  Line 33 
33  //  //
34  // TODO: Test extractions for PartialMatch/Consume  // TODO: Test extractions for PartialMatch/Consume
35    
36    #ifdef HAVE_CONFIG_H
37    #include "config.h"
38    #endif
39    
40    #ifdef HAVE_WINDOWS_H
41    #define snprintf _snprintf
42    #endif
43    
44  #include <stdio.h>  #include <stdio.h>
45  #include <cassert>  #include <cassert>
46  #include <vector>  #include <vector>
 #include "config.h"  
47  #include "pcrecpp.h"  #include "pcrecpp.h"
48    
49  using pcrecpp::StringPiece;  using pcrecpp::StringPiece;
# Line 806  int main(int argc, char** argv) { Line 813  int main(int argc, char** argv) {
813    /***** FullMatch with no args *****/    /***** FullMatch with no args *****/
814    
815    CHECK(RE("h.*o").FullMatch("hello"));    CHECK(RE("h.*o").FullMatch("hello"));
816    CHECK(!RE("h.*o").FullMatch("othello"));    CHECK(!RE("h.*o").FullMatch("othello"));     // Must be anchored at front
817    CHECK(!RE("h.*o").FullMatch("hello!"));    CHECK(!RE("h.*o").FullMatch("hello!"));      // Must be anchored at end
818      CHECK(RE("a*").FullMatch("aaaa"));           // Fullmatch with normal op
819      CHECK(RE("a*?").FullMatch("aaaa"));          // Fullmatch with nongreedy op
820      CHECK(RE("a*?\\z").FullMatch("aaaa"));       // Two unusual ops
821    
822    /***** FullMatch with args *****/    /***** FullMatch with args *****/
823    
# Line 902  int main(int argc, char** argv) { Line 912  int main(int argc, char** argv) {
912      CHECK(!RE("(\\d+)").FullMatch("4294967296", &v));      CHECK(!RE("(\\d+)").FullMatch("4294967296", &v));
913    }    }
914  #ifdef HAVE_LONG_LONG  #ifdef HAVE_LONG_LONG
915    # if defined(__MINGW__) || defined(__MINGW32__)
916    #   define LLD "%I64d"
917    #   define LLU "%I64u"
918    # else
919    #   define LLD "%lld"
920    #   define LLU "%llu"
921    # endif
922    {    {
923      long long v;      long long v;
924      static const long long max_value = 0x7fffffffffffffffLL;      static const long long max_value = 0x7fffffffffffffffLL;
# Line 911  int main(int argc, char** argv) { Line 928  int main(int argc, char** argv) {
928      CHECK(RE("(-?\\d+)").FullMatch("100", &v)); CHECK_EQ(v, 100);      CHECK(RE("(-?\\d+)").FullMatch("100", &v)); CHECK_EQ(v, 100);
929      CHECK(RE("(-?\\d+)").FullMatch("-100",&v)); CHECK_EQ(v, -100);      CHECK(RE("(-?\\d+)").FullMatch("-100",&v)); CHECK_EQ(v, -100);
930    
931      snprintf(buf, sizeof(buf), "%lld", max_value);      snprintf(buf, sizeof(buf), LLD, max_value);
932      CHECK(RE("(-?\\d+)").FullMatch(buf,&v)); CHECK_EQ(v, max_value);      CHECK(RE("(-?\\d+)").FullMatch(buf,&v)); CHECK_EQ(v, max_value);
933    
934      snprintf(buf, sizeof(buf), "%lld", min_value);      snprintf(buf, sizeof(buf), LLD, min_value);
935      CHECK(RE("(-?\\d+)").FullMatch(buf,&v)); CHECK_EQ(v, min_value);      CHECK(RE("(-?\\d+)").FullMatch(buf,&v)); CHECK_EQ(v, min_value);
936    
937      snprintf(buf, sizeof(buf), "%lld", max_value);      snprintf(buf, sizeof(buf), LLD, max_value);
938      assert(buf[strlen(buf)-1] != '9');      assert(buf[strlen(buf)-1] != '9');
939      buf[strlen(buf)-1]++;      buf[strlen(buf)-1]++;
940      CHECK(!RE("(-?\\d+)").FullMatch(buf, &v));      CHECK(!RE("(-?\\d+)").FullMatch(buf, &v));
941    
942      snprintf(buf, sizeof(buf), "%lld", min_value);      snprintf(buf, sizeof(buf), LLD, min_value);
943      assert(buf[strlen(buf)-1] != '9');      assert(buf[strlen(buf)-1] != '9');
944      buf[strlen(buf)-1]++;      buf[strlen(buf)-1]++;
945      CHECK(!RE("(-?\\d+)").FullMatch(buf, &v));      CHECK(!RE("(-?\\d+)").FullMatch(buf, &v));
# Line 938  int main(int argc, char** argv) { Line 955  int main(int argc, char** argv) {
955      CHECK(RE("(-?\\d+)").FullMatch("100",&v)); CHECK_EQ(v, 100);      CHECK(RE("(-?\\d+)").FullMatch("100",&v)); CHECK_EQ(v, 100);
956      CHECK(RE("(-?\\d+)").FullMatch("-100",&v2)); CHECK_EQ(v2, -100);      CHECK(RE("(-?\\d+)").FullMatch("-100",&v2)); CHECK_EQ(v2, -100);
957    
958      snprintf(buf, sizeof(buf), "%llu", max_value);      snprintf(buf, sizeof(buf), LLU, max_value);
959      CHECK(RE("(-?\\d+)").FullMatch(buf,&v)); CHECK_EQ(v, max_value);      CHECK(RE("(-?\\d+)").FullMatch(buf,&v)); CHECK_EQ(v, max_value);
960    
961      assert(buf[strlen(buf)-1] != '9');      assert(buf[strlen(buf)-1] != '9');
# Line 1119  int main(int argc, char** argv) { Line 1136  int main(int argc, char** argv) {
1136      printf("Testing UTF-8 handling\n");      printf("Testing UTF-8 handling\n");
1137    
1138      // Three Japanese characters (nihongo)      // Three Japanese characters (nihongo)
1139      const char utf8_string[] = {      const unsigned char utf8_string[] = {
1140           0xe6, 0x97, 0xa5, // 65e5           0xe6, 0x97, 0xa5, // 65e5
1141           0xe6, 0x9c, 0xac, // 627c           0xe6, 0x9c, 0xac, // 627c
1142           0xe8, 0xaa, 0x9e, // 8a9e           0xe8, 0xaa, 0x9e, // 8a9e
1143           0           0
1144      };      };
1145      const char utf8_pattern[] = {      const unsigned char utf8_pattern[] = {
1146           '.',           '.',
1147           0xe6, 0x9c, 0xac, // 627c           0xe6, 0x9c, 0xac, // 627c
1148           '.',           '.',

Legend:
Removed from v.93  
changed lines
  Added in v.256

  ViewVC Help
Powered by ViewVC 1.1.5