diff --git a/test/yaml/yaml_parse_test.cc b/test/yaml/yaml_parse_test.cc index c71ee8f9e..9b1fd7fcb 100644 --- a/test/yaml/yaml_parse_test.cc +++ b/test/yaml/yaml_parse_test.cc @@ -3,6 +3,52 @@ #include #include +TEST(YAML_parse, scalar_1) { + const std::string input{"1"}; + const auto result{sourcemeta::jsontoolkit::from_yaml(input)}; + const sourcemeta::jsontoolkit::JSON expected{1}; + EXPECT_EQ(result, expected); +} + +TEST(YAML_parse, object_1) { + const std::string input{"hello: world\nfoo: 1\nbar: true"}; + + const auto result{sourcemeta::jsontoolkit::from_yaml(input)}; + + const sourcemeta::jsontoolkit::JSON expected = + sourcemeta::jsontoolkit::parse(R"JSON({ + "hello": "world", + "foo": 1, + "bar": true + })JSON"); + + EXPECT_EQ(result, expected); +} + +TEST(YAML_parse, object_2) { + const std::string input{"foo: >\n bar\n baz"}; + + const auto result{sourcemeta::jsontoolkit::from_yaml(input)}; + + const sourcemeta::jsontoolkit::JSON expected = + sourcemeta::jsontoolkit::parse(R"JSON({ + "foo": "bar baz" + })JSON"); + + EXPECT_EQ(result, expected); +} + +TEST(YAML_parse, array_1) { + const std::string input{"- foo\n- true"}; + + const auto result{sourcemeta::jsontoolkit::from_yaml(input)}; + + const sourcemeta::jsontoolkit::JSON expected = + sourcemeta::jsontoolkit::parse(R"JSON([ "foo", true ])JSON"); + + EXPECT_EQ(result, expected); +} + TEST(YAML_parse, empty) { const std::string input{""}; EXPECT_THROW(sourcemeta::jsontoolkit::from_yaml(input), @@ -14,3 +60,9 @@ TEST(YAML_parse, blank) { EXPECT_THROW(sourcemeta::jsontoolkit::from_yaml(input), sourcemeta::jsontoolkit::YAMLParseError); } + +TEST(YAML_parse, invalid_1) { + const std::string input{"{ xx"}; + EXPECT_THROW(sourcemeta::jsontoolkit::from_yaml(input), + sourcemeta::jsontoolkit::YAMLParseError); +}