| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- //
- // json_binder_test_bool.t.h
- // json
- //
- // Created by Sam Jaffe on 2/27/17.
- //
- #pragma once
- #include <cxxtest/TestSuite.h>
- #include "json/json_binder.hpp"
- using namespace json::binder;
- using namespace json::parser;
- class json_binder_value_bool_TestSuite : public CxxTest::TestSuite {
- public:
- void test_parse_bool_true() {
- char data[] = "true";
- bool out = false;
- value_binder<bool> binder{};
- parse(bind(out, binder), data, allow_all);
- TS_ASSERT_EQUALS( out, true );
- }
-
- void test_parse_bool_false() {
- char data[] = "false";
- bool out = true;
- value_binder<bool> binder{};
- parse(bind(out, binder), data, allow_all);
- TS_ASSERT_EQUALS( out, false );
- }
- void test_parse_nonbool_throws() {
- char data[] = "YES"; // Obj-C
- bool out = false;
- value_binder<bool> binder{};
- TS_ASSERT_THROWS(parse(bind(out, binder), data, allow_all),
- json::malformed_json_exception);
- }
-
- void test_write_bool_true() {
- std::string const expected = "true";
- std::stringstream ss;
- bool const in = true;
- value_binder<bool> binder{};
- write(bind(in, binder), ss);
- TS_ASSERT_EQUALS(ss.str(), expected);
- }
-
- void test_write_bool_false() {
- std::string const expected = "false";
- std::stringstream ss;
- bool const in = false;
- value_binder<bool> binder{};
- write(bind(in, binder), ss);
- TS_ASSERT_EQUALS(ss.str(), expected);
- }
- };
|