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

Tests for the Parser

Test:
Parser Fixture Tests
#include <gtest/gtest.h>
#include <Parser.hpp>
#include <BibElement.hpp>
#include <spdlog/spdlog.h>
#include <string>
#include <string_view>
using namespace std::literals::string_literals;
using namespace std::literals::string_view_literals;
struct ParserFixtureTest : public ::testing::Test {
Parser sample;
ParserFixtureTest() : sample{
// language=json
std::stringstream{R"(
{
"sortableFields": [],
"styles": [
{
"name": "article",
"requiredFields": [
"author",
"title"
],
"optionalFields": [
"journal",
"year",
"volume",
"number",
"month",
"url",
"booktitle"
]
},
{
"name": "book",
"requiredFields": [
"author",
"title",
"year",
"publisher"
],
"optionalFields": [
"volume",
"series",
"address",
"edition",
"month",
"note",
"isbn"
]
}
]
})"}, {"article"}} {};
};
TEST_F(ParserFixtureTest, parseEmptyFileContents) {
ASSERT_EQ(sample.generate(""sv, "year"s, "someFile.bib"s), std::vector<BibElement>());
}
TEST_F(ParserFixtureTest, parseCorrectContent) {
auto const input = R"(@article{FeigenspanSiFr11,
author = {Janet Feigenspan and Norbert Siegmund and Jana Fruth},
title = {{On the Role of Program Comprehension in Embedded Systems}},
journal = {Softwaretechnik-Trends},
year = {2011},
volume = {31},
number = {2},
month = May,
url = {http://www.uni-koblenz-landau.de/koblenz/fb4/institute/uebergreifend/sre/conferences/wsr/wsr2011/wsr2011_proceedings.pdf}
})"sv;
const std::vector<BibElement> expected{
{
"FeigenspanSiFr11",
"article",
{
{"author", "Janet Feigenspan and Norbert Siegmund and Jana Fruth"},
{"title", "On the Role of Program Comprehension in Embedded Systems"},
{"journal", "Softwaretechnik-Trends"},
{"year", "2011"},
{"volume", "31"},
{"number", "2"},
{"month", "May"},
{"url",
"http://www.uni-koblenz-landau.de/koblenz/fb4/institute/uebergreifend/sre/conferences/wsr/wsr2011/wsr2011_proceedings.pdf"
}
}
}
};
auto const actual = sample.generate(input, "year"s, "someFile.bib"s);
ASSERT_EQ(actual, expected);
}
TEST_F(ParserFixtureTest, parseNonRuleCompliantContent) {
auto const input = R"(@article{FeigenspanSiFr11,
author = {Janet Feigenspan and Norbert Siegmund and Jana Fruth},
journal = {Softwaretechnik-Trends},
year = {2011},
volume = {31},
number = {2},
month = May,
url = {http://www.uni-koblenz-landau.de/koblenz/fb4/institute/uebergreifend/sre/conferences/wsr/wsr2011/wsr2011_proceedings.pdf}
})"sv;
auto const actual = sample.generate(input, "year"s, "someFile.bib"s);
ASSERT_EQ(actual, std::vector<BibElement>{});
}
TEST_F(ParserFixtureTest, parseDummyFile) {
boost::filesystem::path target = boost::filesystem::path("../../test/res/publications.bib");
ASSERT_NO_THROW([&]() {
const auto elements = sample.generate(std::vector<boost::filesystem::path>{target}, std::nullopt);
ASSERT_EQ(elements.size(), 1u);
}());
}
TEST_F(ParserFixtureTest, parseDummyFileInDirectoryAndAllowAllElements) {
boost::filesystem::path target = boost::filesystem::path("../../test/res");
ASSERT_NO_THROW(([&]() {
const auto elements = Parser{std::optional<boost::filesystem::path>(std::nullopt), {}, true}.generate(std::vector<
boost::filesystem::path>{target}, std::nullopt);
ASSERT_EQ(elements.size(), 62u);
}()));
}
TEST_F(ParserFixtureTest, parseDummyFileThatDoesNotExist) {
boost::filesystem::path target = boost::filesystem::path("../../test/res/someFileThatDoesNotExist.something");
ASSERT_ANY_THROW(
const auto elements = sample.generate(std::vector<boost::filesystem::path>{target}, std::nullopt);
);
}
TEST_F(ParserFixtureTest, sortingWorks) {
const auto file = R"(
@article{Feigenspan11,
author = {Janet Feigenspan},
title = {{Program Comprehension of Feature-Oriented Software Development}},
booktitle = {International Doctoral Symposium on Empirical Software Engineering (IDoESE)},
year = {2011},
month = Sep,
url = {http://wwwiti.cs.uni-magdeburg.de/iti_db/publikationen/ps/auto/Feigenspan11.pdf}
}
@article{FeigenspanSiFr11,
author = {Janet Feigenspan and Norbert Siegmund and Jana Fruth},
title = {{On the Role of Program Comprehension in Embedded Systems}},
journal = {Softwaretechnik-Trends},
year = {2011},
volume = {31},
number = {2},
month = May,
url = {http://www.uni-koblenz-landau.de/koblenz/fb4/institute/uebergreifend/sre/conferences/wsr/wsr2011/wsr2011_proceedings.pdf}
})"sv;
std::vector<BibElement> expected{
{"FeigenspanSiFr11", "article", {
{"author", "Janet Feigenspan and Norbert Siegmund and Jana Fruth"},
{"title", "On the Role of Program Comprehension in Embedded Systems"},
{"journal", "Softwaretechnik-Trends"},
{"year", "2011"},
{"volume", "31"},
{"number", "2"},
{"month", "May"},
{"url",
"http://www.uni-koblenz-landau.de/koblenz/fb4/institute/uebergreifend/sre/conferences/wsr/wsr2011/wsr2011_proceedings.pdf"}
}},
{"Feigenspan11", "article", {
{"author", "Janet Feigenspan"},
{"title", "Program Comprehension of Feature-Oriented Software Development"},
{"booktitle", "International Doctoral Symposium on Empirical Software Engineering (IDoESE)"},
{"year", "2011"},
{"month", "Sep"},
{"url", "http://wwwiti.cs.uni-magdeburg.de/iti_db/publikationen/ps/auto/Feigenspan11.pdf"}
}}};
ASSERT_EQ(sample.generate(file, "title", "testfile.bib"), expected);
}
ParserFixtureTest
Definition: ParserFixtureTest.cpp:16
Parser::generate
auto generate(const std::vector< boost::filesystem::path > &inputPaths, const std::optional< std::string > &sorting) const -> std::vector< BibElement >
Definition: Parser.cpp:164
Parser
interface to interact with bib-files
Definition: Parser.hpp:18
TEST_F
TEST_F(BibElementFixtureTest, completeElementTest)
Definition: BibElementFixtureTest.cpp:34
Parser.hpp
BibElement.hpp