@@ -281,17 +281,50 @@ namespace Paths {
281281 static const std::string MAKEFILE_EXTENSION = " .mk" ;
282282 static const std::string TEST_SUFFIX = " _test" ;
283283 static const std::string STUB_SUFFIX = " _stub" ;
284+ static const std::string DOT_SEP = " _dot_" ;
285+ static const char dot = ' .' ;
284286
285287 fs::path sourcePathToTestPath (const utbot::ProjectContext &projectContext,
286288 const fs::path &sourceFilePath) {
287289 return projectContext.testDirPath / getRelativeDirPath (projectContext, sourceFilePath) /
288290 sourcePathToTestName (sourceFilePath);
289291 }
292+
293+ static inline fs::path addOrigExtensionAsSuffixAndAddNew (const fs::path &path,
294+ const std::string &newExt) {
295+ std::string extensionAsSuffix = path.extension ().string ();
296+ if (!extensionAsSuffix.empty ()) {
297+ std::string fnWithNewExt =
298+ path.stem ().string () + DOT_SEP + extensionAsSuffix.substr (1 ) + newExt;
299+ return path.parent_path () / fnWithNewExt;
300+ }
301+ return replaceExtension (path, newExt);
302+ }
303+
304+ static inline fs::path restoreExtensionFromSuffix (const fs::path &path,
305+ const std::string &defaultExt) {
306+ std::string fnWithoutExt = path.stem ();
307+ fs::path fnWithExt;
308+ std::size_t posEncodedExtension = fnWithoutExt.rfind (DOT_SEP);
309+ if (posEncodedExtension == std::string::npos) {
310+ // In `sample_class_test.cpp` the `class` is not an extension
311+ fnWithExt = fnWithoutExt + defaultExt;
312+ }
313+ else {
314+ // In `sample_class_dot_cpp.cpp` the `cpp` is an extension
315+ fnWithExt = fnWithoutExt.substr (0 , posEncodedExtension)
316+ + dot
317+ + fnWithoutExt.substr (posEncodedExtension + DOT_SEP.length ());
318+ }
319+ return path.parent_path () / fs::path (fnWithExt);
320+ }
321+
290322 fs::path sourcePathToTestName (const fs::path &source) {
291- return replaceExtension (addSuffix (source, TEST_SUFFIX), " .cpp" ).filename ();
323+ return addSuffix (addOrigExtensionAsSuffixAndAddNew (source, " .cpp" ),
324+ TEST_SUFFIX).filename ();
292325 }
293326 fs::path testPathToSourceName (const fs::path &testFilePath) {
294- return replaceExtension (removeSuffix (testFilePath, TEST_SUFFIX), " .c" ).filename ();
327+ return restoreExtensionFromSuffix (removeSuffix (testFilePath, TEST_SUFFIX), " .c" ).filename ();
295328 }
296329 fs::path sourcePathToStubName (const fs::path &source) {
297330 return addSuffix (source, STUB_SUFFIX).filename ();
0 commit comments