Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
re #442
  • Loading branch information
biojppm committed Jun 20, 2024
1 parent c9e21e3 commit f8b69cb
Showing 1 changed file with 141 additions and 0 deletions.
141 changes: 141 additions & 0 deletions test/test_serialize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,147 @@ TEST(deserialize, issue434_3)
}


template<class T>
void test442(csubstr input, csubstr expected, NodeType style_flag)
{
// as a seq member
{
const std::string input_str = formatrs<std::string>("- {}", input);
const std::string expected_str = formatrs<std::string>("- {}", expected);
const Tree tree = parse_in_arena(to_csubstr(input_str));
EXPECT_TRUE(tree[0].type_has_all(style_flag));
T obj; // T is a scalar type like int, char, double, etc.
tree[0] >> obj;
EXPECT_EQ(expected_str, emitrs_yaml<std::string>(tree));
Tree out_tree;
out_tree.rootref() |= SEQ;
out_tree[0] << obj;
out_tree[0].set_val_style(style_flag);
EXPECT_EQ(expected_str, emitrs_yaml<std::string>(out_tree));
}
// as a map member
{
const std::string input_str = formatrs<std::string>("val: {}", input);
const std::string expected_str = formatrs<std::string>("val: {}", expected);
const Tree tree = parse_in_arena(to_csubstr(input_str));
EXPECT_TRUE(tree["val"].type_has_all(style_flag));
T obj; // T is a scalar type like int, char, double, etc.
tree["val"] >> obj;
EXPECT_EQ(expected_str, emitrs_yaml<std::string>(tree));
Tree out_tree;
out_tree.rootref() |= MAP;
out_tree["val"] << obj;
out_tree["val"].set_val_style(style_flag);
EXPECT_EQ(expected_str, emitrs_yaml<std::string>(out_tree));
}
// as a doc scalar
{
const std::string expected_str(expected.str, expected.len);
const Tree tree = parse_in_arena(input);
EXPECT_TRUE(tree.rootref().type_has_all(style_flag));
T obj; // T is a scalar type like int, char, double, etc.
tree.rootref() >> obj;
EXPECT_EQ(expected_str, emitrs_yaml<std::string>(tree));
Tree out_tree;
out_tree.rootref() << obj;
out_tree.rootref().set_val_style(style_flag);
EXPECT_EQ(expected_str, emitrs_yaml<std::string>(out_tree));
}
}
TEST(serialize, issue442_00)
{
test442<int>("123", "123\n", VAL_PLAIN);
}
TEST(serialize, issue442_01)
{
test442<int>("-123", "-123\n", VAL_PLAIN);
}
TEST(serialize, issue442_02)
{
//test442<int>("+123", "123\n", VAL_PLAIN);
}
TEST(serialize, issue442_10)
{
test442<float>("2.35e-10", "2.35e-10\n", VAL_PLAIN);
}
TEST(serialize, issue442_11)
{
test442<float>("-2.35e-10", "-2.35e-10\n", VAL_PLAIN);
}
TEST(serialize, issue442_12)
{
//test442<float>("+2.35e-10", "2.35e-10\n", VAL_PLAIN);
}
TEST(serialize, issue442_20)
{
test442<double>("2.35e-10", "2.35e-10\n", VAL_PLAIN);
}
TEST(serialize, issue442_21)
{
test442<double>("-2.35e-10", "-2.35e-10\n", VAL_PLAIN);
}
TEST(serialize, issue442_22)
{
//test442<double>("+2.35e-10", "2.35e-10\n", VAL_PLAIN);
}
TEST(serialize, issue442_30)
{
test442<char>("'a'", "'a'\n", VAL_SQUO);
}
TEST(serialize, issue442_31)
{
test442<char>("' '", "' '\n", VAL_SQUO);
}
TEST(serialize, issue442_40)
{
test442<char>("\"a\"", "\"a\"\n", VAL_DQUO);
}
TEST(serialize, issue442_41)
{
test442<char>("\" \"", "\" \"\n", VAL_DQUO);
}
TEST(serialize, issue442_50)
{
test442<char>("a", "a\n", VAL_PLAIN);
}
TEST(serialize, issue442_60)
{
Tree tree;
tree.rootref() << 123;
EXPECT_EQ(std::string("123\n"), emitrs_yaml<std::string>(tree));
}
TEST(serialize, issue442_61)
{
Tree tree;
tree.rootref() << -123;
EXPECT_EQ(std::string("-123\n"), emitrs_yaml<std::string>(tree));
}
TEST(serialize, issue442_62)
{
Tree tree;
tree.rootref() << 2.35e-10;
EXPECT_EQ(std::string("2.35e-10\n"), emitrs_yaml<std::string>(tree));
}
TEST(serialize, issue442_63)
{
Tree tree;
tree.rootref() << -2.35e-10;
EXPECT_EQ(std::string("-2.35e-10\n"), emitrs_yaml<std::string>(tree));
}
TEST(serialize, issue442_64)
{
Tree tree;
tree.rootref() << 2.35e-10f;
EXPECT_EQ(std::string("2.35e-10\n"), emitrs_yaml<std::string>(tree));
}
TEST(serialize, issue442_65)
{
Tree tree;
tree.rootref() << -2.35e-10f;
EXPECT_EQ(std::string("-2.35e-10\n"), emitrs_yaml<std::string>(tree));
}


//-------------------------------------------
// this is needed to use the test case library
Case const* get_case(csubstr /*name*/)
Expand Down

0 comments on commit f8b69cb

Please sign in to comment.