btool
A parser/converter/transpiler for .bib files
/github/workspace/test/TranslationTableFixtureTest.cpp

Tests for the Translation-Table

Test:
TranslationTable Fixture Tests
#include <gtest/gtest.h>
#include <boost/filesystem/path.hpp>
#include <utility>
#include <sstream>
#include <vector>
using namespace std::literals::string_literals;
struct TranslationTableFixtureTest : public ::testing::Test {
// language=json
std::stringstream{R"(
{
"sortableFields": [],
"styles": [
{
"name": "article",
"requiredFields": [
"author",
"title"
],
"optionalFields": [
"some",
"other",
"field"
]
},
{
"name": "book",
"requiredFields": [
"author",
"title",
"year",
"publisher"
],
"optionalFields": [
"volume",
"series",
"address",
"edition",
"month",
"note",
"isbn"
]
}
]
})"}
} {};
};
TEST_F(TranslationTableFixtureTest, getAllStylesTest) {
const auto expectedStyles = std::vector<StyleProperties>{
{
"article"s,
{
"author"s,
"title"s,
},
{
"some"s,
"other"s,
"field"s
}
},
{
"book"s,
{
"author"s,
"title"s,
"year"s,
"publisher"s
},
{
"volume"s,
"series"s,
"address"s,
"edition"s,
"month"s,
"note"s,
"isbn"s
}
}
};
ASSERT_EQ(sample.getStyleProperties(), expectedStyles);
}
ASSERT_EQ(sample.stylePropertiesOf("book"s),
"book"s,
{
"author"s,
"title"s,
"year"s,
"publisher"s
},
{
"volume"s,
"series"s,
"address"s,
"edition"s,
"month"s,
"note"s,
"isbn"s
}
})
);
}
TEST_F(TranslationTableFixtureTest, getInvalidStyleTest) {
ASSERT_EQ(sample.stylePropertiesOf("invalid style"s), std::nullopt);
}
TEST(TranslationTableTest, constructorTestFromPath) {
ASSERT_NO_THROW(TranslationTable(boost::filesystem::path("../../src/translationTable.json")));
}
TEST(TranslationTableTest, parsingInvalidStyleFieldsTest) {
auto invalidContent = std::stringstream{R"(
{
"styles": [
{
"name": "garbage",
"abc": "def"
}
]
}
)"};
const auto table = TranslationTable(std::move(invalidContent));
const auto expected = std::vector<StyleProperties>{{"garbage", {}, {}}};
ASSERT_EQ(table.getStyleProperties(), expected);
}
TEST(TranslationTableTest, parsingInvalidStyleNameTest) {
auto invalidContent = std::stringstream{R"(
{
"styles": [
{
"someKey": "garbage",
"requiredFields": "def",
"optionalFields": "def"
}
]
}
)"};
const auto table = TranslationTable(std::move(invalidContent));
const auto expected = std::vector<StyleProperties>{{"", {}, {}}};
ASSERT_EQ(table.getStyleProperties(), expected);
}
TEST(TranslationTableTest, parsingInvalidStylesTest) {
auto invalidContent = std::stringstream{R"(
{
"not styles": [
{
"name": "garbage",
"requiredFields": "def",
"optionalFields": "def"
}
]
}
)"};
ASSERT_ANY_THROW(const auto table = TranslationTable(std::move(invalidContent)));
}
TEST(TranslationTableTest, parsingInvalidFileContent) {
auto invalidContent = std::stringstream{R"(
{,
"some": [
{
"invalid": "json"
},
],
}
)"};
ASSERT_ANY_THROW(const auto table = TranslationTable(std::move(invalidContent)));
}
TEST(TranslationTableTest, parsingInvalidFile) {
auto invalidFile = boost::filesystem::path("./someUnExistingFile.json");
ASSERT_ANY_THROW(const auto table = TranslationTable(invalidFile););
}
TEST(TranslationTableTest, parsingDirectory) {
auto invalidFile = boost::filesystem::path(".");
ASSERT_ANY_THROW(const auto table = TranslationTable(invalidFile););
}
StyleProperties
style-properties-container
Definition: StyleProperties.hpp:11
TranslationTableFixtureTest
Definition: TranslationTableFixtureTest.cpp:15
TEST
TEST(BibelementTests, constructionTest)
Definition: BibElementFixtureTest.cpp:42
TEST_F
TEST_F(BibElementFixtureTest, completeElementTest)
Definition: BibElementFixtureTest.cpp:34
TranslationTable.hpp
TranslationTable
api to interact with translation-table resource
Definition: TranslationTable.hpp:16