From 8faf426c1a6f47a2da1b12a993590e7ad23a344f Mon Sep 17 00:00:00 2001 From: Cansin Yildiz Date: Mon, 10 Apr 2017 12:23:20 -0700 Subject: [PATCH] Add triple extension support. This becomes handy especially when used in confjunction with --read-lang-def option. --- Unix/t/01_opts.t | 6 ++++++ cloc | 5 +++++ tests/inputs/custom.triple.extension.js | 1 + tests/inputs/triple_lang_def.txt | 6 ++++++ tests/outputs/custom.triple.extension.js.yaml | 21 +++++++++++++++++++++ 5 files changed, 39 insertions(+) create mode 100644 tests/inputs/custom.triple.extension.js create mode 100644 tests/inputs/triple_lang_def.txt create mode 100644 tests/outputs/custom.triple.extension.js.yaml diff --git a/Unix/t/01_opts.t b/Unix/t/01_opts.t index 7df7e6c..4153147 100755 --- a/Unix/t/01_opts.t +++ b/Unix/t/01_opts.t @@ -124,6 +124,12 @@ my @Tests = ( 'args' => '--read-lang-def X fake.thy', 'ref' => '../tests/outputs/issues/166/fake.thy.yaml', }, + { + 'name' => '--read-lang-def w/triple_extension', + 'cd' => '../tests/inputs', + 'args' => '--read-lang-def triple_lang_def.txt custom.triple.extension.js', + 'ref' => '../tests/outputs/custom.triple.extension.js.yaml', + }, ); # Create test input for issue #132 which needs data not in the git repo. diff --git a/cloc b/cloc index 04d2927..9abb1b2 100755 --- a/cloc +++ b/cloc @@ -4063,6 +4063,11 @@ sub classify_file { # {{{1 $extension = lc $extension if $ON_WINDOWS; unshift @extension_list, $extension; # examine double ext first } + if ($file =~ /\.([^\.]+\.[^\.]+\.[^\.]+)$/) { # has a triple extension + my $extension = $1; + $extension = lc $extension if $ON_WINDOWS; + unshift @extension_list, $extension; # examine triple ext first + } foreach my $extension (@extension_list) { if ($Not_Code_Extension{$extension} and !$Forced_Extension{$extension}) { diff --git a/tests/inputs/custom.triple.extension.js b/tests/inputs/custom.triple.extension.js new file mode 100644 index 0000000..be707cd --- /dev/null +++ b/tests/inputs/custom.triple.extension.js @@ -0,0 +1 @@ +js 4 diff --git a/tests/inputs/triple_lang_def.txt b/tests/inputs/triple_lang_def.txt new file mode 100644 index 0000000..c87144d --- /dev/null +++ b/tests/inputs/triple_lang_def.txt @@ -0,0 +1,6 @@ +Custom Triple JS + filter call_regexp_common C++ + filter remove_inline //.*$ + extension triple.extension.js + 3rd_gen_scale 1.48 + end_of_line_continuation \\$ diff --git a/tests/outputs/custom.triple.extension.js.yaml b/tests/outputs/custom.triple.extension.js.yaml new file mode 100644 index 0000000..5889005 --- /dev/null +++ b/tests/outputs/custom.triple.extension.js.yaml @@ -0,0 +1,21 @@ +--- +# github.com/AlDanial/cloc +header : + cloc_url : github.com/AlDanial/cloc + cloc_version : 1.67 + elapsed_seconds : 0.00475001335144043 + n_files : 1 + n_lines : 22 + files_per_second : 210.525724037545 + lines_per_second : 4631.56592882598 + report_file : glossary.json.yaml +Custom Triple JS : + nFiles: 1 + blank: 0 + comment: 0 + code: 1 +SUM: + blank: 0 + comment: 0 + code: 1 + nFiles: 1