Skip to content

Commit

Permalink
TypeChecker (unittests)
Browse files Browse the repository at this point in the history
- Added a negative test case for the unused variables detection mechanism
  • Loading branch information
deavmi committed Nov 5, 2023
1 parent 54ce4be commit ecc07a0
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions source/tlang/compiler/typecheck/core.d
Original file line number Diff line number Diff line change
Expand Up @@ -3686,4 +3686,32 @@ unittest
Variable unusedVarActual = unusedVars[0];
Variable unusedVarExpected = cast(Variable)tc.getResolver().resolveBest(tc.getModule(), "j");
assert(unusedVarActual is unusedVarExpected);
}

/**
* Tests the unused variable detection mechanism
*
* Case: Negative (unused variables do NOT exist)
* Source file: source/tlang/testing/unused_vars_none.t
*/
unittest
{
// Dummy field out
File fileOutDummy;
import tlang.compiler.core;

string sourceFile = "source/tlang/testing/unused_vars_none.t";


Compiler compiler = new Compiler(gibFileData(sourceFile), fileOutDummy);
compiler.doLex();
compiler.doParse();
compiler.doTypeCheck();
TypeChecker tc = compiler.getTypeChecker();

/**
* There should be 0 unused variables
*/
Variable[] unusedVars = tc.getUnusedVariables();
assert(unusedVars.length == 0);
}

0 comments on commit ecc07a0

Please sign in to comment.