Cleaned up collision unit tests (posotive cases)

This commit is contained in:
Tristan B. Velloza Kildaire 2021-04-01 21:00:48 +02:00
parent 4fbde01073
commit b97fdba551
2 changed files with 61 additions and 1 deletions

View File

@ -518,7 +518,52 @@ unittest
}
catch (CollidingNameException e)
{
/* Make sure the member y.y collided with root container (module) y */
/* Make sure the member y.a.b.c.y collided with root container (module) y */
assert(e.defined == container);
}
}
/* Test name colliding with container name (3/3) [container (non-module), nested collider] */
unittest
{
import std.file;
import std.stdio;
import compiler.lexer;
import compiler.parsing.core;
string sourceFile = "source/tlang/testing/collide_container_non_module.t";
File sourceFileFile;
sourceFileFile.open(sourceFile); /* TODO: Error handling with ANY file I/O */
ulong fileSize = sourceFileFile.size();
byte[] fileBytes;
fileBytes.length = fileSize;
fileBytes = sourceFileFile.rawRead(fileBytes);
sourceFileFile.close();
string sourceCode = cast(string) fileBytes;
Lexer currentLexer = new Lexer(sourceCode);
currentLexer.performLex();
Parser parser = new Parser(currentLexer.getTokens());
Module modulle = parser.parse();
TypeChecker typeChecker = new TypeChecker(modulle);
/* Setup testing variables */
Entity container = typeChecker.getResolver().resolveBest(typeChecker.getModule, "a.b.c");
Entity colliderMember = typeChecker.getResolver().resolveBest(typeChecker.getModule, "a.b.c.c");
try
{
/* Perform test */
typeChecker.beginCheck();
/* Shouldn't reach here, collision exception MUST occur */
assert(false);
}
catch (CollidingNameException e)
{
/* Make sure the member a.b.c.c collided with a.b.c container */
assert(e.defined == container);
}
}

View File

@ -0,0 +1,15 @@
module y;
class a
{
class b
{
class c
{
class c
{
}
}
}
}