| 113 | // clang-format on |
| 114 | |
| 115 | inline void test_script_binary(const String &script_name, const Vector<uint8_t> &bytecode, const String &helper_script_text, int revision, bool helper_script, bool no_text_equality_check, bool compare_whitespace = false) { |
| 116 | auto decomp = GDScriptDecomp::create_decomp_for_commit(revision); |
| 117 | CHECK(decomp.is_valid()); |
| 118 | auto result = decomp->test_bytecode(bytecode, false); |
| 119 | CHECK(result == GDScriptDecomp::BYTECODE_TEST_PASS); |
| 120 | if (helper_script && decomp->get_parent() != 0) { |
| 121 | // Test our previously compiled bytecode against the parent |
| 122 | auto parent = GDScriptDecomp::create_decomp_for_commit(decomp->get_parent()); |
| 123 | CHECK(parent.is_valid()); |
| 124 | // Can't test be46be7, the only thing that changed in this commit is the name of the function |
| 125 | if (revision != 0xbe46be7) { |
| 126 | auto parent_result = parent->test_bytecode(bytecode, false); |
| 127 | CHECK(parent_result == GDScriptDecomp::BYTECODE_TEST_FAIL); |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | // test compiling the decompiled code |
| 132 | Error err = decomp->decompile_buffer(bytecode); |
| 133 | CHECK(err == OK); |
| 134 | CHECK(decomp->get_error_message() == ""); |
| 135 | // no whitespace |
| 136 | auto decompiled_string = decomp->get_script_text(); |
| 137 | auto helper_script_text_stripped = remove_comments(helper_script_text).replace("\"\"\"", "\"").replace("'", "\""); |
| 138 | if (!helper_script_text_stripped.strip_edges().is_empty()) { |
| 139 | CHECK(decompiled_string != ""); |
| 140 | } |
| 141 | |
| 142 | auto decompiled_string_stripped = remove_comments(decompiled_string).replace("\"\"\"", "\"").replace("'", "\""); |
| 143 | |
| 144 | #if DEBUG_ENABLED |
| 145 | if (!no_text_equality_check && gdre::remove_whitespace(decompiled_string_stripped) != gdre::remove_whitespace(helper_script_text_stripped)) { |
| 146 | TextDiff::print_diff(TextDiff::get_diff_with_header(script_name, script_name, decompiled_string_stripped, helper_script_text_stripped)); |
| 147 | output_diff(script_name, decompiled_string_stripped, helper_script_text_stripped); |
| 148 | } |
| 149 | #endif |
| 150 | if (!no_text_equality_check) { |
| 151 | CHECK_MESSAGE(gdre::remove_whitespace(decompiled_string_stripped) == gdre::remove_whitespace(helper_script_text_stripped), (String("No whitespace text diff failed: \n") + TextDiff::get_diff_with_header(script_name, script_name, decompiled_string_stripped, helper_script_text_stripped))); |
| 152 | } |
| 153 | if (compare_whitespace) { |
| 154 | if (decompiled_string_stripped != helper_script_text_stripped) { |
| 155 | TextDiff::print_diff(TextDiff::get_diff_with_header(script_name + "_original", script_name + "_decompiled", helper_script_text_stripped, decompiled_string_stripped)); |
| 156 | } |
| 157 | CHECK(decompiled_string_stripped == helper_script_text_stripped); |
| 158 | } |
| 159 | auto recompiled_bytecode = decomp->compile_code_string(decompiled_string); |
| 160 | CHECK(decomp->get_error_message() == ""); |
| 161 | CHECK(recompiled_bytecode.size() > 0); |
| 162 | auto recompiled_result = decomp->test_bytecode(recompiled_bytecode, false); |
| 163 | CHECK(recompiled_result == GDScriptDecomp::BYTECODE_TEST_PASS); |
| 164 | err = decomp->test_bytecode_match(bytecode, recompiled_bytecode); |
| 165 | #if DEBUG_ENABLED |
| 166 | if (err) { |
| 167 | TextDiff::print_diff(TextDiff::get_diff_with_header(script_name + "_original", script_name + "_decompiled", helper_script_text_stripped, decompiled_string_stripped)); |
| 168 | output_diff(script_name, decompiled_string_stripped, helper_script_text_stripped); |
| 169 | } |
| 170 | #endif |
| 171 | |
| 172 | if (revision == GDScriptDecompVersion::LATEST_GDSCRIPT_COMMIT) { |
no test coverage detected