Skip to content

Commit

Permalink
更改测试
Browse files Browse the repository at this point in the history
  • Loading branch information
dayu521 committed Dec 11, 2023
1 parent 7b80b63 commit be45eba
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ message("doctest enabled")

add_executable(mytest
# test/test_BST.cpp
# test/test_usage.cpp
test/test_usage.cpp
# test/test_allocator.cpp
test/test_jsonparser.cpp
)
Expand Down
36 changes: 36 additions & 0 deletions test/test_usage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,39 @@ TEST_CASE("testing json serialization and deserialization")
}

}

TEST_CASE("testing json serialization and deserialization 2")
{
// People lf={18,true,{{"dog",2},{"duck鸭子",1},{"cat",3}}};
Fn lf={
{{18,true,{{"dog",2},{"duck鸭子",1},{"cat",3}}},{},{}},
"liad",
{"pl",56}
};

lsf::SerializeBuilder bu;
lsf::struct_to_json(lf,bu);

std::cout<<bu.get_jsonstring()<<std::endl;

std::ofstream f("example.txt");
if(f.is_open()){
f<<bu.get_jsonstring();
f.close();
std::cout<<"writing to example.txt done"<<std::endl;
}

bu.clear();

//从文件读入
std::cout<<"reading from example.txt "<<std::endl;
lsf::Json j("example.txt");
auto ok=j.run([&](auto t,const std::string &s){
lsf::ErrorType sd=t;
std::cout<<s<<std::endl;
});
CHECK(ok==true);
lsf::TreeNode2string(j.get_output(),bu);
std::cout<<bu.get_jsonstring()<<std::endl;

}

0 comments on commit be45eba

Please sign in to comment.