canonical_string_test.cc
Go to the documentation of this file.
1 #define BOOST_TEST_MODULE(canonical_string_t)
2 #include "boost/test/unit_test.hpp"
3 
5 
6 using namespace cet;
7 
8 BOOST_AUTO_TEST_SUITE(canonical_string_t)
9 
10 BOOST_AUTO_TEST_CASE(is_single_quoted_string_t)
11 {
12  BOOST_TEST(is_single_quoted_string("'3'")); // '3'
13  BOOST_TEST(!is_single_quoted_string("\"3\"")); // "3"
14  BOOST_TEST(!is_single_quoted_string("'3',")); // '3',
15  BOOST_TEST(!is_single_quoted_string(",'3'")); // ,'3'
16  BOOST_TEST(is_single_quoted_string("'\\\'")); // '\\\'
17 }
18 
19 BOOST_AUTO_TEST_CASE(is_double_quoted_string_t)
20 {
21  BOOST_TEST(is_double_quoted_string("\"3\"")); // "3"
22  BOOST_TEST(!is_double_quoted_string("'3'")); // '3'
23  BOOST_TEST(!is_double_quoted_string("\"3\",")); // "3",
24  BOOST_TEST(!is_double_quoted_string(",\"3\"")); // ,"3"
25  // Controversial:
26  BOOST_TEST(is_double_quoted_string("\"\\\"")); // "\"
27 }
28 
29 void
30 becomes(std::string const& input, std::string const& wanted)
31 {
33  BOOST_TEST(cet::canonical_string(input, result),
34  "canonical_result returns false on input: '" << input << "'");
35  BOOST_TEST(result == wanted);
36 }
37 
40 {
41  return '"' + s + '"';
42 }
43 
46 {
47  return '\'' + s + '\'';
48 }
49 
50 BOOST_AUTO_TEST_CASE(canonical_string_t)
51 {
52  becomes("a", dquoted("a"));
53  becomes(squoted("a"), dquoted("a"));
54  becomes(dquoted("a"), dquoted("a"));
55  {
57  BOOST_TEST(!canonical_string("", result),
58  "canonical_string() should return false on empty input.");
59  }
60  becomes(squoted("\n"), dquoted("\\n"));
61  becomes(dquoted("\n"), dquoted("\\n"));
62  becomes(squoted("\\"), dquoted("\\\\"));
63  becomes(dquoted("\\"), dquoted("\\\\"));
64  becomes(squoted("\\\\"), dquoted("\\\\\\\\"));
65  becomes(dquoted("\\\\"), dquoted("\\\\"));
66 
67  becomes(squoted("\t\'\""), dquoted("\\t\\\'\\\""));
68  becomes(dquoted("\t\'\""), dquoted("\\t\\\'\\\""));
69 }
70 
71 BOOST_AUTO_TEST_SUITE_END()
void becomes(std::string const &input, std::string const &wanted)
static QCString result
std::string dquoted(std::string const &s)
std::string string
Definition: nybbler.cc:12
bool is_double_quoted_string(std::string const &str)
static int input(void)
Definition: code.cpp:15695
bool canonical_string(std::string const &str, std::string &result)
std::string squoted(std::string const &s)
BOOST_AUTO_TEST_CASE(is_single_quoted_string_t)
bool is_single_quoted_string(std::string const &str)
static QCString * s
Definition: config.cpp:1042