Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java LoC metric #694

Merged
Merged
Prev Previous commit
Next Next commit
Adds ternary lloc to test
  • Loading branch information
dburriss committed Mar 22, 2022
commit aa42b7c5c28bf9b2a8b80a5516aec68cd42a3b53
27 changes: 21 additions & 6 deletions src/metrics/loc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -840,7 +840,6 @@ impl Loc for JavaCode {
| ReturnStatement
| Statement
| SwitchStatement
| TernaryExpression
| ThrowStatement
| TryStatement
| UpdateExpression => {
Expand Down Expand Up @@ -2014,6 +2013,21 @@ mod tests {
);
}

#[test]
fn java_module_sloc() {
check_metrics!(
"module helloworld{
exports com.test;
}",
"foo.java",
JavaParser,
loc,
[
(sloc, 3, usize), // The number of lines is 3
]
);
}

#[test]
fn java_single_ploc() {
check_metrics!(
Expand Down Expand Up @@ -2213,17 +2227,18 @@ mod tests {

class HelloWorldApp {
public void main(String[] args) {
System.out.println(\"Hello World!\"); // Display the string. Only statement. +1 lloc
String message = args.length == 0 ? \"Hello empty world\" : \"Hello world\"; // +2 lloc : 1 var assignment + binary exp
dburriss marked this conversation as resolved.
Show resolved Hide resolved
System.out.println(message); // Display the string. +1 lloc
}
}",
"foo.java",
JavaParser,
loc,
[
(sloc, 11, usize), // The number of lines is 11
(ploc, 6, usize), // The number of code lines is 6
(lloc, 1, usize), // The number of statements is 1
(cloc, 5, usize), // The number of comments is 5
(sloc, 12, usize), // The number of lines is 11
(ploc, 7, usize), // The number of code lines is 7
(lloc, 3, usize), // The number of statements is 3
(cloc, 6, usize), // The number of comments is 6
(blank, 1, usize) // The number of blank lines is 1
]
);
Expand Down