7 #define BOOST_TEST_MODULE (document test) 8 #include "boost/test/unit_test.hpp" 22 string const nil(9,
'\0');
23 string const failed(8,
'\0');
26 parse_as(
string const&
input)
43 return '\'' + s +
'\'';
47 BOOST_AUTO_TEST_SUITE(document_test)
51 BOOST_CHECK(parse_as(
"@nil") == nil);
52 BOOST_CHECK(parse_as(
" @nil") == nil);
53 BOOST_CHECK(parse_as(
" @nil ") == nil);
54 BOOST_CHECK(parse_as(
" true or false ") == failed);
55 BOOST_CHECK(parse_as(
" TRUE or FALSE ") == failed);
56 BOOST_CHECK(parse_as(
"infinity") ==
"+infinity");
57 BOOST_CHECK(parse_as(
" -infinity") ==
"-infinity");
58 BOOST_CHECK(parse_as(
"+ infinity") == failed);
59 BOOST_CHECK(parse_as(
"nil_") ==
dquoted(
"nil_"));
64 BOOST_CHECK(parse_as(
"0") ==
"0");
65 BOOST_CHECK(parse_as(
"000") ==
"0");
66 BOOST_CHECK(parse_as(
"123456") ==
"123456");
67 BOOST_CHECK(parse_as(
"1234567") ==
"1.234567e6");
68 BOOST_CHECK(parse_as(
"0.0") ==
"0");
69 BOOST_CHECK(parse_as(
"0.") ==
"0");
71 BOOST_CHECK(parse_as(
"+0") ==
"0");
72 BOOST_CHECK(parse_as(
"+000") ==
"0");
73 BOOST_CHECK(parse_as(
"+123456") ==
"123456");
74 BOOST_CHECK(parse_as(
"+1234567") ==
"1.234567e6");
75 BOOST_CHECK(parse_as(
"-0") ==
"0");
76 BOOST_CHECK(parse_as(
"-000") ==
"0");
77 BOOST_CHECK(parse_as(
"-123456") ==
"-123456");
78 BOOST_CHECK(parse_as(
"-1234567") ==
"-1.234567e6");
79 BOOST_CHECK(parse_as(
"1.23e-4") ==
"1.23e-4");
81 BOOST_CHECK(parse_as(
"+0.0E0") ==
"0");
82 BOOST_CHECK(parse_as(
"+00.") ==
"0");
83 BOOST_CHECK(parse_as(
"-0e99") ==
"0");
84 BOOST_CHECK(parse_as(
"-.00") ==
"0");
85 BOOST_CHECK(parse_as(
"+123456e0") ==
"123456");
86 BOOST_CHECK(parse_as(
"+1234567e-0") ==
"1.234567e6");
91 BOOST_CHECK(parse_as(
"Hello") ==
dquoted(
"Hello"));
92 BOOST_CHECK(parse_as(
"_123") ==
dquoted(
"_123"));
93 BOOST_CHECK(parse_as(
"_123Aa_") ==
dquoted(
"_123Aa_"));
94 BOOST_CHECK(parse_as(
"X...") == failed);
95 BOOST_CHECK(parse_as(
"3a4B5c") ==
dquoted(
"3a4B5c"));
96 BOOST_CHECK(parse_as(
"0123Aa_") ==
dquoted(
"0123Aa_"));
97 BOOST_CHECK(parse_as(
"9...") == failed);
98 BOOST_CHECK(parse_as(
"nil") ==
dquoted(
"nil"));
99 BOOST_CHECK(parse_as(R
"($\d+^)") == failed); 101 BOOST_CHECK(parse_as(" ( 1 , 2.3 ) ") ==
"(1,2.3)");
102 BOOST_CHECK(parse_as(
" ( infinity , -infinity ) ") ==
103 "(+infinity,-infinity)");
104 BOOST_CHECK(parse_as(
dquoted(
"Hi, there!")) ==
dquoted(
"Hi, there!"));
106 BOOST_CHECK(parse_as(
squoted(
"Hi, there!")) ==
dquoted(
"Hi, there!"));
107 BOOST_CHECK(parse_as(
squoted(
"\\t\\n")) ==
dquoted(
"\\\\t\\\\n"));
108 BOOST_CHECK(parse_as(
"infinityx") ==
dquoted(
"infinityx"));
109 BOOST_CHECK(parse_as(
dquoted(
"Hi, \\\"Tom\\\"")) ==
113 BOOST_CHECK(parse_as(
" [1,2.3] ") ==
"[1,2.3]");
114 BOOST_CHECK(parse_as(
" [ 1 , 2.3 ] ") ==
"[1,2.3]");
115 BOOST_CHECK(parse_as(
" [hello,there] ") ==
117 BOOST_CHECK(parse_as(
"[ hello,\nthere\t] ") ==
119 BOOST_CHECK(parse_as(
" [ ] ") ==
"[]");
121 BOOST_CHECK(parse_as(
"{ }") ==
"{}");
122 BOOST_CHECK(parse_as(
"{a : 1.2 }") ==
"{a:1.2}");
123 BOOST_CHECK(parse_as(
"{a : 1.2 b: hello}") ==
124 "{a:1.2 b:" +
dquoted(
"hello") +
"}");
125 BOOST_CHECK(parse_as(
"{a : 3 b: 7 a: @erase}") ==
"{b:7}");
128 BOOST_AUTO_TEST_SUITE_END()
bool parse_value_string(std::string const &s, extended_value &v, std::string &unparsed)
std::string dquoted(std::string const &s)
BOOST_AUTO_TEST_CASE(symbols)
std::string squoted(std::string const &s)
std::string to_string() const