diff --git a/src/c4/yml/node_type.cpp b/src/c4/yml/node_type.cpp index fe4119ca..dac9bd27 100644 --- a/src/c4/yml/node_type.cpp +++ b/src/c4/yml/node_type.cpp @@ -153,6 +153,10 @@ bool scalar_style_query_plain(csubstr s) noexcept else if(s.sub(2).is_number()) return true; } + else if(s.begins_with_any("0123456789.-+") && s.is_number()) + { + return true; + } return s != ':' && ( ! s.begins_with_any("-:?*&,'\"{}[]|>%#@`\r")) // @ and ` are reserved characters && ( ! s.ends_with_any(":#")) diff --git a/test/test_node_type.cpp b/test/test_node_type.cpp index 3ba00ed0..47b55b36 100644 --- a/test/test_node_type.cpp +++ b/test/test_node_type.cpp @@ -129,29 +129,132 @@ TEST(NodeType, type_str) #undef teststr } -TEST(NodeType, scalar_style_choose) -{ - EXPECT_EQ(scalar_style_choose(" \n\t"), SCALAR_DQUO); - EXPECT_EQ(scalar_style_choose("01"), SCALAR_PLAIN); -} - TEST(NodeType, scalar_style_choose_json) { EXPECT_EQ(scalar_style_json_choose("true"), SCALAR_PLAIN); EXPECT_EQ(scalar_style_json_choose("false"), SCALAR_PLAIN); EXPECT_EQ(scalar_style_json_choose("null"), SCALAR_PLAIN); EXPECT_EQ(scalar_style_json_choose("0.1"), SCALAR_PLAIN); + EXPECT_EQ(scalar_style_json_choose("-0.1"), SCALAR_PLAIN); + EXPECT_EQ(scalar_style_json_choose("+0.1"), SCALAR_PLAIN); + EXPECT_EQ(scalar_style_json_choose(".1"), SCALAR_PLAIN); + EXPECT_EQ(scalar_style_json_choose("+.1"), SCALAR_PLAIN); + EXPECT_EQ(scalar_style_json_choose("-.1"), SCALAR_PLAIN); EXPECT_EQ(scalar_style_json_choose("01"), SCALAR_DQUO); EXPECT_EQ(scalar_style_json_choose("foo"), SCALAR_DQUO); EXPECT_EQ(scalar_style_json_choose("bar"), SCALAR_DQUO); } +TEST(NodeType, scalar_style_choose) +{ + EXPECT_EQ(scalar_style_choose(" \n\t"), SCALAR_DQUO); + EXPECT_EQ(scalar_style_choose("-.inf"), SCALAR_PLAIN); + EXPECT_EQ(scalar_style_choose("-.INF"), SCALAR_PLAIN); + EXPECT_EQ(scalar_style_choose("-.034"), SCALAR_PLAIN); + EXPECT_EQ(scalar_style_choose("-.034x"), SCALAR_SQUO); + EXPECT_EQ(scalar_style_choose("2.35e-10"), SCALAR_PLAIN); + EXPECT_EQ(scalar_style_choose("-2.35e-10"), SCALAR_PLAIN); + EXPECT_EQ(scalar_style_choose("+2.35e-10"), SCALAR_PLAIN); + EXPECT_EQ(scalar_style_choose("0.1"), SCALAR_PLAIN); + EXPECT_EQ(scalar_style_choose("-0.1"), SCALAR_PLAIN); + EXPECT_EQ(scalar_style_choose("+0.1"), SCALAR_PLAIN); + EXPECT_EQ(scalar_style_choose("01"), SCALAR_PLAIN); + EXPECT_EQ(scalar_style_choose("0x1"), SCALAR_PLAIN); + EXPECT_EQ(scalar_style_choose("0o1"), SCALAR_PLAIN); + EXPECT_EQ(scalar_style_choose("0b1"), SCALAR_PLAIN); + EXPECT_EQ(scalar_style_choose("0x1"), SCALAR_PLAIN); + EXPECT_EQ(scalar_style_choose("0o1"), SCALAR_PLAIN); + EXPECT_EQ(scalar_style_choose("0b1"), SCALAR_PLAIN); + EXPECT_EQ(scalar_style_choose("-01"), SCALAR_PLAIN); + EXPECT_EQ(scalar_style_choose("-0x1"), SCALAR_PLAIN); + EXPECT_EQ(scalar_style_choose("-0o1"), SCALAR_PLAIN); + EXPECT_EQ(scalar_style_choose("-0b1"), SCALAR_PLAIN); + EXPECT_EQ(scalar_style_choose("-0x1"), SCALAR_PLAIN); + EXPECT_EQ(scalar_style_choose("-0o1"), SCALAR_PLAIN); + EXPECT_EQ(scalar_style_choose("-0b1"), SCALAR_PLAIN); + EXPECT_EQ(scalar_style_choose("+01"), SCALAR_PLAIN); + EXPECT_EQ(scalar_style_choose("+0x1"), SCALAR_PLAIN); + EXPECT_EQ(scalar_style_choose("+0o1"), SCALAR_PLAIN); + EXPECT_EQ(scalar_style_choose("+0b1"), SCALAR_PLAIN); + EXPECT_EQ(scalar_style_choose("+0x1"), SCALAR_PLAIN); + EXPECT_EQ(scalar_style_choose("+0o1"), SCALAR_PLAIN); + EXPECT_EQ(scalar_style_choose("+0b1"), SCALAR_PLAIN); + EXPECT_EQ(scalar_style_choose("01"), SCALAR_PLAIN); + EXPECT_EQ(scalar_style_choose("0X1"), SCALAR_PLAIN); + EXPECT_EQ(scalar_style_choose("0O1"), SCALAR_PLAIN); + EXPECT_EQ(scalar_style_choose("0B1"), SCALAR_PLAIN); + EXPECT_EQ(scalar_style_choose("0X1"), SCALAR_PLAIN); + EXPECT_EQ(scalar_style_choose("0O1"), SCALAR_PLAIN); + EXPECT_EQ(scalar_style_choose("0B1"), SCALAR_PLAIN); + EXPECT_EQ(scalar_style_choose("-01"), SCALAR_PLAIN); + EXPECT_EQ(scalar_style_choose("-0X1"), SCALAR_PLAIN); + EXPECT_EQ(scalar_style_choose("-0O1"), SCALAR_PLAIN); + EXPECT_EQ(scalar_style_choose("-0B1"), SCALAR_PLAIN); + EXPECT_EQ(scalar_style_choose("-0X1"), SCALAR_PLAIN); + EXPECT_EQ(scalar_style_choose("-0O1"), SCALAR_PLAIN); + EXPECT_EQ(scalar_style_choose("-0B1"), SCALAR_PLAIN); + EXPECT_EQ(scalar_style_choose("+01"), SCALAR_PLAIN); + EXPECT_EQ(scalar_style_choose("+0X1"), SCALAR_PLAIN); + EXPECT_EQ(scalar_style_choose("+0O1"), SCALAR_PLAIN); + EXPECT_EQ(scalar_style_choose("+0B1"), SCALAR_PLAIN); + EXPECT_EQ(scalar_style_choose("+0X1"), SCALAR_PLAIN); + EXPECT_EQ(scalar_style_choose("+0O1"), SCALAR_PLAIN); + EXPECT_EQ(scalar_style_choose("+0B1"), SCALAR_PLAIN); +} + TEST(NodeType, scalar_style_query_plain) { EXPECT_TRUE(scalar_style_query_plain("-.inf")); EXPECT_TRUE(scalar_style_query_plain("-.INF")); EXPECT_TRUE(scalar_style_query_plain("-.034")); EXPECT_FALSE(scalar_style_query_plain("-.034x")); + EXPECT_TRUE(scalar_style_query_plain("2.35e-10")); + EXPECT_TRUE(scalar_style_query_plain("-2.35e-10")); + EXPECT_TRUE(scalar_style_query_plain("+2.35e-10")); + EXPECT_TRUE(scalar_style_query_plain("0.1")); + EXPECT_TRUE(scalar_style_query_plain("-0.1")); + EXPECT_TRUE(scalar_style_query_plain("+0.1")); + EXPECT_TRUE(scalar_style_query_plain("01")); + EXPECT_TRUE(scalar_style_query_plain("0x1")); + EXPECT_TRUE(scalar_style_query_plain("0o1")); + EXPECT_TRUE(scalar_style_query_plain("0b1")); + EXPECT_TRUE(scalar_style_query_plain("0x1")); + EXPECT_TRUE(scalar_style_query_plain("0o1")); + EXPECT_TRUE(scalar_style_query_plain("0b1")); + EXPECT_TRUE(scalar_style_query_plain("+01")); + EXPECT_TRUE(scalar_style_query_plain("+0x1")); + EXPECT_TRUE(scalar_style_query_plain("+0o1")); + EXPECT_TRUE(scalar_style_query_plain("+0b1")); + EXPECT_TRUE(scalar_style_query_plain("+0x1")); + EXPECT_TRUE(scalar_style_query_plain("+0o1")); + EXPECT_TRUE(scalar_style_query_plain("+0b1")); + EXPECT_TRUE(scalar_style_query_plain("-01")); + EXPECT_TRUE(scalar_style_query_plain("-0x1")); + EXPECT_TRUE(scalar_style_query_plain("-0o1")); + EXPECT_TRUE(scalar_style_query_plain("-0b1")); + EXPECT_TRUE(scalar_style_query_plain("-0x1")); + EXPECT_TRUE(scalar_style_query_plain("-0o1")); + EXPECT_TRUE(scalar_style_query_plain("-0b1")); + EXPECT_TRUE(scalar_style_query_plain("0X1")); + EXPECT_TRUE(scalar_style_query_plain("0O1")); + EXPECT_TRUE(scalar_style_query_plain("0B1")); + EXPECT_TRUE(scalar_style_query_plain("0X1")); + EXPECT_TRUE(scalar_style_query_plain("0O1")); + EXPECT_TRUE(scalar_style_query_plain("0B1")); + EXPECT_TRUE(scalar_style_query_plain("+01")); + EXPECT_TRUE(scalar_style_query_plain("+0X1")); + EXPECT_TRUE(scalar_style_query_plain("+0O1")); + EXPECT_TRUE(scalar_style_query_plain("+0B1")); + EXPECT_TRUE(scalar_style_query_plain("+0X1")); + EXPECT_TRUE(scalar_style_query_plain("+0O1")); + EXPECT_TRUE(scalar_style_query_plain("+0B1")); + EXPECT_TRUE(scalar_style_query_plain("-01")); + EXPECT_TRUE(scalar_style_query_plain("-0X1")); + EXPECT_TRUE(scalar_style_query_plain("-0O1")); + EXPECT_TRUE(scalar_style_query_plain("-0B1")); + EXPECT_TRUE(scalar_style_query_plain("-0X1")); + EXPECT_TRUE(scalar_style_query_plain("-0O1")); + EXPECT_TRUE(scalar_style_query_plain("-0B1")); }