-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcfws_skipper_test.cpp
124 lines (99 loc) · 2.69 KB
/
cfws_skipper_test.cpp
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
113
114
115
116
117
118
119
120
121
122
123
124
// Copyright (C) 2014, Richard Thomson. All rights reserved.
#include <string>
#define BOOST_TEST_DYN_LINK
#include <boost/test/unit_test.hpp>
#include "cfws_skipper.h"
using namespace boost::spirit::qi;
namespace
{
struct fixture
{
fixture()
: suffix("STOP")
{}
bool execute(std::string const& skipped);
const std::string suffix;
std::string text;
std::string::iterator start;
};
bool fixture::execute(std::string const& skipped)
{
text = skipped + suffix;
start = text.begin();
return phrase_parse(start, text.end(), eps,
cfws::skipper<std::string::const_iterator>());
}
}
BOOST_FIXTURE_TEST_SUITE(cfws_skipper_suite, ::fixture);
#define REQUIRE_SKIPPED(text_) \
BOOST_REQUIRE(execute(text_)); \
BOOST_REQUIRE_EQUAL(suffix, (std::string{start, text.end()}))
BOOST_AUTO_TEST_CASE(skips_spaces)
{
REQUIRE_SKIPPED(" ");
}
BOOST_AUTO_TEST_CASE(skips_tabs)
{
REQUIRE_SKIPPED(" \t \t ");
}
BOOST_AUTO_TEST_CASE(skips_folded_whitespace_at_beginning)
{
REQUIRE_SKIPPED("\r\n ");
}
BOOST_AUTO_TEST_CASE(skips_folded_whitespace_in_middle)
{
REQUIRE_SKIPPED(" \r\n \t\t");
}
BOOST_AUTO_TEST_CASE(skips_folded_whitespace_at_end)
{
REQUIRE_SKIPPED(" \t \t \r\n ");
}
BOOST_AUTO_TEST_CASE(skips_comments)
{
REQUIRE_SKIPPED("(this is a comment)");
}
BOOST_AUTO_TEST_CASE(skips_comments_with_leading_and_trailing_spaces)
{
REQUIRE_SKIPPED("( this is a comment )");
}
BOOST_AUTO_TEST_CASE(quoted_whitespace)
{
REQUIRE_SKIPPED("(\\ \\\t)");
}
BOOST_AUTO_TEST_CASE(quoted_visible)
{
REQUIRE_SKIPPED(R"text((\(\)\\))text");
}
BOOST_AUTO_TEST_CASE(nested_comments)
{
REQUIRE_SKIPPED("(this is a comment (with another comment inside))");
}
BOOST_AUTO_TEST_CASE(obsolete_comment_can_contain_control_characters)
{
REQUIRE_SKIPPED("(\x01\x02\x03\x04)");
REQUIRE_SKIPPED("(\x05\x06\x07\x08)");
REQUIRE_SKIPPED("(\x0b\x0c)");
REQUIRE_SKIPPED("(\x0e\x0f)");
REQUIRE_SKIPPED("(\x10\x11\x12\x13)");
REQUIRE_SKIPPED("(\x14\x15\x16\x17)");
REQUIRE_SKIPPED("(\x18\x19\x1a\x1b)");
REQUIRE_SKIPPED("(\x1c\x1d\x1e\x1f)");
}
BOOST_AUTO_TEST_CASE(obsolete_quoted_null)
{
std::string null{};
null.push_back(0);
REQUIRE_SKIPPED(R"((\)" + null + ")");
}
BOOST_AUTO_TEST_CASE(obsolete_quoted_control)
{
REQUIRE_SKIPPED("(\\\x01\\\x02\\\x03\\\x04)");
REQUIRE_SKIPPED("(\\\x05\\\x06\\\x07\\\x08)");
REQUIRE_SKIPPED("(\\\x0b\\\x0c)");
REQUIRE_SKIPPED("(\\\x0e\\\x0f)");
REQUIRE_SKIPPED("(\\\x10\\\x11\\\x12\\\x13)");
REQUIRE_SKIPPED("(\\\x14\\\x15\\\x16\\\x17)");
REQUIRE_SKIPPED("(\\\x18\\\x19\\\x1a\\\x1b)");
REQUIRE_SKIPPED("(\\\x1c\\\x1d\\\x1e\\\x1f)");
}
BOOST_AUTO_TEST_SUITE_END();