#104, add support for ternary expressions

This commit is contained in:
Basile Burg 2016-12-21 00:24:31 +01:00
parent b461b9a12f
commit 3428a0f567
No known key found for this signature in database
GPG Key ID: 1868039F415CB8CF
1 changed files with 22 additions and 0 deletions

View File

@ -271,6 +271,15 @@ private final class HalsteadMetric: ASTVisitor
expr.accept(this);
}
override void visit(const(TernaryExpression) expr)
{
if (expr.orOrExpression)
++operators["if"];
if (expr.expression)
++operators["else"];
expr.accept(this);
}
override void visit(const(TypeidExpression) expr)
{
++operators["typeid"];
@ -869,6 +878,19 @@ unittest
assert(r.operatorsKinds == 4);
}
unittest
{
Function r =
q{
void foo()
{
a = true ? 0 : 1;
}
}.test;
assert(r.operandsKinds == 4);
assert(r.operatorsKinds == 3);
}
version(none) unittest
{
// TODO: detect function call w/o parens