From c1f142eb05bf339c77e51844b6820e094fcfeb83 Mon Sep 17 00:00:00 2001 From: Luni-4 Date: Wed, 1 Jul 2020 13:43:54 +0200 Subject: [PATCH 1/4] Refactor loc tests --- src/metrics/loc.rs | 24 +++--------------------- 1 file changed, 3 insertions(+), 21 deletions(-) diff --git a/src/metrics/loc.rs b/src/metrics/loc.rs index b386f0164..224d8460b 100644 --- a/src/metrics/loc.rs +++ b/src/metrics/loc.rs @@ -377,7 +377,7 @@ mod tests { use super::*; #[test] - fn test_blank_python() { + fn test_blank() { check_metrics!( "\na = 42\n\n", "foo.py", @@ -385,10 +385,7 @@ mod tests { loc, [(blank, 1, usize)] ); - } - #[test] - fn test_blank_rust() { check_metrics!( "\nlet a = 42;\n\n", "foo.rs", @@ -404,10 +401,7 @@ mod tests { loc, [(blank, 0, usize)] ); - } - #[test] - fn test_blank_c() { check_metrics!( "\nint a = 42;\n\n", "foo.c", @@ -418,7 +412,7 @@ mod tests { } #[test] - fn test_cloc_python() { + fn test_cloc() { check_metrics!( "\"\"\"Block comment\nBlock comment\n\"\"\"\n # Line Comment\na = 42 # Line Comment\n", @@ -427,10 +421,7 @@ mod tests { loc, [(cloc, 5, usize)] ); - } - #[test] - fn test_cloc_rust() { check_metrics!( "/*Block comment\nBlock Comment*/\n//Line Comment\n/*Block Comment*/ let a = 42; // Line Comment\n", "foo.rs", @@ -438,10 +429,7 @@ mod tests { loc, [(cloc, 5, usize)] ); - } - #[test] - fn test_cloc_c() { check_metrics!( "/*Block comment\nBlock Comment*/\n//Line Comment\n/*Block Comment*/ int a = 42; // Line Comment\n", "foo.c", @@ -452,7 +440,7 @@ mod tests { } #[test] - fn test_lloc_python() { + fn test_lloc() { check_metrics!( "for x in range(0,42):\n if x % 2 == 0:\n @@ -462,10 +450,7 @@ mod tests { loc, [(lloc, 3, usize)] ); - } - #[test] - fn test_lloc_rust() { check_metrics!( "for x in 0..42 {\n if x % 2 == 0 {\n @@ -491,10 +476,7 @@ mod tests { loc, [(lloc, 3, usize)] ); - } - #[test] - fn test_lloc_c() { check_metrics!( "for (;;)\n break;\n", From b1cb8de3f361d66c93682f4855f026550eabaa39 Mon Sep 17 00:00:00 2001 From: Luni-4 Date: Wed, 1 Jul 2020 13:44:09 +0200 Subject: [PATCH 2/4] Add a general loc test --- src/metrics/loc.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/metrics/loc.rs b/src/metrics/loc.rs index 224d8460b..91c5832f8 100644 --- a/src/metrics/loc.rs +++ b/src/metrics/loc.rs @@ -486,4 +486,26 @@ mod tests { [(lloc, 2, usize)] ); } + + #[test] + fn test_general_loc() { + check_metrics!( + "def func(a, + b, + c): + print(a) + print(b) + print(c)\n", + "foo.py", + PythonParser, + loc, + [ + (sloc, 6, usize), + (ploc, 6, usize), + (lloc, 3, usize), + (cloc, 0, usize), + (blank, 0, usize) + ] + ); + } } From b30a61dd5f4622c6919fc255812d99d52acc5e91 Mon Sep 17 00:00:00 2001 From: Luni-4 Date: Wed, 1 Jul 2020 15:44:48 +0200 Subject: [PATCH 3/4] Uniform loc tests --- src/metrics/loc.rs | 53 +++++++++++++++++++++++++++++----------------- 1 file changed, 34 insertions(+), 19 deletions(-) diff --git a/src/metrics/loc.rs b/src/metrics/loc.rs index 91c5832f8..ae8ac1a20 100644 --- a/src/metrics/loc.rs +++ b/src/metrics/loc.rs @@ -379,7 +379,9 @@ mod tests { #[test] fn test_blank() { check_metrics!( - "\na = 42\n\n", + " + a = 42 + \n", "foo.py", PythonParser, loc, @@ -387,7 +389,9 @@ mod tests { ); check_metrics!( - "\nlet a = 42;\n\n", + " + let a = 42; + \n", "foo.rs", RustParser, loc, @@ -403,7 +407,9 @@ mod tests { ); check_metrics!( - "\nint a = 42;\n\n", + " + int a = 42; + \n", "foo.c", CppParser, loc, @@ -414,8 +420,11 @@ mod tests { #[test] fn test_cloc() { check_metrics!( - "\"\"\"Block comment\nBlock comment\n\"\"\"\n - # Line Comment\na = 42 # Line Comment\n", + "\"\"\"Block comment + Block comment + \"\"\" + # Line Comment + a = 42 # Line Comment\n", "foo.py", PythonParser, loc, @@ -423,7 +432,10 @@ mod tests { ); check_metrics!( - "/*Block comment\nBlock Comment*/\n//Line Comment\n/*Block Comment*/ let a = 42; // Line Comment\n", + "/*Block comment + Block Comment*/ + //Line Comment + /*Block Comment*/ let a = 42; // Line Comment\n", "foo.rs", RustParser, loc, @@ -431,7 +443,10 @@ mod tests { ); check_metrics!( - "/*Block comment\nBlock Comment*/\n//Line Comment\n/*Block Comment*/ int a = 42; // Line Comment\n", + "/*Block comment + Block Comment*/ + //Line Comment + /*Block Comment*/ int a = 42; // Line Comment\n", "foo.c", CppParser, loc, @@ -442,8 +457,8 @@ mod tests { #[test] fn test_lloc() { check_metrics!( - "for x in range(0,42):\n - if x % 2 == 0:\n + "for x in range(0,42): + if x % 2 == 0: print(x)\n", "foo.py", PythonParser, @@ -452,10 +467,10 @@ mod tests { ); check_metrics!( - "for x in 0..42 {\n - if x % 2 == 0 {\n - println!(\"{}\", x);\n - }\n + "for x in 0..42 { + if x % 2 == 0 { + println!(\"{}\", x); + } }\n", "foo.rs", RustParser, @@ -465,11 +480,11 @@ mod tests { // LLOC returns three because there is an empty Rust statement check_metrics!( - "let a = 42;\n - if true {\n - 42\n - } else {\n - 43\n + "let a = 42; + if true { + 42 + } else { + 43 };\n", "foo.rs", RustParser, @@ -478,7 +493,7 @@ mod tests { ); check_metrics!( - "for (;;)\n + "for (;;) break;\n", "foo.c", CppParser, From db0daf330a5299fb261ccb39c3bc46505aeb6904 Mon Sep 17 00:00:00 2001 From: Luni-4 Date: Thu, 2 Jul 2020 11:30:18 +0200 Subject: [PATCH 4/4] Clarify tests --- src/metrics/loc.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/metrics/loc.rs b/src/metrics/loc.rs index ae8ac1a20..6d04259f6 100644 --- a/src/metrics/loc.rs +++ b/src/metrics/loc.rs @@ -515,11 +515,11 @@ mod tests { PythonParser, loc, [ - (sloc, 6, usize), - (ploc, 6, usize), - (lloc, 3, usize), - (cloc, 0, usize), - (blank, 0, usize) + (sloc, 6, usize), // The number of lines is 6 + (ploc, 6, usize), // The number of code lines is 6 + (lloc, 3, usize), // The number of statements is 3 (print) + (cloc, 0, usize), // The number of comments is 0 + (blank, 0, usize) // The number of blank lines is 0 ] ); }