// // json_binder_value_string.t.h // json // // Created by Sam Jaffe on 2/25/17. // #pragma once #include #include "json/json_binder.hpp" using namespace json::binder; using namespace json::parser; class json_binder_value_string_TestSuite : public CxxTest::TestSuite { public: void test_bind_to_string_type() { char data[] = "\"This is a string\""; std::string out = ""; value_binder binder{}; parse(json::binder::bind(out, binder), data, allow_all); TS_ASSERT_EQUALS(out, "This is a string"); } void test_bind_to_string_with_quote_recieves_whole_string() { char data[] = "\"This is a \\\"string\\\"\""; std::string out = ""; value_binder binder{}; parse(json::binder::bind(out, binder), data, allow_all); TS_ASSERT_EQUALS(out, "This is a \"string\""); } void test_cannot_bind_raw_string() { char data[] = "This is a string"; std::string out = ""; value_binder binder{}; TS_ASSERT_THROWS(parse(json::binder::bind(out, binder), data, allow_all), json::malformed_json_exception); TS_ASSERT_EQUALS(out, ""); } void test_throws_error_binding_unterminated_string() { char data[] = "\"This is a string"; std::string out = ""; value_binder binder{}; TS_ASSERT_THROWS(parse(json::binder::bind(out, binder), data, allow_all), json::unterminated_json_exception); TS_ASSERT_EQUALS(out, ""); } void test_write_string() { std::string const expected = "\"This is a string\""; std::stringstream ss; std::string const in = "This is a string"; value_binder binder{}; write(json::binder::bind(in, binder), ss); TS_ASSERT_EQUALS(ss.str(), expected); } void test_write_string_with_quotes() { std::string const expected = "\"This is a \\\"string\\\"\""; std::stringstream ss; std::string const in = "This is a \"string\""; value_binder binder{}; write(json::binder::bind(in, binder), ss); TS_ASSERT_EQUALS(ss.str(), expected); } };