diff --git a/src/lib/c/factories.c b/src/lib/c/factories.c index c021e58..b583541 100644 --- a/src/lib/c/factories.c +++ b/src/lib/c/factories.c @@ -79,6 +79,9 @@ SourceFormatDetection detectSourceFormat(const RcnSourceFile* file) { detection.isSupportedFormat = true; detection.isProgrammingLanguage = true; detection.format = RCN_LANG_JAVA; + } else if (strcmp(extension, "md") == 0) { + detection.isSupportedFormat = true; + detection.format = RCN_TEXT_MARKDOWN; } else if (strcmp(extension, "txt") == 0) { detection.isSupportedFormat = true; detection.format = RCN_TEXT_UNFORMATTED; diff --git a/src/lib/include/reckon/reckon.h b/src/lib/include/reckon/reckon.h index c3b6291..856768e 100644 --- a/src/lib/include/reckon/reckon.h +++ b/src/lib/include/reckon/reckon.h @@ -100,7 +100,7 @@ extern "C" { * The total number of supported text formats, including * supported programming languages. */ -#define RECKON_NUM_SUPPORTED_FORMATS 3 +#define RECKON_NUM_SUPPORTED_FORMATS 4 /** * Macro to create a format option bitmask. @@ -140,15 +140,20 @@ typedef enum RcnTextFormat { */ RCN_TEXT_UNFORMATTED = 0, + /** + * Text formatted in Markdown, as found in files with a '.md' extension. + */ + RCN_TEXT_MARKDOWN = 1, + /** * Source files for the C programming language. */ - RCN_LANG_C = 1, + RCN_LANG_C = 2, /** * Source files for the Java programming language. */ - RCN_LANG_JAVA = 2 + RCN_LANG_JAVA = 3 } RcnTextFormat; diff --git a/src/lib/tests/res/mixed/text2.md b/src/lib/tests/res/mixed/text2.md new file mode 100644 index 0000000..20680ff --- /dev/null +++ b/src/lib/tests/res/mixed/text2.md @@ -0,0 +1,10 @@ +# This is some test text data used for testing purposes. + +## Here comes a line. + +And *another* one. + +**Another** line here. + + +## The End. diff --git a/src/lib/tests/unit/c/test_count_options.c b/src/lib/tests/unit/c/test_count_options.c index f74dfa1..debda9a 100644 --- a/src/lib/tests/unit/c/test_count_options.c +++ b/src/lib/tests/unit/c/test_count_options.c @@ -224,7 +224,7 @@ void testCountStatisticsOnlyJavaSources(void) { TEST_ASSERT_EQUAL_INT(0, stats->sourceSize[RCN_TEXT_UNFORMATTED]); TEST_ASSERT_EQUAL_INT(450, stats->sourceSize[RCN_LANG_JAVA]); TEST_ASSERT_EQUAL_INT(0, stats->sourceSize[RCN_LANG_C]); - TEST_ASSERT_EQUAL_INT(3, stats->count.size); + TEST_ASSERT_EQUAL_INT(4, stats->count.size); TEST_ASSERT_EQUAL_INT(1, stats->count.sizeProcessed); RcnSourceFile* file = &stats->count.files[0]; TEST_ASSERT_EQUAL_STRING("Source.java", file->name); @@ -272,7 +272,7 @@ void testCountStatisticsOnlyUnformattedTextSources(void) { TEST_ASSERT_EQUAL_INT(122, stats->sourceSize[RCN_TEXT_UNFORMATTED]); TEST_ASSERT_EQUAL_INT(0, stats->sourceSize[RCN_LANG_JAVA]); TEST_ASSERT_EQUAL_INT(0, stats->sourceSize[RCN_LANG_C]); - TEST_ASSERT_EQUAL_INT(3, stats->count.size); + TEST_ASSERT_EQUAL_INT(4, stats->count.size); TEST_ASSERT_EQUAL_INT(1, stats->count.sizeProcessed); RcnSourceFile* file = &stats->count.files[2]; TEST_ASSERT_EQUAL_STRING("text.txt", file->name); @@ -303,27 +303,32 @@ void testCountStatisticsAllOperationsWithAllDefaultOptions(void) { TEST_ASSERT_EQUAL_INT(RCN_ERR_NONE, stats->state.errorCode); TEST_ASSERT_NULL(stats->state.errorMessage); TEST_ASSERT_EQUAL_INT(34, stats->totalLogicalLines); - TEST_ASSERT_EQUAL_INT(50, stats->totalPhysicalLines); - TEST_ASSERT_EQUAL_INT(104, stats->totalWords); - TEST_ASSERT_EQUAL_INT(941, stats->totalCharacters); - TEST_ASSERT_EQUAL_INT(941, stats->totalSourceSize); + TEST_ASSERT_EQUAL_INT(60, stats->totalPhysicalLines); + TEST_ASSERT_EQUAL_INT(129, stats->totalWords); + TEST_ASSERT_EQUAL_INT(1079, stats->totalCharacters); + TEST_ASSERT_EQUAL_INT(1079, stats->totalSourceSize); TEST_ASSERT_EQUAL_INT(0, stats->logicalLines[RCN_TEXT_UNFORMATTED]); + TEST_ASSERT_EQUAL_INT(0, stats->logicalLines[RCN_TEXT_MARKDOWN]); TEST_ASSERT_EQUAL_INT(16, stats->logicalLines[RCN_LANG_JAVA]); TEST_ASSERT_EQUAL_INT(18, stats->logicalLines[RCN_LANG_C]); TEST_ASSERT_EQUAL_INT(8, stats->physicalLines[RCN_TEXT_UNFORMATTED]); + TEST_ASSERT_EQUAL_INT(10, stats->physicalLines[RCN_TEXT_MARKDOWN]); TEST_ASSERT_EQUAL_INT(21, stats->physicalLines[RCN_LANG_JAVA]); TEST_ASSERT_EQUAL_INT(21, stats->physicalLines[RCN_LANG_C]); TEST_ASSERT_EQUAL_INT(22, stats->words[RCN_TEXT_UNFORMATTED]); + TEST_ASSERT_EQUAL_INT(25, stats->words[RCN_TEXT_MARKDOWN]); TEST_ASSERT_EQUAL_INT(39, stats->words[RCN_LANG_JAVA]); TEST_ASSERT_EQUAL_INT(43, stats->words[RCN_LANG_C]); TEST_ASSERT_EQUAL_INT(122, stats->characters[RCN_TEXT_UNFORMATTED]); + TEST_ASSERT_EQUAL_INT(138, stats->characters[RCN_TEXT_MARKDOWN]); TEST_ASSERT_EQUAL_INT(450, stats->characters[RCN_LANG_JAVA]); TEST_ASSERT_EQUAL_INT(369, stats->characters[RCN_LANG_C]); TEST_ASSERT_EQUAL_INT(122, stats->sourceSize[RCN_TEXT_UNFORMATTED]); + TEST_ASSERT_EQUAL_INT(138, stats->sourceSize[RCN_TEXT_MARKDOWN]); TEST_ASSERT_EQUAL_INT(450, stats->sourceSize[RCN_LANG_JAVA]); TEST_ASSERT_EQUAL_INT(369, stats->sourceSize[RCN_LANG_C]); - TEST_ASSERT_EQUAL_INT(3, stats->count.size); - TEST_ASSERT_EQUAL_INT(3, stats->count.sizeProcessed); + TEST_ASSERT_EQUAL_INT(4, stats->count.size); + TEST_ASSERT_EQUAL_INT(4, stats->count.sizeProcessed); RcnSourceFile* javaFile = &stats->count.files[0]; TEST_ASSERT_EQUAL_STRING("Source.java", javaFile->name); TEST_ASSERT_EQUAL_INT(RCN_FILE_OP_OK, javaFile->status); @@ -333,6 +338,9 @@ void testCountStatisticsAllOperationsWithAllDefaultOptions(void) { RcnSourceFile* textFile = &stats->count.files[2]; TEST_ASSERT_EQUAL_STRING("text.txt", textFile->name); TEST_ASSERT_EQUAL_INT(RCN_FILE_OP_OK, textFile->status); + RcnSourceFile* mdFile = &stats->count.files[3]; + TEST_ASSERT_EQUAL_STRING("text2.md", mdFile->name); + TEST_ASSERT_EQUAL_INT(RCN_FILE_OP_OK, mdFile->status); RcnCountResultGroup* javaResult = &stats->count.results[0]; TEST_ASSERT_TRUE(javaResult->isProcessed); TEST_ASSERT_EQUAL_INT(16, javaResult->logicalLines); @@ -363,6 +371,16 @@ void testCountStatisticsAllOperationsWithAllDefaultOptions(void) { TEST_ASSERT_TRUE(textResult->state.ok); TEST_ASSERT_EQUAL_INT(RCN_ERR_NONE, textResult->state.errorCode); TEST_ASSERT_NULL(textResult->state.errorMessage); + RcnCountResultGroup* mdResult = &stats->count.results[3]; + TEST_ASSERT_TRUE(mdResult->isProcessed); + TEST_ASSERT_EQUAL_INT(0, mdResult->logicalLines); + TEST_ASSERT_EQUAL_INT(10, mdResult->physicalLines); + TEST_ASSERT_EQUAL_INT(25, mdResult->words); + TEST_ASSERT_EQUAL_INT(138, mdResult->characters); + TEST_ASSERT_EQUAL_INT(138, mdResult->sourceSize); + TEST_ASSERT_TRUE(mdResult->state.ok); + TEST_ASSERT_EQUAL_INT(RCN_ERR_NONE, mdResult->state.errorCode); + TEST_ASSERT_NULL(mdResult->state.errorMessage); rcnFreeCountStatistics(stats); } @@ -402,7 +420,7 @@ void testCountStatisticsOperationsWithExplicitOptions(void) { TEST_ASSERT_EQUAL_INT(122, stats->sourceSize[RCN_TEXT_UNFORMATTED]); TEST_ASSERT_EQUAL_INT(450, stats->sourceSize[RCN_LANG_JAVA]); TEST_ASSERT_EQUAL_INT(0, stats->sourceSize[RCN_LANG_C]); - TEST_ASSERT_EQUAL_INT(3, stats->count.size); + TEST_ASSERT_EQUAL_INT(4, stats->count.size); TEST_ASSERT_EQUAL_INT(2, stats->count.sizeProcessed); RcnSourceFile* javaFile = &stats->count.files[0]; TEST_ASSERT_EQUAL_STRING("Source.java", javaFile->name); diff --git a/src/scount/c/print.c b/src/scount/c/print.c index 3975824..12703c4 100644 --- a/src/scount/c/print.c +++ b/src/scount/c/print.c @@ -447,6 +447,9 @@ static void prSummaryRows( case RCN_TEXT_UNFORMATTED: label = "Plain Text"; break; + case RCN_TEXT_MARKDOWN: + label = "Markdown"; + break; case RCN_LANG_C: label = "C"; break; diff --git a/src/scount/tests/functionality/res/expected/mixed.txt b/src/scount/tests/functionality/res/expected/mixed.txt index 18e443d..f094722 100644 --- a/src/scount/tests/functionality/res/expected/mixed.txt +++ b/src/scount/tests/functionality/res/expected/mixed.txt @@ -1,12 +1,14 @@ Directory: mixed -Scanned files: 6 +Scanned files: 8 o---------- File ----------o--- LLC ---o--- PHL ---o--- WRD ---o--- CHR ---o--- SZE ---o | Sample1.java | 3 | 12 | 34 | 233 | 233 | | Sample2.java | 4 | 13 | 38 | 286 | 286 | | sample1.c | 4 | 10 | 29 | 180 | 180 | + | sample1.md | 0 | 1 | 8 | 52 | 52 | | sample1.txt | 0 | 1 | 9 | 52 | 52 | | sample2.c | 5 | 11 | 33 | 219 | 219 | + | sample2.md | 0 | 1 | 8 | 53 | 53 | | sample2.txt | 0 | 2 | 13 | 75 | 75 | o--------------------------o-----------o-----------o-----------o-----------o-----------o @@ -14,10 +16,11 @@ Summary: o-------- Language --------o--- LLC ---o--- PHL ---o--- WRD ---o--- CHR ---o--- SZE ---o | Plain Text | 0 | 3 | 22 | 127 | 127 | + | Markdown | 0 | 2 | 16 | 105 | 105 | | C | 9 | 21 | 62 | 399 | 399 | | Java | 7 | 25 | 72 | 519 | 519 | o==========================o===========o===========o===========o===========o===========o - | Total: | 16 | 49 | 156 | 1045 | 1045 | + | Total: | 16 | 51 | 172 | 1150 | 1150 | o==========================o===========o===========o===========o===========o===========o diff --git a/src/scount/tests/functionality/res/mixed/sample1.md b/src/scount/tests/functionality/res/mixed/sample1.md new file mode 100644 index 0000000..84e1d62 --- /dev/null +++ b/src/scount/tests/functionality/res/mixed/sample1.md @@ -0,0 +1 @@ +This is a first sample with Markdown-formatted text. \ No newline at end of file diff --git a/src/scount/tests/functionality/res/mixed/sample2.md b/src/scount/tests/functionality/res/mixed/sample2.md new file mode 100644 index 0000000..96d51f8 --- /dev/null +++ b/src/scount/tests/functionality/res/mixed/sample2.md @@ -0,0 +1 @@ +This is a second sample with Markdown-formatted text. \ No newline at end of file