diff options
author | Ömer Sinan Ağacan <omeragacan@gmail.com> | 2024-08-06 20:17:23 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-06 18:17:23 +0000 |
commit | a985e16832f86cbc42eb6488e6f9fc2a9eff7dc7 (patch) | |
tree | 0c81a3a861c44d6b838db07f6620fe7a1447afbd /test/gtest | |
parent | 1c3578c7e28d9fced48a756546c07a2acb26bdcc (diff) | |
download | binaryen-a985e16832f86cbc42eb6488e6f9fc2a9eff7dc7.tar.gz binaryen-a985e16832f86cbc42eb6488e6f9fc2a9eff7dc7.tar.bz2 binaryen-a985e16832f86cbc42eb6488e6f9fc2a9eff7dc7.zip |
[Source maps] Handle single-segment entries in source map header decoder (#6794)
Single-segment mappings were already handled in readNextDebugLocation,
but not in readSourceMapHeader.
Diffstat (limited to 'test/gtest')
-rw-r--r-- | test/gtest/CMakeLists.txt | 1 | ||||
-rw-r--r-- | test/gtest/binary-reader.cpp | 63 |
2 files changed, 64 insertions, 0 deletions
diff --git a/test/gtest/CMakeLists.txt b/test/gtest/CMakeLists.txt index e8eec3f1d..17e880a4e 100644 --- a/test/gtest/CMakeLists.txt +++ b/test/gtest/CMakeLists.txt @@ -2,6 +2,7 @@ include_directories(../../third_party/googletest/googletest/include) include_directories(../../src/wasm) set(unittest_SOURCES + binary-reader.cpp cfg.cpp dfa_minimization.cpp disjoint_sets.cpp diff --git a/test/gtest/binary-reader.cpp b/test/gtest/binary-reader.cpp new file mode 100644 index 000000000..b73fe55bd --- /dev/null +++ b/test/gtest/binary-reader.cpp @@ -0,0 +1,63 @@ +/* + * Copyright 2024 WebAssembly Community Group participants + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "parser/wat-parser.h" +#include "print-test.h" +#include "wasm-binary.h" +#include "gtest/gtest.h" + +using namespace wasm; + +using BinaryReaderTest = PrintTest; + +// Check that debug location parsers can handle single-segment mappings. +TEST_F(BinaryReaderTest, SourceMappingSingleSegment) { + auto moduleText = "(module)"; + Module module; + parseWast(module, moduleText); + + BufferWithRandomAccess buffer; + WasmBinaryWriter(&module, buffer, PassOptions()); + auto moduleBytes = buffer.getAsChars(); + + // A single-segment mapping starting at offset 0. + std::string sourceMap = R"( + { + "version": 3, + "sources": [], + "names": [], + "mappings": "A" + } + )"; + std::stringstream sourceMapStream(sourceMap); + + // Test `readSourceMapHeader` (only check for errors, as there is no mapping + // to print). + { + Module module; + WasmBinaryReader binaryReader(module, FeatureSet::All, moduleBytes); + binaryReader.setDebugLocations(&sourceMapStream); + binaryReader.readSourceMapHeader(); + } + + // Test `readNextDebugLocation`. + { + Module module; + WasmBinaryReader binaryReader(module, FeatureSet::All, moduleBytes); + binaryReader.setDebugLocations(&sourceMapStream); + binaryReader.readNextDebugLocation(); + } +} |