Skip to content

Commit d0d7dc9

Browse files
author
Samat Gaynutdinov
committed
refactor: remove struct
1 parent cb859cf commit d0d7dc9

File tree

3 files changed

+26
-27
lines changed

3 files changed

+26
-27
lines changed

server/src/Paths.cpp

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -278,11 +278,12 @@ namespace Paths {
278278
//endregion
279279

280280
//region transformation
281-
const std::string Extensions::MAKEFILE_EXTENSION = ".mk";
282-
const std::string Extensions::TEST_SUFFIX = "_test";
283-
const std::string Extensions::STUB_SUFFIX = "_stub";
284-
const std::string Extensions::DOT_SEP = "_dot_";
285-
const std::string Extensions::MAKE_WRAPPER_SUFFIX = "_wrapper";
281+
const std::string MAKEFILE_EXTENSION = ".mk";
282+
const std::string TEST_SUFFIX = "_test";
283+
const std::string STUB_SUFFIX = "_stub";
284+
const std::string DOT_SEP = "_dot_";
285+
const std::string MAKE_WRAPPER_SUFFIX = "_wrapper";
286+
const char dot = '.';
286287

287288
fs::path sourcePathToTestPath(const utbot::ProjectContext &projectContext,
288289
const fs::path &sourceFilePath) {
@@ -295,7 +296,7 @@ namespace Paths {
295296
std::string extensionAsSuffix = path.extension().string();
296297
if (!extensionAsSuffix.empty()) {
297298
std::string fnWithNewExt =
298-
path.stem().string() + Extensions::DOT_SEP + extensionAsSuffix.substr(1) + newExt;
299+
path.stem().string() + DOT_SEP + extensionAsSuffix.substr(1) + newExt;
299300
return path.parent_path() / fnWithNewExt;
300301
}
301302
return replaceExtension(path, newExt);
@@ -305,32 +306,32 @@ namespace Paths {
305306
const std::string &defaultExt) {
306307
std::string fnWithoutExt = path.stem();
307308
fs::path fnWithExt;
308-
std::size_t posEncodedExtension = fnWithoutExt.rfind(Extensions::DOT_SEP);
309+
std::size_t posEncodedExtension = fnWithoutExt.rfind(DOT_SEP);
309310
if (posEncodedExtension == std::string::npos) {
310311
// In `sample_class_test.cpp` the `class` is not an extension
311312
fnWithExt = fnWithoutExt + defaultExt;
312313
}
313314
else {
314315
// In `sample_class_dot_cpp.cpp` the `cpp` is an extension
315316
fnWithExt = fnWithoutExt.substr(0, posEncodedExtension)
316-
+ Extensions::dot
317-
+ fnWithoutExt.substr(posEncodedExtension + Extensions::DOT_SEP.length());
317+
+ dot
318+
+ fnWithoutExt.substr(posEncodedExtension + DOT_SEP.length());
318319
}
319320
return path.parent_path() / fs::path(fnWithExt);
320321
}
321322

322323
fs::path sourcePathToTestName(const fs::path &source) {
323324
return addSuffix(addOrigExtensionAsSuffixAndAddNew(source, ".cpp"),
324-
Extensions::TEST_SUFFIX).filename();
325+
TEST_SUFFIX).filename();
325326
}
326327
fs::path testPathToSourceName(const fs::path &testFilePath) {
327-
return restoreExtensionFromSuffix(removeSuffix(testFilePath, Extensions::TEST_SUFFIX), ".c").filename();
328+
return restoreExtensionFromSuffix(removeSuffix(testFilePath, TEST_SUFFIX), ".c").filename();
328329
}
329330
fs::path sourcePathToStubName(const fs::path &source) {
330-
return addSuffix(source, Extensions::STUB_SUFFIX).filename();
331+
return addSuffix(source, STUB_SUFFIX).filename();
331332
}
332333
fs::path getStubBitcodeFilePath(const fs::path &bitcodeFilePath) {
333-
return Paths::addSuffix(bitcodeFilePath, Extensions::STUB_SUFFIX);
334+
return Paths::addSuffix(bitcodeFilePath, STUB_SUFFIX);
334335
}
335336

336337
fs::path sourcePathToStubHeaderPath(const utbot::ProjectContext &projectContext,
@@ -362,15 +363,15 @@ namespace Paths {
362363
if (!suffix.empty()) {
363364
addSuffix(makefileDir, suffix);
364365
}
365-
std::string makefileName = replaceExtension(sourceFilePath, Extensions::MAKEFILE_EXTENSION).filename();
366+
std::string makefileName = replaceExtension(sourceFilePath, MAKEFILE_EXTENSION).filename();
366367
return makefileDir / makefileName;
367368
}
368369

369370
fs::path getStubsMakefilePath(const utbot::ProjectContext &projectContext,
370371
const fs::path &sourceFilePath) {
371372
fs::path makefileDir = getMakefileDir(projectContext, sourceFilePath);
372373
std::string makefileName =
373-
addExtension(addSuffix(sourceFilePath.stem(), Extensions::STUB_SUFFIX), Extensions::MAKEFILE_EXTENSION);
374+
addExtension(addSuffix(sourceFilePath.stem(), STUB_SUFFIX), MAKEFILE_EXTENSION);
374375
return makefileDir / makefileName;
375376
}
376377

@@ -409,11 +410,11 @@ namespace Paths {
409410
fs::path sourceFilePath =
410411
projectContext.projectPath /
411412
fs::relative(stubPath, getStubsDirPath(projectContext));
412-
return removeSuffix(sourceFilePath, Extensions::STUB_SUFFIX);
413+
return removeSuffix(sourceFilePath, STUB_SUFFIX);
413414
}
414415

415416
bool isHeadersEqual(const fs::path &srcPath, const fs::path &headerPath) {
416-
return removeSuffix(srcPath, Extensions::STUB_SUFFIX).stem() == headerPath.stem();
417+
return removeSuffix(srcPath, STUB_SUFFIX).stem() == headerPath.stem();
417418
}
418419
fs::path getUtbotBuildDir(const utbot::ProjectContext &projectContext) {
419420
return projectContext.buildDir / CompilationUtils::UTBOT_BUILD_DIR_NAME;

server/src/Paths.h

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -318,14 +318,12 @@ namespace Paths {
318318
//endregion
319319

320320
//region transformations
321-
struct Extensions {
322-
static const std::string MAKEFILE_EXTENSION;
323-
static const std::string TEST_SUFFIX;
324-
static const std::string STUB_SUFFIX;
325-
static const std::string DOT_SEP;
326-
static const std::string MAKE_WRAPPER_SUFFIX;
327-
static const char dot = '.';
328-
};
321+
extern const std::string MAKEFILE_EXTENSION;
322+
extern const std::string TEST_SUFFIX;
323+
extern const std::string STUB_SUFFIX;
324+
extern const std::string DOT_SEP;
325+
extern const std::string MAKE_WRAPPER_SUFFIX;
326+
extern const char dot;
329327

330328
fs::path sourcePathToTestPath(const utbot::ProjectContext &projectContext, const fs::path &sourceFilePath);
331329

server/test/framework/CLI_Tests.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ namespace {
8080
FileSystemUtils::RecursiveDirectoryIterator directoryIterator(getTestDirectory());
8181
for (auto &&it : directoryIterator) {
8282
if (!it.is_regular_file() ||
83-
it.path().extension() == Paths::Extensions::MAKEFILE_EXTENSION ||
84-
StringUtils::endsWith(Paths::removeExtension(it.path().filename()).string(), Paths::Extensions::MAKE_WRAPPER_SUFFIX)) {
83+
it.path().extension() == Paths::MAKEFILE_EXTENSION ||
84+
StringUtils::endsWith(Paths::removeExtension(it.path().filename()).string(), Paths::MAKE_WRAPPER_SUFFIX)) {
8585
continue;
8686
}
8787
EXPECT_TRUE(Paths::isSubPathOf(getStubsDirectory(), it.path()) ||

0 commit comments

Comments
 (0)