Skip to content

Commit

Permalink
refactor: Sort sloppiness parsing/generation
Browse files Browse the repository at this point in the history
  • Loading branch information
jrosdahl committed Apr 1, 2022
1 parent 0b3c5f1 commit 836f76e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 38 deletions.
56 changes: 28 additions & 28 deletions src/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,28 +267,28 @@ parse_sloppiness(const std::string& value)
end = value.find_first_of(", ", start);
std::string token =
util::strip_whitespace(value.substr(start, end - start));
if (token == "file_stat_matches") {
if (token == "clang_index_store") {
result.enable(core::Sloppy::clang_index_store);
} else if (token == "file_stat_matches") {
result.enable(core::Sloppy::file_stat_matches);
} else if (token == "file_stat_matches_ctime") {
result.enable(core::Sloppy::file_stat_matches_ctime);
} else if (token == "include_file_ctime") {
result.enable(core::Sloppy::include_file_ctime);
} else if (token == "include_file_mtime") {
result.enable(core::Sloppy::include_file_mtime);
} else if (token == "system_headers" || token == "no_system_headers") {
result.enable(core::Sloppy::system_headers);
} else if (token == "pch_defines") {
result.enable(core::Sloppy::pch_defines);
} else if (token == "time_macros") {
result.enable(core::Sloppy::time_macros);
} else if (token == "clang_index_store") {
result.enable(core::Sloppy::clang_index_store);
} else if (token == "ivfsoverlay") {
result.enable(core::Sloppy::ivfsoverlay);
} else if (token == "locale") {
result.enable(core::Sloppy::locale);
} else if (token == "modules") {
result.enable(core::Sloppy::modules);
} else if (token == "ivfsoverlay") {
result.enable(core::Sloppy::ivfsoverlay);
} else if (token == "pch_defines") {
result.enable(core::Sloppy::pch_defines);
} else if (token == "system_headers" || token == "no_system_headers") {
result.enable(core::Sloppy::system_headers);
} else if (token == "time_macros") {
result.enable(core::Sloppy::time_macros);
} // else: ignore unknown value for forward compatibility
start = value.find_first_not_of(", ", end);
}
Expand All @@ -299,38 +299,38 @@ std::string
format_sloppiness(core::Sloppiness sloppiness)
{
std::string result;
if (sloppiness.is_enabled(core::Sloppy::include_file_mtime)) {
result += "include_file_mtime, ";
}
if (sloppiness.is_enabled(core::Sloppy::include_file_ctime)) {
result += "include_file_ctime, ";
}
if (sloppiness.is_enabled(core::Sloppy::time_macros)) {
result += "time_macros, ";
}
if (sloppiness.is_enabled(core::Sloppy::pch_defines)) {
result += "pch_defines, ";
if (sloppiness.is_enabled(core::Sloppy::clang_index_store)) {
result += "clang_index_store, ";
}
if (sloppiness.is_enabled(core::Sloppy::file_stat_matches)) {
result += "file_stat_matches, ";
}
if (sloppiness.is_enabled(core::Sloppy::file_stat_matches_ctime)) {
result += "file_stat_matches_ctime, ";
}
if (sloppiness.is_enabled(core::Sloppy::system_headers)) {
result += "system_headers, ";
if (sloppiness.is_enabled(core::Sloppy::include_file_ctime)) {
result += "include_file_ctime, ";
}
if (sloppiness.is_enabled(core::Sloppy::clang_index_store)) {
result += "clang_index_store, ";
if (sloppiness.is_enabled(core::Sloppy::include_file_mtime)) {
result += "include_file_mtime, ";
}
if (sloppiness.is_enabled(core::Sloppy::ivfsoverlay)) {
result += "ivfsoverlay, ";
}
if (sloppiness.is_enabled(core::Sloppy::locale)) {
result += "locale, ";
}
if (sloppiness.is_enabled(core::Sloppy::modules)) {
result += "modules, ";
}
if (sloppiness.is_enabled(core::Sloppy::ivfsoverlay)) {
result += "ivfsoverlay, ";
if (sloppiness.is_enabled(core::Sloppy::pch_defines)) {
result += "pch_defines, ";
}
if (sloppiness.is_enabled(core::Sloppy::system_headers)) {
result += "system_headers, ";
}
if (sloppiness.is_enabled(core::Sloppy::time_macros)) {
result += "time_macros, ";
}
if (!result.empty()) {
// Strip last ", ".
Expand Down
20 changes: 10 additions & 10 deletions unittest/test_Config.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2011-2021 Joel Rosdahl and other contributors
// Copyright (C) 2011-2022 Joel Rosdahl and other contributors
//
// See doc/AUTHORS.adoc for a complete list of contributors.
//
Expand Down Expand Up @@ -169,15 +169,15 @@ TEST_CASE("Config::update_from_file")
CHECK(config.reshare());
CHECK_FALSE(config.run_second_cpp());
CHECK(config.sloppiness().to_bitmask()
== (static_cast<uint32_t>(core::Sloppy::include_file_mtime)
| static_cast<uint32_t>(core::Sloppy::include_file_ctime)
| static_cast<uint32_t>(core::Sloppy::time_macros)
== (static_cast<uint32_t>(core::Sloppy::clang_index_store)
| static_cast<uint32_t>(core::Sloppy::file_stat_matches)
| static_cast<uint32_t>(core::Sloppy::file_stat_matches_ctime)
| static_cast<uint32_t>(core::Sloppy::system_headers)
| static_cast<uint32_t>(core::Sloppy::include_file_ctime)
| static_cast<uint32_t>(core::Sloppy::include_file_mtime)
| static_cast<uint32_t>(core::Sloppy::ivfsoverlay)
| static_cast<uint32_t>(core::Sloppy::pch_defines)
| static_cast<uint32_t>(core::Sloppy::clang_index_store)
| static_cast<uint32_t>(core::Sloppy::ivfsoverlay)));
| static_cast<uint32_t>(core::Sloppy::system_headers)
| static_cast<uint32_t>(core::Sloppy::time_macros)));
CHECK_FALSE(config.stats());
CHECK(config.temporary_dir() == FMT("{}_foo", user));
CHECK(config.umask() == 0777u);
Expand Down Expand Up @@ -473,9 +473,9 @@ TEST_CASE("Config::visit_items")
"(test.conf) reshare = true",
"(test.conf) run_second_cpp = false",
"(test.conf) secondary_storage = ss",
"(test.conf) sloppiness = include_file_mtime, include_file_ctime,"
" time_macros, pch_defines, file_stat_matches, file_stat_matches_ctime,"
" system_headers, clang_index_store, ivfsoverlay",
"(test.conf) sloppiness = clang_index_store, file_stat_matches,"
" file_stat_matches_ctime, include_file_ctime, include_file_mtime,"
" ivfsoverlay, pch_defines, system_headers, time_macros",
"(test.conf) stats = false",
"(test.conf) stats_log = sl",
"(test.conf) temporary_dir = td",
Expand Down

0 comments on commit 836f76e

Please sign in to comment.