Remove googletest (#178)
This commit is contained in:
@@ -45,147 +45,149 @@ namespace clice::testing {
|
||||
|
||||
namespace {
|
||||
|
||||
TEST(JSON, String) {
|
||||
json::Value expect = "hello";
|
||||
suite<"JSON"> json_tests = [] {
|
||||
test("String") = [&] {
|
||||
json::Value expected = "hello";
|
||||
|
||||
std::string input = "hello";
|
||||
EXPECT_EQ(json::serialize(input), expect);
|
||||
EXPECT_EQ(json::deserialize<std::string>(expect), input);
|
||||
std::string input = "hello";
|
||||
expect(json::serialize(input) == expected);
|
||||
expect(json::deserialize<std::string>(expected) == input);
|
||||
|
||||
std::string_view input2 = "hello";
|
||||
EXPECT_EQ(json::serialize(input2), expect);
|
||||
EXPECT_EQ(json::deserialize<std::string_view>(expect), input2);
|
||||
std::string_view input2 = "hello";
|
||||
expect(json::serialize(input2) == expected);
|
||||
expect(json::deserialize<std::string_view>(expected) == input2);
|
||||
|
||||
llvm::StringRef input3 = "hello";
|
||||
EXPECT_EQ(json::serialize(input3), expect);
|
||||
EXPECT_EQ(json::deserialize<llvm::StringRef>(expect), input3);
|
||||
llvm::StringRef input3 = "hello";
|
||||
expect(json::serialize(input3) == expected);
|
||||
expect(json::deserialize<llvm::StringRef>(expected) == input3);
|
||||
|
||||
llvm::SmallString<5> input4 = {"hello"};
|
||||
EXPECT_EQ(json::serialize(input4), expect);
|
||||
EXPECT_EQ(json::deserialize<llvm::SmallString<5>>(expect), input4);
|
||||
}
|
||||
|
||||
TEST(JSON, MapRange) {
|
||||
json::Value expect = json::Object{
|
||||
{"1", 2},
|
||||
{"3", 4},
|
||||
{"5", 6}
|
||||
llvm::SmallString<5> input4 = {"hello"};
|
||||
expect(json::serialize(input4) == expected);
|
||||
expect(json::deserialize<llvm::SmallString<5>>(expected) == input4);
|
||||
};
|
||||
|
||||
std::map<int, int> input = {
|
||||
{1, 2},
|
||||
{3, 4},
|
||||
{5, 6}
|
||||
};
|
||||
|
||||
EXPECT_EQ(json::serialize(input), expect);
|
||||
EXPECT_EQ(input, json::deserialize<decltype(input)>(expect));
|
||||
|
||||
std::unordered_map<int, int> input2 = {
|
||||
{1, 2},
|
||||
{3, 4},
|
||||
{5, 6}
|
||||
};
|
||||
EXPECT_EQ(json::serialize(input2), expect);
|
||||
EXPECT_EQ(input2, json::deserialize<decltype(input2)>(expect));
|
||||
|
||||
llvm::DenseMap<int, int> input4 = {
|
||||
{1, 2},
|
||||
{3, 4},
|
||||
{5, 6}
|
||||
};
|
||||
EXPECT_EQ(json::serialize(input4), expect);
|
||||
EXPECT_EQ(input4, json::deserialize<decltype(input4)>(expect));
|
||||
}
|
||||
|
||||
TEST(JSON, SetRange) {
|
||||
json::Value expect = {1, 2, 3, 4, 5};
|
||||
|
||||
std::set<int> input = {1, 2, 3, 4, 5};
|
||||
EXPECT_EQ(input, json::deserialize<decltype(input)>(expect));
|
||||
|
||||
std::unordered_set<int> input2 = {1, 2, 3, 4, 5};
|
||||
EXPECT_EQ(input2, json::deserialize<decltype(input2)>(expect));
|
||||
}
|
||||
|
||||
TEST(JSON, SequenceRange) {
|
||||
json::Value expect = {1, 2, 3, 4, 5};
|
||||
|
||||
std::vector<int> input = {1, 2, 3, 4, 5};
|
||||
EXPECT_EQ(json::serialize(input), expect);
|
||||
EXPECT_EQ(json::deserialize<std::vector<int>>(expect), input);
|
||||
|
||||
llvm::ArrayRef<int> input2 = input;
|
||||
EXPECT_EQ(json::serialize(input2), expect);
|
||||
|
||||
llvm::SmallVector<int, 5> input3 = {1, 2, 3, 4, 5};
|
||||
EXPECT_EQ(json::serialize(input3), expect);
|
||||
EXPECT_EQ((json::deserialize<llvm::SmallVector<int, 5>>(expect)), input3);
|
||||
}
|
||||
|
||||
TEST(JSON, Enum) {
|
||||
enum class E { A, B, C };
|
||||
|
||||
json::Value expect = json::Value(1);
|
||||
|
||||
E input = E::B;
|
||||
EXPECT_EQ(json::serialize(input), expect);
|
||||
EXPECT_EQ(json::deserialize<E>(expect), input);
|
||||
|
||||
struct Color : refl::Enum<Color, false, int> {
|
||||
enum Kind {
|
||||
Red = 0,
|
||||
Green,
|
||||
Blue,
|
||||
Yellow,
|
||||
test("MapRange") = [&] {
|
||||
json::Value expected = json::Object{
|
||||
{"1", 2},
|
||||
{"3", 4},
|
||||
{"5", 6}
|
||||
};
|
||||
|
||||
using Enum::Enum;
|
||||
std::map<int, int> input = {
|
||||
{1, 2},
|
||||
{3, 4},
|
||||
{5, 6}
|
||||
};
|
||||
|
||||
expect(json::serialize(input) == expected);
|
||||
expect(input == json::deserialize<decltype(input)>(expected));
|
||||
|
||||
std::unordered_map<int, int> input2 = {
|
||||
{1, 2},
|
||||
{3, 4},
|
||||
{5, 6}
|
||||
};
|
||||
expect(json::serialize(input2) == expected);
|
||||
expect(input2 == json::deserialize<decltype(input2)>(expected));
|
||||
|
||||
llvm::DenseMap<int, int> input4 = {
|
||||
{1, 2},
|
||||
{3, 4},
|
||||
{5, 6}
|
||||
};
|
||||
expect(json::serialize(input4) == expected);
|
||||
expect(input4 == json::deserialize<decltype(input4)>(expected));
|
||||
};
|
||||
|
||||
json::Value expect2 = json::Value(2);
|
||||
test("SetRange") = [&] {
|
||||
json::Value expected = {1, 2, 3, 4, 5};
|
||||
|
||||
Color input2 = Color::Blue;
|
||||
EXPECT_EQ(json::serialize(input2), expect2);
|
||||
EXPECT_EQ(json::deserialize<Color>(expect2), input2);
|
||||
}
|
||||
std::set<int> input = {1, 2, 3, 4, 5};
|
||||
expect(input == json::deserialize<decltype(input)>(expected));
|
||||
|
||||
TEST(JSON, Struct) {
|
||||
struct A {
|
||||
int x;
|
||||
int y;
|
||||
|
||||
bool operator== (const A& other) const = default;
|
||||
std::unordered_set<int> input2 = {1, 2, 3, 4, 5};
|
||||
expect(input2 == json::deserialize<decltype(input2)>(expected));
|
||||
};
|
||||
|
||||
json::Value expect = json::Object{
|
||||
{"x", 1},
|
||||
{"y", 2}
|
||||
test("SequenceRange") = [&] {
|
||||
json::Value expected = {1, 2, 3, 4, 5};
|
||||
|
||||
std::vector<int> input = {1, 2, 3, 4, 5};
|
||||
expect(json::serialize(input) == expected);
|
||||
expect(json::deserialize<std::vector<int>>(expected) == input);
|
||||
|
||||
llvm::ArrayRef<int> input2 = input;
|
||||
expect(json::serialize(input2) == expected);
|
||||
|
||||
llvm::SmallVector<int, 5> input3 = {1, 2, 3, 4, 5};
|
||||
expect(json::serialize(input3) == expected);
|
||||
expect((json::deserialize<llvm::SmallVector<int, 5>>(expected)) == input3);
|
||||
};
|
||||
|
||||
A input = {1, 2};
|
||||
EXPECT_EQ(json::serialize(input), expect);
|
||||
EXPECT_EQ(json::deserialize<A>(expect), input);
|
||||
test("Enum") = [&] {
|
||||
enum class E { A, B, C };
|
||||
|
||||
struct B {
|
||||
A a;
|
||||
std::string s;
|
||||
json::Value expected = json::Value(1);
|
||||
|
||||
bool operator== (const B& other) const = default;
|
||||
E input = E::B;
|
||||
expect(json::serialize(input) == expected);
|
||||
expect(json::deserialize<E>(expected) == input);
|
||||
|
||||
struct Color : refl::Enum<Color, false, int> {
|
||||
enum Kind {
|
||||
Red = 0,
|
||||
Green,
|
||||
Blue,
|
||||
Yellow,
|
||||
};
|
||||
|
||||
using Enum::Enum;
|
||||
};
|
||||
|
||||
json::Value expected2 = json::Value(2);
|
||||
|
||||
Color input2 = Color::Blue;
|
||||
expect(json::serialize(input2) == expected2);
|
||||
expect(json::deserialize<Color>(expected2) == input2);
|
||||
};
|
||||
|
||||
json::Value expect2 = json::Object{
|
||||
{"a", json::Object{{"x", 1}, {"y", 2}}},
|
||||
{"s", "hello" }
|
||||
};
|
||||
test("Struct") = [&] {
|
||||
struct A {
|
||||
int x;
|
||||
int y;
|
||||
|
||||
B input2 = {
|
||||
{1, 2},
|
||||
"hello",
|
||||
bool operator== (const A& other) const = default;
|
||||
};
|
||||
|
||||
json::Value expected = json::Object{
|
||||
{"x", 1},
|
||||
{"y", 2}
|
||||
};
|
||||
|
||||
A input = {1, 2};
|
||||
expect(json::serialize(input) == expected);
|
||||
expect(json::deserialize<A>(expected) == input);
|
||||
|
||||
struct B {
|
||||
A a;
|
||||
std::string s;
|
||||
|
||||
bool operator== (const B& other) const = default;
|
||||
};
|
||||
|
||||
json::Value expected2 = json::Object{
|
||||
{"a", json::Object{{"x", 1}, {"y", 2}}},
|
||||
{"s", "hello" }
|
||||
};
|
||||
|
||||
B input2 = {
|
||||
{1, 2},
|
||||
"hello",
|
||||
};
|
||||
expect(json::serialize(input2) == expected2);
|
||||
expect(json::deserialize<B>(expected2) == input2);
|
||||
};
|
||||
EXPECT_EQ(json::serialize(input2), expect2);
|
||||
EXPECT_EQ(json::deserialize<B>(expect2), input2);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
|
||||
Reference in New Issue
Block a user