From 5b57ed32beed2ffc8ef84cc43619f1a4775b7bd7 Mon Sep 17 00:00:00 2001 From: Miles Liu Date: Tue, 4 Oct 2022 21:20:18 +0800 Subject: [PATCH] Add C++ language code sample for tests --- pkg/analyzer/analyzer_test.go | 15 +++++++++++++++ pkg/scanner/scanner_test.go | 13 ++++++++++--- test/fixtures/code_samples/_main.cc | 17 +++++++++++++++++ 3 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 test/fixtures/code_samples/_main.cc diff --git a/pkg/analyzer/analyzer_test.go b/pkg/analyzer/analyzer_test.go index aa87259..b7e70e2 100644 --- a/pkg/analyzer/analyzer_test.go +++ b/pkg/analyzer/analyzer_test.go @@ -52,6 +52,11 @@ func TestMatchingFiles(t *testing.T) { Extension: ".c", Language: "C", }, + { + FilePath: filepath.Join(codeSamplesDir, "_main.cc"), + Extension: ".cc", + Language: "C++", + }, { FilePath: filepath.Join(codeSamplesDir, "index.html"), Extension: ".html", @@ -89,6 +94,11 @@ func TestMatchingFiles(t *testing.T) { Extension: ".c", Language: "C", }, + { + FilePath: filepath.Join(codeSamplesDir, "_main.cc"), + Extension: ".cc", + Language: "C++", + }, { FilePath: filepath.Join(codeSamplesDir, "index.html"), Extension: ".html", @@ -121,6 +131,11 @@ func TestMatchingFiles(t *testing.T) { Extension: ".c", Language: "C", }, + { + FilePath: filepath.Join(codeSamplesDir, "_main.cc"), + Extension: ".cc", + Language: "C++", + }, { FilePath: filepath.Join(codeSamplesDir, "index.html"), Extension: ".html", diff --git a/pkg/scanner/scanner_test.go b/pkg/scanner/scanner_test.go index 492c8a8..a2597c4 100644 --- a/pkg/scanner/scanner_test.go +++ b/pkg/scanner/scanner_test.go @@ -37,27 +37,34 @@ func TestScan(t *testing.T) { }, { Metadata: files[1], + Lines: 17, + CodeLines: 10, + BlankLines: 5, + Comments: 2, + }, + { + Metadata: files[2], Lines: 167, CodeLines: 137, BlankLines: 14, Comments: 16, }, { - Metadata: files[2], + Metadata: files[3], Lines: 20, CodeLines: 9, BlankLines: 5, Comments: 6, }, { - Metadata: files[3], + Metadata: files[4], Lines: 13, CodeLines: 8, BlankLines: 3, Comments: 2, }, { - Metadata: files[4], + Metadata: files[5], Lines: 13, CodeLines: 8, BlankLines: 3, diff --git a/test/fixtures/code_samples/_main.cc b/test/fixtures/code_samples/_main.cc new file mode 100644 index 0000000..7668ef5 --- /dev/null +++ b/test/fixtures/code_samples/_main.cc @@ -0,0 +1,17 @@ +#include + +using namespace std; + +// main function +int main(int argc, char *argv[]) { + std::cout << "Hello World!" << std::endl; + + auto a = 2; + auto b = 3; + // Sum a + b + auto total = a + b; + + std::cout << total << std::endl; + + return 0; +}