-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Juan Cruz Viotti <[email protected]>
- Loading branch information
Showing
3 changed files
with
77 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
add_executable(sourcemeta_jsontoolkit_yaml_unit | ||
yaml_parse_test.cc) | ||
noa_add_default_options(PRIVATE sourcemeta_jsontoolkit_yaml_unit) | ||
target_link_libraries(sourcemeta_jsontoolkit_yaml_unit | ||
PRIVATE GTest::gtest GTest::gtest_main) | ||
target_link_libraries(sourcemeta_jsontoolkit_yaml_unit | ||
PRIVATE sourcemeta::jsontoolkit::json) | ||
target_link_libraries(sourcemeta_jsontoolkit_yaml_unit | ||
PRIVATE sourcemeta::jsontoolkit::yaml) | ||
set_target_properties(sourcemeta_jsontoolkit_yaml_unit | ||
PROPERTIES FOLDER "JSON Toolkit/YAML") | ||
add_test(NAME JSON COMMAND sourcemeta_jsontoolkit_yaml_unit --gtest_brief=1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#include <gtest/gtest.h> | ||
|
||
#include <sourcemeta/jsontoolkit/json.h> | ||
#include <sourcemeta/jsontoolkit/yaml.h> | ||
|
||
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), | ||
sourcemeta::jsontoolkit::YAMLParseError); | ||
} | ||
|
||
TEST(YAML_parse, blank) { | ||
const std::string input{" "}; | ||
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); | ||
} |