Skip to content

Commit

Permalink
Merge pull request #1653 from Expensify/tyler-different-test-serializ…
Browse files Browse the repository at this point in the history
…ation

Simplify PrintEquality
  • Loading branch information
flodnv authored Feb 22, 2024
2 parents 4e8d6e5 + 696e630 commit 86f4b43
Showing 1 changed file with 27 additions and 44 deletions.
71 changes: 27 additions & 44 deletions test/lib/PrintEquality.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,55 +2,38 @@

#include <iostream>
#include <string>
#include <cxxabi.h>
#include <set>
#include <map>
#include <list>

using namespace std;

class PrintEquality {
public:
template <typename T, enable_if_t<is_integral<T>::value, bool> = true, typename U>
PrintEquality(T a, U b, bool isEqual)
{
// Integral case.
if (!isEqual) {
cout << "(Integral): " << a << " != " << b << "\n";
} else {
cout << "(Integral): " << a << " == " << b << "\n";
}
}

template <typename T, enable_if_t<!is_integral<T>::value, bool> = true, typename U>
PrintEquality(T a, U b, bool isEqual)
{
// Non-integral base case.
char buffer[1000];
size_t length = 1000;
int status;
abi::__cxa_demangle(typeid(a).name(), buffer, &length, &status);
template<typename T>
ostream& operator<<(ostream& output, const list<T>& val)
{
return output << "[" << SComposeList(val) << "]";
}

if (!isEqual) {
cout << "Not equal (unhandled type: " << buffer << ")" << "\n";
} else {
cout << "equal (unhandled type: " << buffer << ")" << "\n";
}
}
template<typename T>
ostream& operator<<(ostream& output, const set<T>& val)
{
return output << "[" << SComposeList(val) << "]";
}

template <typename U>
PrintEquality(string a, U b, bool isEqual)
{
if (!isEqual) {
cout << "(string): \"" << a << "\" != \"" << b << "\"" << "\n";
} else {
cout << "(string): \"" << a << "\" == \"" << b << "\"" << "\n";
}
}
template<typename T, typename U>
ostream& operator<<(ostream& output, const map<T, U>& val)
{
output << "[Map] {" << endl;
for (const auto& [k, v] : val) {
output << k << ": " << v << endl;
}
return output << "}";
}

template <typename U>
PrintEquality(const char* a, U b, bool isEqual) {
if (!isEqual) {
cout << "(const char*): \"" << a << "\" != \"" << b << "\"" << "\n";
} else {
cout << "(const char*): \"" << a << "\" == \"" << b << "\"" << "\n";
}
class PrintEquality {
public:
template <typename U, typename V>
PrintEquality(const U& a, const V& b, bool isEqual) {
cout << a << " " << (isEqual ? "=" : "!") << "= " << b << "\n";
}
};

0 comments on commit 86f4b43

Please sign in to comment.