1/* 2 * Copyright (c) 2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16#include <cstdio> 17 18#include "ecmascript/extractortool/src/source_map.h" 19#include "ecmascript/tests/test_helper.h" 20 21using namespace panda::ecmascript; 22const std::string sourceMapData = 23 "{\n" 24 " \"entry/src/main/ets/pages/Index.ts\": {\n" 25 " \"version\": 3,\n" 26 " \"file\": \"Index.ets\",\n" 27 " \"sources\": [\n" 28 " \"entry/src/main/ets/pages/Index.ets\"\n" 29 " ],\n" 30 " \"names\": [],\n" 31 " \"mappings\": \";MAEO,CAAK,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA," 32 "CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA," 33 "CAAA,CAAA,CAAA,CAAA,CAAA,CAAA;AAFZ,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA," 34 "CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA," 35 "CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA," 36 "CAAA,CAAA,CAAA,CAAA;;sDAG2B,CAAa,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA," 37 "CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA;;AAHxC,CAAA,CAAA,CAAA," 38 "CAAA,CAAA,CAAA;;;;;;;;;;;;;;;;QAGS,CAAO,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA;;;QAAP,CAAO," 39 "CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA;;;AAEd,CAAA," 40 "CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA;;;" 41 "YACE,CAAG,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA;YAAH,CAAG,CAAA,CAAA,CAQF,CAAM," 42 "CAAA,CAAA,CAAA,CAAA,CAAA,CAAC,CAAM,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA;;gBARd,CAAG,CAAA,CAAA,CAAA,CAAA," 43 "CAAA,CAAA,CAAA,CAAA,CAAA,CAAA;;;;;;YACD,CAAM,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA," 44 "CAAA,CAAA,CAAA,CAAA;YAAN,CAAM,CAAA,CAAA,CAAA,CAAA,CAAA,CAKL,CAAK,CAAA,CAAA,CAAA,CAAA,CAAC,CAAM,CAAA,CAAA," 45 "CAAA,CAAA,CAAA,CAAA,CAAA,CAAA;;gBALb,CAAM,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA;" 46 ";;;;;YACJ,CAAI,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAC,CAAI,CAAA,CAAA,CAAA,CAAC,CAAO,CAAA," 47 "CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA;YAAjB,CAAI,CAAA,CAAA,CAAA,CACD,CAAQ,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA," 48 "CAAA,CAAC,CAAE,CAAA,CAAA,CAAA,CAAA;AADd,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA," 49 "CAAA,CAAA,CAAI,CAED,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAU,CAAC,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA," 50 "CAAA,CAAA,CAAA,CAAU,CAAC,CAAI,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA;;gBAF7B,CAAI,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA," 51 "CAAA,CAAA,CAAA,CAAA;;;;QAAJ,CAAI,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA;QADN,CAAM,CAAA,CAAA," 52 "CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA;QADR,CAAG,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA," 53 "CAAA;AASJ,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA;;;;;;;;\"\n" 54 " }\n" 55 "}"; 56const std::string sourceMapDataWithoutSources = 57 "{\n" 58 " \"entry/src/main/ets/pages/Index.ts\": {\n" 59 " \"version\": 3,\n" 60 " \"file\": \"Index.ets\",\n" 61 " \"sources\": [],\n" 62 " \"names\": [],\n" 63 " \"mappings\": \";MAEO,CAAK,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA," 64 "CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA;\"\n" 65 " }\n" 66 "}"; 67const std::string sourceMapDataWithShortMappings = 68 "{\n" 69 " \"entry/src/main/ets/pages/Index.ts\": {\n" 70 " \"version\": 3,\n" 71 " \"file\": \"Index.ets\",\n" 72 " \"sources\": [\n" 73 " \"entry/src/main/ets/pages/Index.ets\"\n" 74 " ],\n" 75 " \"names\": [],\n" 76 " \"mappings\": \"\n" 77 " }\n" 78 "}"; 79const std::string sourceMapDataWithInvalidMappings1 = 80 "{\n" 81 " \"entry/src/main/ets/pages/Index.ts\": {\n" 82 " \"version\": 3,\n" 83 " \"file\": \"Index.ets\",\n" 84 " \"sources\": [\n" 85 " \"entry/src/main/ets/pages/Index.ets\"\n" 86 " ],\n" 87 " \"names\": [],\n" 88 " \"mappings\": pA;\n" 89 " }\n" 90 "}"; 91const std::string sourceMapDataWithInvalidMappings2 = 92 "{\n" 93 " \"entry/src/main/ets/pages/Index.ts\": {\n" 94 " \"version\": 3,\n" 95 " \"file\": \"Index.ets\",\n" 96 " \"sources\": [\n" 97 " \"entry/src/main/ets/pages/Index.ets\"\n" 98 " ],\n" 99 " \"names\": [],\n" 100 " \"mappings\": pAq;ABCD;abcd;0123;0+/-;\n" 101 " }\n" 102 "}"; 103const std::string sourceMapDataWithInvalidMappings3 = 104 "{\n" 105 " \"entry/src/main/ets/pages/Index.ts\": {\n" 106 " \"version\": 3,\n" 107 " \"file\": \"Index.ets\",\n" 108 " \"sources\": [\n" 109 " \"entry/src/main/ets/pages/Index.ets\"\n" 110 " ],\n" 111 " \"names\": [],\n" 112 " \"mappings\": X;\n" 113 " }\n" 114 "}"; 115const std::string sourceMapDataWithInvalidMappings4 = 116 "{\n" 117 " \"entry/src/main/ets/pages/Index.ts\": {\n" 118 " \"version\": 3,\n" 119 " \"file\": \"Index.ets\",\n" 120 " \"sources\": [\n" 121 " \"entry/src/main/ets/pages/Index.ets\"\n" 122 " ],\n" 123 " \"names\": [],\n" 124 " \"mappings\": A;\n" 125 " }\n" 126 "}"; 127const std::string sourceMapDataWithInvalidMappings5 = 128 "{\n" 129 " \"entry/src/main/ets/pages/Index.ts\": {\n" 130 " \"version\": 3,\n" 131 " \"file\": \"Index.ets\",\n" 132 " \"sources\": [\n" 133 " \"entry/src/main/ets/pages/Index.ets\"\n" 134 " ],\n" 135 " \"names\": [],\n" 136 " \"mappings\": ;\n" 137 " }\n" 138 "}"; 139const std::string sourceMapDataWithJsSources = 140 "{\n" 141 " \"entry/src/main/ets/pages/Index.js\": {\n" 142 " \"version\": 3,\n" 143 " \"file\": \"Index.ets\",\n" 144 " \"sources\": [\n" 145 " \"entry/src/main/ets/pages/Index.js\"\n" 146 " ],\n" 147 " \"names\": [],\n" 148 " \"mappings\": ;\n" 149 " }\n" 150 "}"; 151 152namespace panda::ecmascript { 153class SourceMapFriend { 154public: 155 uint32_t Base64CharToInt(char charCode) 156 { 157 return sourceMap.Base64CharToInt(charCode); 158 } 159 160 void SplitSourceMap(const std::string &sourceMapData) 161 { 162 sourceMap.SplitSourceMap(sourceMapData); 163 } 164 165 void ExtractSourceMapData(const std::string &allmappings, std::shared_ptr<SourceMapData> &curMapData) 166 { 167 sourceMap.ExtractSourceMapData(allmappings, curMapData); 168 } 169 170 MappingInfo Find(int32_t row, int32_t col, const SourceMapData &targetMap, bool& isReplaces) 171 { 172 return sourceMap.Find(row, col, targetMap, isReplaces); 173 } 174 175 void ExtractKeyInfo(const std::string &aSourceMap, std::vector<std::string> &sourceKeyInfo) 176 { 177 sourceMap.ExtractKeyInfo(aSourceMap, sourceKeyInfo); 178 } 179 180 void GetPosInfo(const std::string &temp, int32_t start, std::string &line, std::string &column) 181 { 182 sourceMap.GetPosInfo(temp, start, line, column); 183 } 184 185 std::vector<std::string> HandleMappings(const std::string &mapping) 186 { 187 return sourceMap.HandleMappings(mapping); 188 } 189 190 bool VlqRevCode(const std::string &vStr, std::vector<int32_t> &ans) 191 { 192 return sourceMap.VlqRevCode(vStr, ans); 193 } 194 195 bool TranslateUrlPositionBySourceMap(std::string &url, int &line, int &column) 196 { 197 return sourceMap.TranslateUrlPositionBySourceMap(url, line, column); 198 } 199 200 bool GetLineAndColumnNumbers(int &line, int &column, SourceMapData &targetMap, bool& isReplaces) 201 { 202 return sourceMap.GetLineAndColumnNumbers(line, column, targetMap, isReplaces); 203 } 204 205private: 206 SourceMap sourceMap; 207}; 208} 209 210namespace panda::test { 211class SourceMapTest : public testing::Test { 212public: 213 static void SetUpTestCase() 214 { 215 GTEST_LOG_(INFO) << "SetUpTestCase"; 216 } 217 218 static void TearDownTestCase() 219 { 220 GTEST_LOG_(INFO) << "TearDownCase"; 221 } 222 223 void SetUp() override 224 { 225 TestHelper::CreateEcmaVMWithScope(instance, thread, scope); 226 instance->SetEnableForceGC(false); 227 } 228 229 void TearDown() override 230 { 231 TestHelper::DestroyEcmaVMWithScope(instance, scope); 232 } 233 234 EcmaVM *instance{nullptr}; 235 EcmaHandleScope *scope{nullptr}; 236 JSThread *thread{nullptr}; 237}; 238 239uint8_t *StringToUint8(const std::string &str) 240{ 241 const auto *data = reinterpret_cast<const uint8_t *>(str.c_str()); 242 return const_cast<uint8_t *>(data); 243} 244 245SourceMap TestInit(const std::string &sourceMapData) 246{ 247 uint8_t *data = StringToUint8(sourceMapData); 248 size_t dataSize = sourceMapData.size(); 249 SourceMap sourceMap; 250 sourceMap.Init(const_cast<uint8_t *>(data), dataSize); 251 return sourceMap; 252} 253 254HWTEST_F_L0(SourceMapTest, TranslateUrlPositionBySourceMapTest) 255{ 256 SourceMap sourceMap; 257 int line = 10, column = 5; 258 std::string url = "test.js"; 259 // if url contains ".js" returns true 260 EXPECT_FALSE(sourceMap.TranslateUrlPositionBySourceMap(url, line, column)); 261 262 // if it can't find sources which match url after init, returns false and throw Translate failed 263 // e.g. 1. sourceMapData is valid, but url is not valid; 264 sourceMap = TestInit(sourceMapData); 265 url = "entry/src/main/ets/pages/Index1.ts"; 266 EXPECT_FALSE(sourceMap.TranslateUrlPositionBySourceMap(url, line, column)); 267 268 // e.g. 2. sourceMapData is not valid 269 sourceMap = TestInit("testInvalidSourceMapData"); 270 url = "entry/src/main/ets/pages/Index.ts"; 271 EXPECT_FALSE(sourceMap.TranslateUrlPositionBySourceMap(url, line, column)); 272 273 sourceMap = TestInit(sourceMapDataWithoutSources); 274 url = "entry/src/main/ets/pages/Index.ts"; 275 EXPECT_TRUE(sourceMap.TranslateUrlPositionBySourceMap(url, line, column)); 276 277 // if mappings is too short(<18), it will throw translate failed 278 sourceMap = TestInit(sourceMapDataWithShortMappings); 279 url = "entry/src/main/ets/pages/Index.ts"; 280 EXPECT_FALSE(sourceMap.TranslateUrlPositionBySourceMap(url, line, column)); 281 282 sourceMap = TestInit(sourceMapData); 283 url = "entry/src/main/ets/pages/Index.ts"; 284 EXPECT_TRUE(sourceMap.TranslateUrlPositionBySourceMap(url, line, column)); 285 286 // if sourceMapData was used twice, sourceMap should cache url/modularMap 287 EXPECT_FALSE(sourceMap.TranslateUrlPositionBySourceMap(url, line, column)); 288 289 sourceMap = TestInit(sourceMapDataWithInvalidMappings1); 290 url = "entry/src/main/ets/pages/Index.ts"; 291 EXPECT_FALSE(sourceMap.TranslateUrlPositionBySourceMap(url, line, column)); 292 293 sourceMap = TestInit(sourceMapDataWithInvalidMappings2); 294 url = "entry/src/main/ets/pages/Index.ts"; 295 EXPECT_FALSE(sourceMap.TranslateUrlPositionBySourceMap(url, line, column)); 296 297 sourceMap = TestInit(sourceMapDataWithInvalidMappings3); 298 url = "entry/src/main/ets/pages/Index.ts"; 299 EXPECT_FALSE(sourceMap.TranslateUrlPositionBySourceMap(url, line, column)); 300 301 sourceMap = TestInit(sourceMapDataWithInvalidMappings4); 302 url = "entry/src/main/ets/pages/Index.ts"; 303 EXPECT_FALSE(sourceMap.TranslateUrlPositionBySourceMap(url, line, column)); 304 305 sourceMap = TestInit(sourceMapDataWithInvalidMappings5); 306 url = "entry/src/main/ets/pages/Index.ts"; 307 EXPECT_FALSE(sourceMap.TranslateUrlPositionBySourceMap(url, line, column)); 308 309 sourceMap = TestInit(sourceMapData); 310 url = "entry/src/main/ets/pages/Index.ts"; 311 line = 0, column = 5; 312 EXPECT_FALSE(sourceMap.TranslateUrlPositionBySourceMap(url, line, column)); 313 314 sourceMap = TestInit(sourceMapData); 315 url = "entry/src/main/ets/pages/Index.ts"; 316 line = 5, column = 0; 317 EXPECT_FALSE(sourceMap.TranslateUrlPositionBySourceMap(url, line, column)); 318 319 // if sourceMapData is valid and url is end by ".js", it should return true 320 url = "entry/src/main/ets/pages/Index.js"; 321 sourceMap = TestInit(sourceMapDataWithJsSources); 322 EXPECT_TRUE(sourceMap.TranslateUrlPositionBySourceMap(url, line, column)); 323} 324 325HWTEST_F_L0(SourceMapTest, Base64CharToIntTest) 326{ 327 SourceMapFriend sourceMapFriend; 328 EXPECT_EQ(sourceMapFriend.Base64CharToInt('A'), 0); 329 EXPECT_EQ(sourceMapFriend.Base64CharToInt('a'), 26); 330 EXPECT_EQ(sourceMapFriend.Base64CharToInt('0'), 52); 331 EXPECT_EQ(sourceMapFriend.Base64CharToInt('+'), 62); 332 EXPECT_EQ(sourceMapFriend.Base64CharToInt('/'), 63); 333 EXPECT_EQ(sourceMapFriend.Base64CharToInt('-'), 64); 334} 335 336void PrintSourceMapData(const SourceMapData &data) 337{ 338 std::cout << "URL: " << data.url_ << std::endl; 339 std::cout << "Now Position: (" << data.nowPos_.afterRow << ", " << data.nowPos_.afterColumn << ")" << std::endl; 340 341 std::cout << "Files:" << std::endl; 342 for (const auto &file: data.files_) { 343 std::cout << "- " << file << std::endl; 344 } 345 346 std::cout << "Sources:" << std::endl; 347 for (const auto &source: data.sources_) { 348 std::cout << "- " << source << std::endl; 349 } 350 351 std::cout << "Names:" << std::endl; 352 for (const auto &name: data.names_) { 353 std::cout << "- " << name << std::endl; 354 } 355 356 std::cout << "Mappings:" << std::endl; 357 for (const auto &mapping: data.mappings_) { 358 std::cout << "- " << mapping << std::endl; 359 } 360 361 std::cout << "After Positions:" << std::endl; 362 for (const auto &pos: data.afterPos_) { 363 std::cout << "- (" << pos.beforeRow << ", " << pos.beforeColumn << ", " << pos.afterRow << ", " 364 << pos.afterColumn << ")" << std::endl; 365 } 366} 367 368HWTEST_F_L0(SourceMapTest, ExtractSourceMapDataTest) 369{ 370 SourceMapFriend sourceMapFriend; 371 std::string mappings = ";MAEO,CAAK,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA"; 372 auto sourceMapDataInstance = std::make_shared<SourceMapData>(); 373 std::shared_ptr<SourceMapData> &curMapData = sourceMapDataInstance; 374 375 sourceMapFriend.ExtractSourceMapData(mappings, curMapData); 376 SourceMapData &data = *curMapData; 377 EXPECT_EQ(data.afterPos_.size(), 13); 378} 379 380HWTEST_F_L0(SourceMapTest, FindTest) 381{ 382 // Find Full Covered 383 SourceMapFriend sourceMapFriend; 384 SourceMapData targetMap; 385 MappingInfo mappingInfo; 386 bool isReplaces = true; 387 388 mappingInfo = sourceMapFriend.Find(0, 1, targetMap, isReplaces); 389 EXPECT_EQ(mappingInfo.row, 0); 390 EXPECT_EQ(mappingInfo.col, 0); 391 EXPECT_TRUE(isReplaces); 392 mappingInfo = sourceMapFriend.Find(1, 1, targetMap, isReplaces); 393 EXPECT_EQ(mappingInfo.row, 0); 394 EXPECT_EQ(mappingInfo.col, 0); 395 EXPECT_TRUE(isReplaces); 396 397 std::vector<SourceMapInfo> afterPos; 398 SourceMapInfo info; 399 info.beforeRow = 1; 400 info.beforeColumn = 1; 401 info.afterRow = 2; 402 info.afterColumn = 2; 403 info.sourcesVal = 1; 404 info.namesVal = 1; 405 afterPos.push_back(info); 406 targetMap.afterPos_ = afterPos; 407 mappingInfo = sourceMapFriend.Find(3, 3, targetMap, isReplaces); 408 EXPECT_EQ(mappingInfo.row, 2); 409 EXPECT_EQ(mappingInfo.col, 2); 410 EXPECT_TRUE(isReplaces); 411 412 mappingInfo = sourceMapFriend.Find(3, 2, targetMap, isReplaces); 413 EXPECT_EQ(mappingInfo.row, 2); 414 EXPECT_EQ(mappingInfo.col, 2); 415 EXPECT_TRUE(isReplaces); 416 417 mappingInfo = sourceMapFriend.Find(2, 2, targetMap, isReplaces); 418 EXPECT_EQ(mappingInfo.row, 2); 419 EXPECT_EQ(mappingInfo.col, 2); 420 EXPECT_TRUE(isReplaces); 421} 422 423HWTEST_F_L0(SourceMapTest, ExtractKeyInfoTest) 424{ 425 // ExtractKeyInfo Full Covered 426 SourceMapFriend sourceMapFriend; 427 std::string sourceMap = R"({"key1": "value1", "key2": "value\"2"})"; 428 std::vector<std::string> sourceKey; 429 std::vector<std::string> &sourceKeyInfo = sourceKey; 430 sourceMapFriend.ExtractKeyInfo(sourceMap, sourceKeyInfo); 431 EXPECT_EQ(sourceKeyInfo[0], "key1"); 432 EXPECT_EQ(sourceKeyInfo[1], "value1"); 433 EXPECT_EQ(sourceKeyInfo[2], "key2"); 434 EXPECT_EQ(sourceKeyInfo[3], "value\"2"); 435} 436 437HWTEST_F_L0(SourceMapTest, GetPosInfoTest) 438{ 439 SourceMapFriend sourceMapFriend; 440 std::string temp = "005:012:0"; 441 int32_t start = 6; 442 std::string line, column; 443 444 sourceMapFriend.GetPosInfo(temp, start, line, column); 445 EXPECT_EQ(line, "05"); 446 EXPECT_EQ(column, "01"); 447} 448 449HWTEST_F_L0(SourceMapTest, HandleMappingsTest) 450{ 451 SourceMapFriend sourceMapFriend; 452 std::string mapping = "X;Y"; 453 std::vector<std::string> result = sourceMapFriend.HandleMappings(mapping); 454 ASSERT_EQ(result.size(), 3u); 455 EXPECT_EQ(result[0], "X"); 456 EXPECT_EQ(result[1], ";"); 457 EXPECT_EQ(result[2], "Y"); 458} 459 460HWTEST_F_L0(SourceMapTest, VlqRevCodeTest) 461{ 462 SourceMapFriend sourceMapFriend; 463 std::string vStr; 464 std::vector<int32_t> ans; 465 EXPECT_TRUE(sourceMapFriend.VlqRevCode(vStr, ans)); 466 467 vStr = "A"; 468 EXPECT_TRUE(sourceMapFriend.VlqRevCode(vStr, ans)); 469 ASSERT_EQ(ans.size(), 1u); 470 471 vStr = "A=A"; 472 EXPECT_FALSE(sourceMapFriend.VlqRevCode(vStr, ans)); 473 474 vStr = "X"; 475 EXPECT_TRUE(sourceMapFriend.VlqRevCode(vStr, ans)); 476 477 vStr = "A"; 478 EXPECT_TRUE(sourceMapFriend.VlqRevCode(vStr, ans)); 479} 480 481HWTEST_F_L0(SourceMapTest, GetLineAndColumnNumbersTest) 482{ 483 // GetLineAndColumnNumbers is full covered 484 SourceMapFriend sourceMapFriend; 485 SourceMapData targetMap; 486 std::vector<SourceMapInfo> afterPos; 487 SourceMapInfo info; 488 info.beforeRow = 1; 489 info.beforeColumn = 1; 490 info.afterRow = 2; 491 info.afterColumn = 2; 492 info.sourcesVal = 1; 493 info.namesVal = 1; 494 afterPos.push_back(info); 495 targetMap.afterPos_ = afterPos; 496 bool isReplaces = true; 497 498 int line = 1; 499 int column = 1; 500 bool result = sourceMapFriend.GetLineAndColumnNumbers(line, column, targetMap, isReplaces); 501 EXPECT_TRUE(result); 502 EXPECT_EQ(line, 2); 503 EXPECT_EQ(column, 2); 504 EXPECT_TRUE(isReplaces); 505 506 line = 5; 507 column = 5; 508 result = sourceMapFriend.GetLineAndColumnNumbers(line, column, targetMap, isReplaces); 509 EXPECT_TRUE(result); 510 EXPECT_EQ(line, 5); 511 EXPECT_EQ(column, 5); 512 EXPECT_FALSE(isReplaces); 513 514 line = 99; 515 column = 99; 516 result = sourceMapFriend.GetLineAndColumnNumbers(line, column, targetMap, isReplaces); 517 EXPECT_TRUE(result); 518 EXPECT_EQ(line, 99); 519 EXPECT_EQ(column, 99); 520 EXPECT_FALSE(isReplaces); 521} 522}