Skip to content

Commit

Permalink
Adds unit test for escape_path()
Browse files Browse the repository at this point in the history
  • Loading branch information
Robin Luckey committed Dec 22, 2011
1 parent 3539672 commit 140f487
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/detector.h
Expand Up @@ -31,4 +31,7 @@ const char *ohcount_detect_language(SourceFile *sourcefile);


int ohcount_is_binary_filename(const char *filename); int ohcount_is_binary_filename(const char *filename);


/* Exported for unit testing */
void escape_path(char *safe, const char *unsafe);

#endif #endif
17 changes: 17 additions & 0 deletions test/unit/detector_test.h
Expand Up @@ -191,7 +191,24 @@ void test_detector_emacs_mode() {
ASSERT_DETECT(LANG_C, "emacs_mode.c"); 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() { void all_detector_tests() {
test_detector_escape_path();
test_detector_smalltalk(); test_detector_smalltalk();
test_detector_disambiguate_asx(); test_detector_disambiguate_asx();
test_detector_disambiguate_def(); test_detector_disambiguate_def();
Expand Down

0 comments on commit 140f487

Please sign in to comment.