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

Diff of /code/trunk/pcre_scanner_unittest.cc

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

revision 77 by nigel, Sat Feb 24 21:40:45 2007 UTC revision 257 by ph10, Wed Sep 19 09:11:19 2007 UTC
# Line 32  Line 32 
32  // Unittest for scanner, especially GetNextComments and GetComments()  // Unittest for scanner, especially GetNextComments and GetComments()
33  // functionality.  // functionality.
34    
35    #ifdef HAVE_CONFIG_H
36    #include "config.h"
37    #endif
38    
39  #include <stdio.h>  #include <stdio.h>
40    #include <string>
41  #include <vector>  #include <vector>
42  #include <pcre_stringpiece.h>  
43  #include <pcre_scanner.h>  #include "pcrecpp.h"
44    #include "pcre_stringpiece.h"
45    #include "pcre_scanner.h"
46    
47    #define FLAGS_unittest_stack_size   49152
48    
49  // Dies with a fatal error if the two values are not equal.  // Dies with a fatal error if the two values are not equal.
50  #define CHECK_EQ(a, b)  do {                                    \  #define CHECK_EQ(a, b)  do {                                    \
# Line 68  static void TestScanner() { Line 77  static void TestScanner() {
77    s.Consume(re, &var, &number);    s.Consume(re, &var, &number);
78    CHECK_EQ(var, "alpha");    CHECK_EQ(var, "alpha");
79    CHECK_EQ(number, 1);    CHECK_EQ(number, 1);
80      CHECK_EQ(s.LineNumber(), 3);
81    s.GetNextComments(&comments);    s.GetNextComments(&comments);
82    CHECK_EQ(comments.size(), 1);    CHECK_EQ(comments.size(), 1);
83    CHECK_EQ(comments[0].as_string(), " // this sets alpha\n");    CHECK_EQ(comments[0].as_string(), " // this sets alpha\n");
# Line 115  static void TestScanner() { Line 125  static void TestScanner() {
125    comments.resize(0);    comments.resize(0);
126  }  }
127    
128    static void TestBigComment() {
129      string input;
130      for (int i = 0; i < 1024; ++i) {
131        char buf[1024];  // definitely big enough
132        sprintf(buf, "    # Comment %d\n", i);
133        input += buf;
134      }
135      input += "name = value;\n";
136    
137      Scanner s(input.c_str());
138      s.SetSkipExpression("\\s+|#.*\n");
139    
140      string name;
141      string value;
142      s.Consume("(\\w+) = (\\w+);", &name, &value);
143      CHECK_EQ(name, "name");
144      CHECK_EQ(value, "value");
145    }
146    
147    // TODO: also test scanner and big-comment in a thread with a
148    //       small stack size
149    
150  int main(int argc, char** argv) {  int main(int argc, char** argv) {
151    TestScanner();    TestScanner();
152      TestBigComment();
153    
154    // Done    // Done
155    printf("OK\n");    printf("OK\n");

Legend:
Removed from v.77  
changed lines
  Added in v.257

  ViewVC Help
Powered by ViewVC 1.1.5