Permalink
Browse files

Adds unit test for escape_path()

  • Loading branch information...
robinluckey committed Dec 22, 2011
1 parent 3539672 commit 140f487859b6b5da92752c29ae186882ae9449a5
Showing with 20 additions and 0 deletions.
  1. +3 −0 src/detector.h
  2. +17 −0 test/unit/detector_test.h
View
@@ -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
View
@@ -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();

0 comments on commit 140f487

Please sign in to comment.