-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cover sort, format, and the PackageCache modules. Some of this overlaps with our integration tests, but it's nice to have coverage at multiple levels and the tests are fast enough.
- Loading branch information
1 parent
5d4a162
commit 5e7bcad
Showing
8 changed files
with
460 additions
and
45 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
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
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,100 @@ | ||
#include "format.hh" | ||
|
||
#include <iostream> | ||
#include <sstream> | ||
|
||
#include "aur/package.hh" | ||
#include "gtest/gtest.h" | ||
|
||
class ScopedCapturer { | ||
public: | ||
ScopedCapturer(std::ostream& stream) : stream_(stream) { | ||
stream_.rdbuf(buffer_.rdbuf()); | ||
} | ||
|
||
~ScopedCapturer() { stream_.rdbuf(original_sbuf_); } | ||
|
||
std::string GetCapturedOutput() { | ||
auto str = buffer_.str(); | ||
buffer_.str(std::string()); | ||
return str; | ||
} | ||
|
||
private: | ||
std::stringstream buffer_; | ||
std::streambuf* original_sbuf_ = std::cout.rdbuf(); | ||
std::ostream& stream_; | ||
}; | ||
|
||
aur::Package MakePackage() { | ||
aur::Package p; | ||
|
||
// string | ||
p.name = "cower"; | ||
p.version = "1.2.3"; | ||
|
||
// floating point | ||
p.popularity = 5.20238; | ||
|
||
// datetime | ||
p.submitted_s = std::chrono::seconds(1499013608); | ||
|
||
// lists | ||
p.conflicts = { | ||
"auracle", | ||
"cower", | ||
"cower-git", | ||
}; | ||
|
||
return p; | ||
} | ||
|
||
TEST(FormatTest, DetectsInvalidFormats) { | ||
std::string err; | ||
EXPECT_FALSE(format::FormatIsValid("{invalid}", &err)); | ||
EXPECT_FALSE(err.empty()); | ||
} | ||
|
||
TEST(FormatTest, CustomStringFormat) { | ||
ScopedCapturer capture(std::cout); | ||
|
||
format::Custom("{name} -> {version}", MakePackage()); | ||
|
||
EXPECT_EQ(capture.GetCapturedOutput(), "cower -> 1.2.3\n"); | ||
} | ||
|
||
TEST(FormatTest, CustomFloatFormat) { | ||
ScopedCapturer capture(std::cout); | ||
|
||
auto p = MakePackage(); | ||
|
||
format::Custom("{popularity}", p); | ||
EXPECT_EQ(capture.GetCapturedOutput(), "5.20238\n"); | ||
|
||
format::Custom("{popularity:.2f}", p); | ||
EXPECT_EQ(capture.GetCapturedOutput(), "5.20\n"); | ||
} | ||
|
||
TEST(FormatTest, CustomDateTimeFormat) { | ||
ScopedCapturer capture(std::cout); | ||
|
||
auto p = MakePackage(); | ||
|
||
format::Custom("{submitted}", p); | ||
EXPECT_EQ(capture.GetCapturedOutput(), "Sun Jul 2 16:40:08 2017\n"); | ||
|
||
format::Custom("{submitted:%s}", p); | ||
EXPECT_EQ(capture.GetCapturedOutput(), "1499013608\n"); | ||
} | ||
|
||
TEST(FormatTest, ListFormat) { | ||
ScopedCapturer capture(std::cout); | ||
|
||
auto p = MakePackage(); | ||
|
||
format::Custom("{conflicts}", p); | ||
EXPECT_EQ(capture.GetCapturedOutput(), "auracle cower cower-git\n"); | ||
|
||
format::Custom("{conflicts::,,}", p); | ||
EXPECT_EQ(capture.GetCapturedOutput(), "auracle:,,cower:,,cower-git\n"); | ||
} |
Oops, something went wrong.
5e7bcad
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Build ends with "call of overloaded 'Package(const nlohmann::basic_json<>&)' is ambiguous"
buildlog.txt