File: named_subexpressions_test.cpp

package info (click to toggle)
boost1.62 1.62.0%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 686,420 kB
  • sloc: cpp: 2,609,004; xml: 972,558; ansic: 53,674; python: 32,437; sh: 8,829; asm: 3,071; cs: 2,121; makefile: 964; perl: 859; yacc: 472; php: 132; ruby: 94; f90: 55; sql: 13; csh: 6
file content (112 lines) | stat: -rw-r--r-- 3,604 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*
 *
 * Copyright (c) 2009
 * John Maddock
 *
 * Use, modification and distribution are subject to the 
 * Boost Software License, Version 1.0. (See accompanying file 
 * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
 *
 */

#include <boost/regex.hpp>
#include <boost/detail/lightweight_main.hpp>
#include "../test_macros.hpp"

#ifdef BOOST_INTEL
#pragma warning(disable:1418 981 983 383)
#endif

template <class charT>
void test_named_subexpressions(charT)
{
   //
   // Really this is just a test that the overloaded access functions work correctly:
   //
   static const charT e[] = 
   {
      '(', '?', '\'', 'o', 'n', 'e', '\'', 'a', '+', ')', '(', '?', '<', 't', 'w', 'o', '>', 'b', '+', ')', '\0'
   };
   static const charT t[] = 
   {
      'm', 'm', 'a', 'a', 'a', 'b', 'b', 'n', 'n', '\0'
   };
   static const charT one[] = 
   {
      'o', 'n', 'e', '\0'
   };
   static const charT two[] = 
   {
      't', 'w', 'o', '\0'
   };
   static const std::basic_string<charT> s_one(one);
   static const std::basic_string<charT> s_two(two);
   static const charT result1[] = { 'a', 'a', 'a', '\0' };
   static const charT result2[] = { 'b', 'b', '\0' };
   static const std::basic_string<charT> s_result1(result1);
   static const std::basic_string<charT> s_result2(result2);

   static const char* c_one = "one";
   static const char* c_two = "two";
   static const std::string cs_one(c_one);
   static const std::string cs_two(c_two);

   boost::basic_regex<charT> expression(e);
   boost::match_results<const charT*> what;
   if(regex_search(t, what, expression))
   {
      BOOST_CHECK(what.length(1) == 3);
      BOOST_CHECK(what.length(one) == 3);
      BOOST_CHECK(what.length(s_one) == 3);
      BOOST_CHECK(what.length(c_one) == 3);
      BOOST_CHECK(what.length(cs_one) == 3);
      BOOST_CHECK(what.position(1) == 2);
      BOOST_CHECK(what.position(one) == 2);
      BOOST_CHECK(what.position(s_one) == 2);
      BOOST_CHECK(what.position(c_one) == 2);
      BOOST_CHECK(what.position(cs_one) == 2);
      BOOST_CHECK(what.str(1) == s_result1);
      BOOST_CHECK(what.str(one) == s_result1);
      BOOST_CHECK(what.str(s_one) == s_result1);
      BOOST_CHECK(what.str(c_one) == s_result1);
      BOOST_CHECK(what.str(cs_one) == s_result1);
      BOOST_CHECK(what[1] == s_result1);
      BOOST_CHECK(what[one] == s_result1);
      BOOST_CHECK(what[s_one] == s_result1);
      BOOST_CHECK(what[c_one] == s_result1);
      BOOST_CHECK(what[cs_one] == s_result1);

      BOOST_CHECK(what.length(2) == 2);
      BOOST_CHECK(what.length(two) == 2);
      BOOST_CHECK(what.length(s_two) == 2);
      BOOST_CHECK(what.length(c_two) == 2);
      BOOST_CHECK(what.length(cs_two) == 2);
      BOOST_CHECK(what.position(2) == 5);
      BOOST_CHECK(what.position(two) == 5);
      BOOST_CHECK(what.position(s_two) == 5);
      BOOST_CHECK(what.position(c_two) == 5);
      BOOST_CHECK(what.position(cs_two) == 5);
      BOOST_CHECK(what.str(2) == s_result2);
      BOOST_CHECK(what.str(two) == s_result2);
      BOOST_CHECK(what.str(s_two) == s_result2);
      BOOST_CHECK(what.str(c_two) == s_result2);
      BOOST_CHECK(what.str(cs_two) == s_result2);
      BOOST_CHECK(what[2] == s_result2);
      BOOST_CHECK(what[two] == s_result2);
      BOOST_CHECK(what[s_two] == s_result2);
      BOOST_CHECK(what[c_two] == s_result2);
      BOOST_CHECK(what[cs_two] == s_result2);
   }
   else
   {
      BOOST_ERROR("Expected match not found");
   }
}

int cpp_main( int , char* [] )
{
   test_named_subexpressions(char(0));
   test_named_subexpressions(wchar_t(0));
   return 0;
}