summaryrefslogtreecommitdiff
path: root/test/gtest/stringify.cpp
diff options
context:
space:
mode:
authorAshley Nelson <nashley@google.com>2023-09-25 13:38:32 -0700
committerGitHub <noreply@github.com>2023-09-25 13:38:32 -0700
commit87bcf76c33356d3603e0e2721d54f6e450762627 (patch)
treeedaf852f9746a9a8c2c6eb0bef65032238244395 /test/gtest/stringify.cpp
parent4f1295a96d175f39257a750e06a426e5beb3933a (diff)
downloadbinaryen-87bcf76c33356d3603e0e2721d54f6e450762627.tar.gz
binaryen-87bcf76c33356d3603e0e2721d54f6e450762627.tar.bz2
binaryen-87bcf76c33356d3603e0e2721d54f6e450762627.zip
Outlining Test Improvements (#5971)
Abstracts repeat code
Diffstat (limited to 'test/gtest/stringify.cpp')
-rw-r--r--test/gtest/stringify.cpp34
1 files changed, 21 insertions, 13 deletions
diff --git a/test/gtest/stringify.cpp b/test/gtest/stringify.cpp
index 42f4e128f..fac745be9 100644
--- a/test/gtest/stringify.cpp
+++ b/test/gtest/stringify.cpp
@@ -161,14 +161,18 @@ static auto dupModuleText = R"wasm(
)
)wasm";
+std::vector<uint32_t> hashStringifyModule(Module* wasm) {
+ HashStringifyWalker stringify = HashStringifyWalker();
+ stringify.walkModule(wasm);
+ return std::move(stringify.hashString);
+}
+
TEST_F(StringifyTest, Stringify) {
Module wasm;
parseWast(wasm, dupModuleText);
+ auto hashString = hashStringifyModule(&wasm);
- HashStringifyWalker stringify = HashStringifyWalker();
- stringify.walkModule(&wasm);
-
- EXPECT_EQ(stringify.hashString,
+ EXPECT_EQ(hashString,
(std::vector<uint32_t>{
0, // function block evaluated as a whole
(uint32_t)-1, // separate function block from function contents
@@ -218,15 +222,11 @@ TEST_F(StringifyTest, Stringify) {
}));
}
-TEST_F(StringifyTest, Substrings) {
- Module wasm;
- parseWast(wasm, dupModuleText);
-
- HashStringifyWalker stringify = HashStringifyWalker();
- stringify.walkModule(&wasm);
-
- SuffixTree st(stringify.hashString);
- std::vector<SuffixTree::RepeatedSubstring> substrings(st.begin(), st.end());
+std::vector<SuffixTree::RepeatedSubstring>
+repeatSubstrings(std::vector<uint32_t> hashString) {
+ SuffixTree st(hashString);
+ std::vector<SuffixTree::RepeatedSubstring> substrings =
+ std::vector(st.begin(), st.end());
std::sort(
substrings.begin(),
substrings.end(),
@@ -238,6 +238,14 @@ TEST_F(StringifyTest, Substrings) {
}
return aWeight > bWeight;
});
+ return substrings;
+}
+
+TEST_F(StringifyTest, Substrings) {
+ Module wasm;
+ parseWast(wasm, dupModuleText);
+ auto hashString = hashStringifyModule(&wasm);
+ auto substrings = repeatSubstrings(hashString);
EXPECT_EQ(
substrings,