diff --git a/src/detector.h b/src/detector.h index 53277b84..48d19dc3 100644 --- a/src/detector.h +++ b/src/detector.h @@ -31,4 +31,7 @@ const char *ohcount_detect_language(SourceFile *sourcefile); int ohcount_is_binary_filename(const char *filename); +/* Exported for unit testing */ +void escape_path(char *safe, const char *unsafe); + #endif diff --git a/test/unit/detector_test.h b/test/unit/detector_test.h index 40b33905..ae7f9d44 100755 --- a/test/unit/detector_test.h +++ b/test/unit/detector_test.h @@ -191,7 +191,24 @@ void test_detector_emacs_mode() { ASSERT_DETECT(LANG_C, "emacs_mode.c"); } +void test_detector_escape_path() { + char escaped[100]; + + escape_path(escaped, ""); + assert(strcmp(escaped, "") == 0); + + escape_path(escaped, "hello.c"); + assert(strcmp(escaped, "hello.c") == 0); + + escape_path(escaped, "'"); + assert(strcmp(escaped, "\'\\\'\'") == 0); + + escape_path(escaped, "Robin's 'Fancy' Filename"); + assert(strcmp(escaped, "Robin\'\\\'\'s \'\\\'\'Fancy\'\\\'\' Filename") == 0); +} + void all_detector_tests() { + test_detector_escape_path(); test_detector_smalltalk(); test_detector_disambiguate_asx(); test_detector_disambiguate_def();