2012-04-20 18:17:38 +10:00
|
|
|
|
|
|
|
#include "../debug.hpp"
|
|
|
|
#include "../json.hpp"
|
2013-02-27 15:17:33 +11:00
|
|
|
#include "../maths.hpp"
|
2012-04-20 18:17:38 +10:00
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
#include <cstdlib>
|
|
|
|
|
|
|
|
int
|
|
|
|
main (int, char**) {
|
2015-02-02 23:02:26 +11:00
|
|
|
static const char TEST_STRING[] = R"_(
|
|
|
|
{
|
|
|
|
"string":"brad",
|
|
|
|
"integer":1,
|
|
|
|
"null":null,
|
|
|
|
"false":false,
|
|
|
|
"true":true,
|
|
|
|
"double":3.14,
|
|
|
|
"object":{
|
|
|
|
"test": "test"
|
|
|
|
},
|
|
|
|
"array":[
|
|
|
|
1, 2, 3, 4
|
|
|
|
]
|
|
|
|
})_";
|
2012-04-20 18:17:38 +10:00
|
|
|
|
2015-02-02 21:22:38 +11:00
|
|
|
std::unique_ptr<json::tree::node> ptr = json::tree::parse (TEST_STRING);
|
2015-01-28 14:49:34 +11:00
|
|
|
CHECK (ptr->is_object ());
|
2012-04-20 18:17:38 +10:00
|
|
|
|
2015-02-02 21:22:38 +11:00
|
|
|
const json::tree::node &ref = *ptr;
|
2012-04-20 18:17:38 +10:00
|
|
|
|
2015-01-28 14:49:34 +11:00
|
|
|
CHECK ( ref["string"].is_string ());
|
|
|
|
CHECK (!ref["string"].is_array ());
|
|
|
|
CHECK (!ref["string"].is_boolean ());
|
|
|
|
CHECK (!ref["string"].is_null ());
|
|
|
|
CHECK (!ref["string"].is_number ());
|
|
|
|
CHECK (!ref["string"].is_object ());
|
2012-05-14 16:10:32 +10:00
|
|
|
CHECK_EQ ( ref["string"].as_string (), "brad");
|
2012-04-20 18:17:38 +10:00
|
|
|
|
2015-01-28 14:49:34 +11:00
|
|
|
CHECK ( ref["integer"].is_number ());
|
|
|
|
CHECK (!ref["integer"].is_array ());
|
|
|
|
CHECK (!ref["integer"].is_boolean ());
|
|
|
|
CHECK (!ref["integer"].is_null ());
|
|
|
|
CHECK (!ref["integer"].is_object ());
|
|
|
|
CHECK (!ref["integer"].is_string ());
|
2013-02-27 15:17:33 +11:00
|
|
|
CHECK (
|
|
|
|
exactly_equal (
|
|
|
|
(unsigned)ref["integer"].as_number ().native (),
|
|
|
|
1u
|
|
|
|
)
|
|
|
|
);
|
2012-04-20 18:17:38 +10:00
|
|
|
|
2015-01-28 14:49:34 +11:00
|
|
|
CHECK ( ref["null"].is_null ());
|
|
|
|
CHECK (!ref["null"].is_array ());
|
|
|
|
CHECK (!ref["null"].is_boolean ());
|
|
|
|
CHECK (!ref["null"].is_number ());
|
|
|
|
CHECK (!ref["null"].is_object ());
|
|
|
|
CHECK (!ref["null"].is_string ());
|
2012-04-20 18:17:38 +10:00
|
|
|
|
2015-01-28 14:49:34 +11:00
|
|
|
CHECK ( ref["false"].is_boolean ());
|
|
|
|
CHECK (!ref["false"].is_array ());
|
|
|
|
CHECK (!ref["false"].is_null ());
|
|
|
|
CHECK (!ref["false"].is_number ());
|
|
|
|
CHECK (!ref["false"].is_object ());
|
|
|
|
CHECK (!ref["false"].is_string ());
|
2012-05-14 16:10:32 +10:00
|
|
|
CHECK_EQ ( ref["false"].as_boolean (), false);
|
2012-04-20 18:17:38 +10:00
|
|
|
|
2015-01-28 14:49:34 +11:00
|
|
|
CHECK ( ref["true"].is_boolean ());
|
|
|
|
CHECK (!ref["true"].is_array ());
|
|
|
|
CHECK (!ref["true"].is_null ());
|
|
|
|
CHECK (!ref["true"].is_number ());
|
|
|
|
CHECK (!ref["true"].is_object ());
|
|
|
|
CHECK (!ref["true"].is_string ());
|
2012-05-14 16:10:32 +10:00
|
|
|
CHECK_EQ ( ref["true"].as_boolean (), true);
|
2012-04-20 18:17:38 +10:00
|
|
|
|
2015-01-28 14:49:34 +11:00
|
|
|
CHECK ( ref["double"].is_number ());
|
|
|
|
CHECK (!ref["double"].is_array ());
|
|
|
|
CHECK (!ref["double"].is_boolean ());
|
|
|
|
CHECK (!ref["double"].is_null ());
|
|
|
|
CHECK (!ref["double"].is_object ());
|
|
|
|
CHECK (!ref["double"].is_string ());
|
2013-02-27 15:17:33 +11:00
|
|
|
CHECK (
|
|
|
|
exactly_equal (
|
|
|
|
ref["double"].as_number ().native (),
|
|
|
|
3.14
|
|
|
|
)
|
|
|
|
);
|
2012-04-20 18:17:38 +10:00
|
|
|
|
2015-01-28 14:49:34 +11:00
|
|
|
CHECK ( ref["object"].is_object ());
|
|
|
|
CHECK (!ref["object"].is_array ());
|
|
|
|
CHECK (!ref["object"].is_boolean ());
|
|
|
|
CHECK (!ref["object"].is_null ());
|
|
|
|
CHECK (!ref["object"].is_number ());
|
|
|
|
CHECK (!ref["object"].is_string ());
|
2012-04-20 18:17:38 +10:00
|
|
|
|
2015-01-28 14:49:34 +11:00
|
|
|
CHECK ( ref["array"].is_array ());
|
|
|
|
CHECK (!ref["array"].is_boolean ());
|
|
|
|
CHECK (!ref["array"].is_null ());
|
|
|
|
CHECK (!ref["array"].is_number ());
|
|
|
|
CHECK (!ref["array"].is_object ());
|
|
|
|
CHECK (!ref["array"].is_string ());
|
2012-04-20 18:17:38 +10:00
|
|
|
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|