btool
A parser/converter/transpiler for .bib files
ParserFixtureTest.cpp
Go to the documentation of this file.
1 #include <gtest/gtest.h>
2 #include <Parser.hpp>
3 #include <BibElement.hpp>
4 #include <spdlog/spdlog.h>
5 #include <string>
6 #include <string_view>
7 
8 using namespace std::literals::string_literals;
9 using namespace std::literals::string_view_literals;
10 
16 struct ParserFixtureTest : public ::testing::Test {
18 
19  ParserFixtureTest() : sample{
20  // language=json
21  std::stringstream{R"(
22  {
23  "sortableFields": [],
24  "styles": [
25  {
26  "name": "article",
27  "requiredFields": [
28  "author",
29  "title"
30  ],
31  "optionalFields": [
32  "journal",
33  "year",
34  "volume",
35  "number",
36  "month",
37  "url",
38  "booktitle"
39  ]
40  },
41  {
42  "name": "book",
43  "requiredFields": [
44  "author",
45  "title",
46  "year",
47  "publisher"
48  ],
49  "optionalFields": [
50  "volume",
51  "series",
52  "address",
53  "edition",
54  "month",
55  "note",
56  "isbn"
57  ]
58  }
59  ]
60  })"}, {"article"}} {};
61 };
62 
63 TEST_F(ParserFixtureTest, parseEmptyFileContents) {
64  ASSERT_EQ(sample.generate(""sv, "year"s, "someFile.bib"s), std::vector<BibElement>());
65 }
66 
67 TEST_F(ParserFixtureTest, parseCorrectContent) {
68  auto const input = R"(@article{FeigenspanSiFr11,
69  author = {Janet Feigenspan and Norbert Siegmund and Jana Fruth},
70  title = {{On the Role of Program Comprehension in Embedded Systems}},
71  journal = {Softwaretechnik-Trends},
72  year = {2011},
73  volume = {31},
74  number = {2},
75  month = May,
76  url = {http://www.uni-koblenz-landau.de/koblenz/fb4/institute/uebergreifend/sre/conferences/wsr/wsr2011/wsr2011_proceedings.pdf}
77 })"sv;
78 
79  const std::vector<BibElement> expected{
80  {
81  "FeigenspanSiFr11",
82  "article",
83  {
84  {"author", "Janet Feigenspan and Norbert Siegmund and Jana Fruth"},
85  {"title", "On the Role of Program Comprehension in Embedded Systems"},
86  {"journal", "Softwaretechnik-Trends"},
87  {"year", "2011"},
88  {"volume", "31"},
89  {"number", "2"},
90  {"month", "May"},
91  {"url",
92  "http://www.uni-koblenz-landau.de/koblenz/fb4/institute/uebergreifend/sre/conferences/wsr/wsr2011/wsr2011_proceedings.pdf"
93  }
94  }
95  }
96  };
97  auto const actual = sample.generate(input, "year"s, "someFile.bib"s);
98  ASSERT_EQ(actual, expected);
99 }
100 
101 TEST_F(ParserFixtureTest, parseNonRuleCompliantContent) {
102  auto const input = R"(@article{FeigenspanSiFr11,
103  author = {Janet Feigenspan and Norbert Siegmund and Jana Fruth},
104  journal = {Softwaretechnik-Trends},
105  year = {2011},
106  volume = {31},
107  number = {2},
108  month = May,
109  url = {http://www.uni-koblenz-landau.de/koblenz/fb4/institute/uebergreifend/sre/conferences/wsr/wsr2011/wsr2011_proceedings.pdf}
110 })"sv;
111 
112  auto const actual = sample.generate(input, "year"s, "someFile.bib"s);
113  ASSERT_EQ(actual, std::vector<BibElement>{});
114 }
115 
116 TEST_F(ParserFixtureTest, parseDummyFile) {
117  boost::filesystem::path target = boost::filesystem::path("../../test/res/publications.bib");
118  ASSERT_NO_THROW([&]() {
119  const auto elements = sample.generate(std::vector<boost::filesystem::path>{target}, std::nullopt);
120  ASSERT_EQ(elements.size(), 1u);
121  }());
122 }
123 
124 TEST_F(ParserFixtureTest, parseDummyFileInDirectoryAndAllowAllElements) {
125  boost::filesystem::path target = boost::filesystem::path("../../test/res");
126  ASSERT_NO_THROW(([&]() {
127  const auto elements = Parser{std::optional<boost::filesystem::path>(std::nullopt), {}, true}.generate(std::vector<
128  boost::filesystem::path>{target}, std::nullopt);
129  ASSERT_EQ(elements.size(), 62u);
130  }()));
131 }
132 
133 TEST_F(ParserFixtureTest, parseDummyFileThatDoesNotExist) {
134  boost::filesystem::path target = boost::filesystem::path("../../test/res/someFileThatDoesNotExist.something");
135  ASSERT_ANY_THROW(
136  const auto elements = sample.generate(std::vector<boost::filesystem::path>{target}, std::nullopt);
137  );
138 }
139 
140 TEST_F(ParserFixtureTest, sortingWorks) {
141  const auto file = R"(
142 @article{Feigenspan11,
143  author = {Janet Feigenspan},
144  title = {{Program Comprehension of Feature-Oriented Software Development}},
145  booktitle = {International Doctoral Symposium on Empirical Software Engineering (IDoESE)},
146  year = {2011},
147  month = Sep,
148  url = {http://wwwiti.cs.uni-magdeburg.de/iti_db/publikationen/ps/auto/Feigenspan11.pdf}
149 }
150 @article{FeigenspanSiFr11,
151  author = {Janet Feigenspan and Norbert Siegmund and Jana Fruth},
152  title = {{On the Role of Program Comprehension in Embedded Systems}},
153  journal = {Softwaretechnik-Trends},
154  year = {2011},
155  volume = {31},
156  number = {2},
157  month = May,
158  url = {http://www.uni-koblenz-landau.de/koblenz/fb4/institute/uebergreifend/sre/conferences/wsr/wsr2011/wsr2011_proceedings.pdf}
159 })"sv;
160 
161  std::vector<BibElement> expected{
162  {"FeigenspanSiFr11", "article", {
163  {"author", "Janet Feigenspan and Norbert Siegmund and Jana Fruth"},
164  {"title", "On the Role of Program Comprehension in Embedded Systems"},
165  {"journal", "Softwaretechnik-Trends"},
166  {"year", "2011"},
167  {"volume", "31"},
168  {"number", "2"},
169  {"month", "May"},
170  {"url",
171  "http://www.uni-koblenz-landau.de/koblenz/fb4/institute/uebergreifend/sre/conferences/wsr/wsr2011/wsr2011_proceedings.pdf"}
172  }},
173  {"Feigenspan11", "article", {
174  {"author", "Janet Feigenspan"},
175  {"title", "Program Comprehension of Feature-Oriented Software Development"},
176  {"booktitle", "International Doctoral Symposium on Empirical Software Engineering (IDoESE)"},
177  {"year", "2011"},
178  {"month", "Sep"},
179  {"url", "http://wwwiti.cs.uni-magdeburg.de/iti_db/publikationen/ps/auto/Feigenspan11.pdf"}
180  }}};
181 
182  ASSERT_EQ(sample.generate(file, "title", "testfile.bib"), expected);
183 }
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
ParserFixtureTest::sample
Parser sample
Definition: ParserFixtureTest.cpp:17
ParserFixtureTest::ParserFixtureTest
ParserFixtureTest()
Definition: ParserFixtureTest.cpp:19
Parser
interface to interact with bib-files
Definition: Parser.hpp:18
TEST_F
TEST_F(ParserFixtureTest, parseEmptyFileContents)
Definition: ParserFixtureTest.cpp:63
Parser.hpp
BibElement.hpp