Skip to content

Commit

Permalink
Add Halstead test for Rust grammar
Browse files Browse the repository at this point in the history
  • Loading branch information
Luni-4 committed Mar 23, 2021
1 parent 77f997a commit 4c17538
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/getter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ impl Getter for RustCode {
| LT | GT | AMP | MutableSpecifier | DOTDOT | DOTDOTEQ | DASH | AMPAMP | PIPEPIPE
| PIPE | CARET | EQEQ | BANGEQ | LTEQ | GTEQ | LTLT | GTGT | SLASH | PERCENT
| PLUSEQ | DASHEQ | STAREQ | SLASHEQ | PERCENTEQ | AMPEQ | PIPEEQ | CARETEQ
| LTLTEQ | GTGTEQ | Move | DOT | PrimitiveType => HalsteadType::Operator,
| LTLTEQ | GTGTEQ | Move | DOT | PrimitiveType | Fn | SEMI => HalsteadType::Operator,
Identifier | StringLiteral | RawStringLiteral | IntegerLiteral | FloatLiteral
| BooleanLiteral | Zelf | CharLiteral | UNDERSCORE => HalsteadType::Operand,
_ => HalsteadType::Unknown,
Expand Down
20 changes: 20 additions & 0 deletions src/metrics/halstead.rs
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,26 @@ mod tests {
);
}

#[test]
fn rust_operators_and_operands() {
check_metrics!(
"fn main() {
let a = 5; let b = 5; let c = 5;
let avg = (a + b + c) / 3;
println!(\"{}\", avg);
}",
"foo.rs",
RustParser,
halstead,
[
(u_operators, 9, usize), // fn, (), {}, let, =, ,, +, /, ;
(operators, 22, usize),
(u_operands, 9, usize), // main, a, b, c, avg, 5, 3, println, "{}"
(operands, 15, usize)
]
);
}

#[test]
fn python_wrong_operators() {
check_metrics!(
Expand Down

0 comments on commit 4c17538

Please sign in to comment.