Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/lib/c/factories.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ SourceFormatDetection detectSourceFormat(const RcnSourceFile* file) {
|| strcmp(extension, "markdown") == 0) {
detection.isSupportedFormat = true;
detection.format = RCN_TEXT_MARKDOWN;
} else if (strcmp(extension, "json") == 0) {
detection.isSupportedFormat = true;
detection.format = RCN_TEXT_JSON;
} else if (strcmp(extension, "txt") == 0) {
detection.isSupportedFormat = true;
detection.format = RCN_TEXT_UNFORMATTED;
Expand Down
16 changes: 13 additions & 3 deletions src/lib/include/reckon/reckon.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ extern "C" {
* The total number of supported text formats, including
* supported programming languages.
*/
#define RECKON_NUM_SUPPORTED_FORMATS 4
#define RECKON_NUM_SUPPORTED_FORMATS 5

/**
* Macro to create a format option bitmask.
Expand Down Expand Up @@ -145,15 +145,20 @@ typedef enum RcnTextFormat {
*/
RCN_TEXT_MARKDOWN = 1,

/**
* Text formatted in JSON, as found in files with a '.json' extension.
*/
RCN_TEXT_JSON = 2,

/**
* Source files for the C programming language.
*/
RCN_LANG_C = 2,
RCN_LANG_C = 3,

/**
* Source files for the Java programming language.
*/
RCN_LANG_JAVA = 3
RCN_LANG_JAVA = 4

} RcnTextFormat;

Expand Down Expand Up @@ -691,6 +696,11 @@ typedef enum RcnFormatOption {
*/
RCN_OPT_TEXT_MARKDOWN = RECKON_MK_FRMT_OPT(RCN_TEXT_MARKDOWN),

/**
* Option to select statistics for JSON text files.
*/
RCN_OPT_TEXT_JSON = RECKON_MK_FRMT_OPT(RCN_TEXT_JSON),

/**
* Option to select statistics for source code files written in
* the C programming language.
Expand Down
37 changes: 37 additions & 0 deletions src/lib/tests/res/misc/sample.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions src/lib/tests/unit/c/test_statistics.c
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,31 @@ void testCountResultGroupLogicalLineCheckField(void) {
rcnFreeCountStatistics(stats);
}

void testCountResultsJson(void) {
char* path = RECKON_TEST_PATH_RES_BASE "/misc/sample.json";
RcnCountStatistics* stats = rcnCreateCountStatistics(path);
RcnStatOptions options = {
.formats = RCN_OPT_TEXT_JSON
};

rcnCount(stats, options);

TEST_ASSERT_EQUAL_INT(1, stats->count.size);
RcnSourceFile* file = &stats->count.files[0];
RcnCountResultGroup* result = &stats->count.results[0];
TEST_ASSERT_TRUE(result->state.ok);
TEST_ASSERT_EQUAL_INT(RCN_ERR_NONE, result->state.errorCode);
TEST_ASSERT_NULL(result->state.errorMessage);
TEST_ASSERT_EQUAL_STRING("sample.json", file->name);
TEST_ASSERT_TRUE(result->isProcessed);
TEST_ASSERT_EQUAL_INT(0, result->logicalLines);
TEST_ASSERT_EQUAL_INT(37, result->physicalLines);
TEST_ASSERT_EQUAL_INT(59, result->words);
TEST_ASSERT_EQUAL_INT(561, result->characters);
TEST_ASSERT_EQUAL_INT(561, result->sourceSize);
rcnFreeCountStatistics(stats);
}

// NOLINTEND(readability-magic-numbers)

int main(void) {
Expand All @@ -255,5 +280,6 @@ int main(void) {
RUN_TEST(testCountWhenFileHasUnsupportedFormat);
RUN_TEST(testCountWithMultipleFilesWhenOneFileHasError);
RUN_TEST(testCountResultGroupLogicalLineCheckField);
RUN_TEST(testCountResultsJson);
return UNITY_END();
}
3 changes: 3 additions & 0 deletions src/scount/c/print.c
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,9 @@ static void prSummaryRows(
case RCN_TEXT_MARKDOWN:
label = "Markdown";
break;
case RCN_TEXT_JSON:
label = "JSON";
break;
case RCN_LANG_C:
label = "C";
hasLogicalLines = true;
Expand Down
7 changes: 5 additions & 2 deletions src/scount/tests/functionality/res/expected/mixed.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions src/scount/tests/functionality/res/mixed/sample1.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions src/scount/tests/functionality/res/mixed/sample2.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.