begin support of actual serialization
diff --git a/CMakeLists.txt b/CMakeLists.txt
index ca1b86f..7270899 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -269,7 +269,7 @@
list(REMOVE_AT ARGV 0)
add_executable(${name} ${ARGV})
add_dependencies(everything ${name})
- target_link_libraries(${name} libwabt)
+ target_link_libraries(${name} libwabt libjsoncpp)
set_property(TARGET ${name} PROPERTY CXX_STANDARD 11)
set_property(TARGET ${name} PROPERTY CXX_STANDARD_REQUIRED ON)
list(APPEND WABT_EXECUTABLES ${name})
@@ -353,7 +353,7 @@
third_party/gtest/googletest/src/gtest_main.cc
)
wabt_executable(wabt-unittests ${UNITTESTS_SRCS})
- target_link_libraries(wabt-unittests libgtest ${CMAKE_THREAD_LIBS_INIT})
+ target_link_libraries(wabt-unittests libgtest libjsoncpp ${CMAKE_THREAD_LIBS_INIT})
endif ()
# test running
diff --git a/src/source-maps.cc b/src/source-maps.cc
index 84f5cb9..435dea3 100644
--- a/src/source-maps.cc
+++ b/src/source-maps.cc
@@ -19,6 +19,8 @@
#include <cassert>
#include <iostream>
+#include "json/json.h"
+
#define INDEX_NONE static_cast<size_t>(-1)
#define INVALID() \
@@ -158,8 +160,17 @@
std::vector<std::string> mapping_results;
mapping_results.reserve(mappings.size());
CompressMappings();
- // TODO: serialize the mappings.
- return "";
+ Json::Value output;
+ output["version"] = SourceMap::kSourceMapVersion;
+ output["file"] = map.file;
+ output["sourceRoot"] = map.source_root;
+ Json::Value sources(Json::arrayValue);
+ for (const auto& source : map.sources) {
+ sources.append(source);
+ }
+ output["sources"] = sources;
+ std::cout << output;
+ return output.toStyledString();
}
void SourceMapGenerator::DumpRawMappings() {
diff --git a/src/source-maps.h b/src/source-maps.h
index 5af89db..849cc73 100644
--- a/src/source-maps.h
+++ b/src/source-maps.h
@@ -92,7 +92,7 @@
CompressMappings();
return map;
};
-
+ std::string SerializeMappings();
public:
// TODO: make this private? But need to find a way to use it in tests.
struct SourceMapping {
@@ -108,7 +108,6 @@
private:
void CompressMappings();
- std::string SerializeMappings();
bool map_prepared = false; // Is the map compressed and ready for export?
SourceMap map;
std::map<std::string, size_t> sources_map;
diff --git a/src/test-source-maps.cc b/src/test-source-maps.cc
index 7816577..5b6dcfb 100644
--- a/src/test-source-maps.cc
+++ b/src/test-source-maps.cc
@@ -215,3 +215,18 @@
s = {{1, 1}, {true, 0}, {8, 0}, {0, 0}, {false, 0}};
EXPECT_SEGMENT_EQ(s, map.segment_groups.back().segments.back());
}
+
+#define EXPECT_JSON_CONTAINS_STR(output, key, value) \
+ EXPECT_TRUE(output.find(std::string("\"") + key + "\" : \"" + value + "\"") != std::string::npos)
+#define EXPECT_JSON_CONTAINS_NUM(output, key, value) \
+ EXPECT_TRUE(output.find(std::string("\"") + key + "\" : " + value) != std::string::npos)
+
+
+TEST(source_maps, serialization_empty) {
+ SourceMapGenerator smg("source.out", "source-root");
+ std::string output = smg.SerializeMappings();
+ EXPECT_JSON_CONTAINS_NUM(output, "version", "3");
+ EXPECT_JSON_CONTAINS_STR(output, "file", "source.out");
+ EXPECT_JSON_CONTAINS_STR(output, "sourceRoot", "source-root");
+ EXPECT_JSON_CONTAINS_NUM(output, "sources", "[]"); // TODO: fix this abuse of NUM
+}