diff options
Diffstat (limited to 'test/example/hash.cpp')
-rw-r--r-- | test/example/hash.cpp | 33 |
1 files changed, 31 insertions, 2 deletions
diff --git a/test/example/hash.cpp b/test/example/hash.cpp index ba9ca24ea..944cef14c 100644 --- a/test/example/hash.cpp +++ b/test/example/hash.cpp @@ -11,6 +11,14 @@ using namespace wasm; #define assertNotEqual(left, right) \ assert(ExpressionAnalyzer::hash(&left) != ExpressionAnalyzer::hash(&right)); +#define assertShallowEqual(left, right) \ + assert(ExpressionAnalyzer::shallowHash(&left) == \ + ExpressionAnalyzer::shallowHash(&right)); + +#define assertShallowNotEqual(left, right) \ + assert(ExpressionAnalyzer::shallowHash(&left) != \ + ExpressionAnalyzer::shallowHash(&right)); + int main() { { Const x, y; @@ -33,7 +41,7 @@ int main() { assertNotEqual(x, y); } { - // Nested child. + // Nested identical child. Drop dx, dy; Const x, y; x.set(Literal(int32_t(10))); @@ -43,7 +51,17 @@ int main() { assertEqual(dx, dy); } { - // Nested child. + // Nested identical child, checked shallowly. + Drop dx, dy; + Const x, y; + x.set(Literal(int32_t(10))); + y.set(Literal(int32_t(10))); + dx.value = &x; + dy.value = &y; + assertShallowEqual(dx, dy); + } + { + // Nested different child. Drop dx, dy; Const x, y; x.set(Literal(int32_t(10))); @@ -52,6 +70,17 @@ int main() { dy.value = &y; assertNotEqual(dx, dy); } + { + // Nested different child, checked shallowly (so we ignore the difference, + // and return equal). + Drop dx, dy; + Const x, y; + x.set(Literal(int32_t(10))); + y.set(Literal(int32_t(11))); + dx.value = &x; + dy.value = &y; + assertShallowEqual(dx, dy); + } MixedArena arena; { // Blocks |