Compare commits

...

3 Commits

Author SHA1 Message Date
Bartek Kryza
100f7c88ad Merge pull request #228 from bkryza/add-coroutine-testcase
Add coroutine testcase
2024-01-11 17:10:25 +01:00
Bartek Kryza
13f2ffb706 Merge pull request #220 from bkryza/fix-source-location-extraction-on-windows
Fix manual parsing of Windows source location paths (#217)
2023-12-15 15:20:53 +01:00
Bartek Kryza
4da14a32d7 Fix manual parsing of Windows source location paths (#217) 2023-12-14 19:43:37 +01:00
3 changed files with 57 additions and 2 deletions

View File

@@ -836,12 +836,23 @@ bool parse_source_location(const std::string &location_str, std::string &file,
if (tokens.size() < 3)
return false;
if (tokens.size() == 4) {
// Handle Windows paths
decltype(tokens) tmp_tokens{};
tmp_tokens.emplace_back(
fmt::format("{}:{}", tokens.at(0), tokens.at(1)));
tmp_tokens.emplace_back(tokens.at(2));
tmp_tokens.emplace_back(tokens.at(3));
tokens = std::move(tmp_tokens);
}
file = tokens.at(0);
try {
line = std::stoi(tokens.at(1));
}
catch (std::invalid_argument &e) {
line = 0;
return false;
}
try {

View File

@@ -145,7 +145,7 @@ void translation_unit_visitor::set_source_location(
file_path = fs::absolute(file_path);
}
file_path = fs::canonical(file_path);
file_path = fs::weakly_canonical(file_path);
file = file_path.string();

View File

@@ -431,3 +431,47 @@ TEST_CASE("Test is_relative_to", "[unit-test]")
CHECK(is_relative_to(child, base1));
CHECK_FALSE(is_relative_to(child, base2));
}
TEST_CASE("Test parse_source_location", "[unit-test]")
{
using namespace clanguml::common;
const std::string int_template_str{"ns1::ns2::class1<int>"};
std::string file;
unsigned line{};
unsigned column{};
bool result = false;
result = parse_source_location("/a/b/c/d/test.cpp:123", file, line, column);
CHECK_FALSE(result);
result = false, file = "", line = 0, column = 0;
result =
parse_source_location("/a/b/c/d/test.cpp:123:456", file, line, column);
CHECK(result);
CHECK(file == "/a/b/c/d/test.cpp");
CHECK(line == 123);
CHECK(column == 456);
result = false, file = "", line = 0, column = 0;
result = parse_source_location(
"E:\\test\\src\\main.cpp:123", file, line, column);
CHECK_FALSE(result);
result = false, file = "", line = 0, column = 0;
result = parse_source_location(
"E:\\test\\src\\main.cpp:123:456", file, line, column);
CHECK(result);
CHECK(file == "E:\\test\\src\\main.cpp");
CHECK(line == 123);
CHECK(column == 456);
result = false, file = "", line = 0, column = 0;
}