mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-02 04:04:19 +00:00
Add compare operator to code generated for c++ (#4940)
* Add operator== for c++ genated code New "--gen-compare" option for flatc to generate compare operators. The operators are defined based on object based api types. Inspired by issue #263. * Improve compare operator for c++. Thanks for the code review. - Improve robustness against future schema extensions - Code style - Fix --rust generation in generate_code.sh
This commit is contained in:
committed by
Wouter van Oortmerssen
parent
873a60b0d8
commit
33791dc7b0
@@ -1978,6 +1978,25 @@ void UninitializedVectorTest() {
|
||||
TEST_EQ(test_1->b(), 40);
|
||||
}
|
||||
|
||||
void EqualOperatorTest() {
|
||||
MonsterT a;
|
||||
MonsterT b;
|
||||
TEST_EQ(b == a, true);
|
||||
|
||||
b.mana = 33;
|
||||
TEST_EQ(b == a, false);
|
||||
b.mana = 150;
|
||||
TEST_EQ(b == a, true);
|
||||
|
||||
b.inventory.push_back(3);
|
||||
TEST_EQ(b == a, false);
|
||||
b.inventory.clear();
|
||||
TEST_EQ(b == a, true);
|
||||
|
||||
b.test.type = Any_Monster;
|
||||
TEST_EQ(b == a, false);
|
||||
}
|
||||
|
||||
// For testing any binaries, e.g. from fuzzing.
|
||||
void LoadVerifyBinaryTest() {
|
||||
std::string binary;
|
||||
@@ -2062,6 +2081,7 @@ int main(int /*argc*/, const char * /*argv*/ []) {
|
||||
|
||||
FlexBuffersTest();
|
||||
UninitializedVectorTest();
|
||||
EqualOperatorTest();
|
||||
|
||||
if (!testing_fails) {
|
||||
TEST_OUTPUT_LINE("ALL TESTS PASSED");
|
||||
|
||||
Reference in New Issue
Block a user