Giter Site home page Giter Site logo

cppson's Introduction

Hi there ๐Ÿ‘‹

cppson's People

Contributors

jwvg0425 avatar pjc024789 avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

cppson's Issues

toJson

instance data to json file

handle boolean type values which not wrapped with quotes.

In standard json format, json can accept 'null', 'false' and 'true' values. but your implementation cannot parse boolean types which not wrapped with quotes("").

expected result

JSON_CLASS(Foo)
{
public:
  FIELD(bool, b);
}
{
  "b" : true
}

add tests

#define CATCH_CONFIG_MAIN
#include "catch.h"

TEST_CASE("parse from string") {
    JSON_CLASS(NestedObject)
    {
    public:
        FIELD(int, _int);
        FIELD(bool, _bool);
    };
    JSON_CLASS(TestObject)
    {
    public:
        FIELD(int, _int);
        FIELD(bool, _bool);
        //FIELD(float, _float);
        FIELD(std::string, _string);

        FIELD(std::vector<int>, _vector);

        FIELD(NestedObject, _nested);
    };

    TestObject obj;
    obj.ParseFromString(
        "{"
        /* for 'basic types' section */
        "\"_int\" : 5,"
        "\"_bool\" : \"true\","
        //"\"_float\" : 2.5,"
        "\"_string\" : \"hello\","

        /* for 'std::vector type' section */
        "\"_vector\" : [1, 2, 3 ,4 ,5],"

        /* for 'std::map type' section */
        //"\"_vector\" : [1, 2, 3 ,4 ,5],"

        /* for 'nested object' section */
        "\"_nested\" : {"
            "\"_int\" : 14,"
            "\"_bool\" : \"false\""
            "}"
        "}");

    SECTION("basic types") {
        REQUIRE(obj._int == 5);
        REQUIRE(obj._bool == true);
        //REQUIRE(obj._float == 5.0f);
        REQUIRE(obj._string == "hello");
    }
    SECTION("std::vector type") {
        REQUIRE(obj._vector.size() == 5);
        REQUIRE(obj._vector == (std::vector<int>{1, 2, 3, 4, 5}));
    }
    SECTION("std::map type") {
        /* .... */
    }
    SECTION("nested object") {
        REQUIRE(obj._nested._int == 14);
        REQUIRE(obj._nested._bool == false);
    }
}

move sementics

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.