Added more uni tests
parent
a7c0d37a01
commit
28ab54e852
|
@ -4,57 +4,6 @@ import std.container.slist;
|
||||||
import gogga;
|
import gogga;
|
||||||
import std.conv : to;
|
import std.conv : to;
|
||||||
|
|
||||||
/* Test input: `hello "world";` */
|
|
||||||
unittest
|
|
||||||
{
|
|
||||||
import std.algorithm.comparison;
|
|
||||||
string sourceCode = "hello \"world\";";
|
|
||||||
Lexer currentLexer = new Lexer(sourceCode);
|
|
||||||
currentLexer.performLex();
|
|
||||||
gprintln("Collected "~to!(string)(currentLexer.getTokens()));
|
|
||||||
assert(currentLexer.getTokens() == ["hello", "\"world\"",";"]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Test input: `hello "world"|| ` */
|
|
||||||
unittest
|
|
||||||
{
|
|
||||||
import std.algorithm.comparison;
|
|
||||||
string sourceCode = "hello \"world\"|| ";
|
|
||||||
Lexer currentLexer = new Lexer(sourceCode);
|
|
||||||
currentLexer.performLex();
|
|
||||||
gprintln("Collected "~to!(string)(currentLexer.getTokens()));
|
|
||||||
assert(currentLexer.getTokens() == ["hello", "\"world\"","||"]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Test input: `hello "world"||` */
|
|
||||||
unittest
|
|
||||||
{
|
|
||||||
import std.algorithm.comparison;
|
|
||||||
string sourceCode = "hello \"world\"||";
|
|
||||||
Lexer currentLexer = new Lexer(sourceCode);
|
|
||||||
currentLexer.performLex();
|
|
||||||
gprintln("Collected "~to!(string)(currentLexer.getTokens()));
|
|
||||||
assert(currentLexer.getTokens() == ["hello", "\"world\"","||"]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Test input: `hello "world";` */
|
|
||||||
unittest
|
|
||||||
{
|
|
||||||
import std.algorithm.comparison;
|
|
||||||
string sourceCode = "hello \"world\";";
|
|
||||||
Lexer currentLexer = new Lexer(sourceCode);
|
|
||||||
currentLexer.performLex();
|
|
||||||
gprintln("Collected "~to!(string)(currentLexer.getTokens()));
|
|
||||||
assert(currentLexer.getTokens() == ["hello", "\"world\"",";"]);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// string sourceCode = "hello \"world\"|| ";
|
|
||||||
//string sourceCode = "hello \"world\"||"; /* TODO: Implement this one */
|
|
||||||
// string sourceCode = "hello;";
|
|
||||||
|
|
||||||
public final class Lexer
|
public final class Lexer
|
||||||
{
|
{
|
||||||
/* The source to be lexed */
|
/* The source to be lexed */
|
||||||
|
@ -202,3 +151,58 @@ public final class Lexer
|
||||||
character == '|' || character == '^' || character == '!';
|
character == '|' || character == '^' || character == '!';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Test input: `hello "world";` */
|
||||||
|
unittest
|
||||||
|
{
|
||||||
|
import std.algorithm.comparison;
|
||||||
|
string sourceCode = "hello \"world\";";
|
||||||
|
Lexer currentLexer = new Lexer(sourceCode);
|
||||||
|
currentLexer.performLex();
|
||||||
|
gprintln("Collected "~to!(string)(currentLexer.getTokens()));
|
||||||
|
assert(currentLexer.getTokens() == ["hello", "\"world\"",";"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Test input: `hello "world"|| ` */
|
||||||
|
unittest
|
||||||
|
{
|
||||||
|
import std.algorithm.comparison;
|
||||||
|
string sourceCode = "hello \"world\"|| ";
|
||||||
|
Lexer currentLexer = new Lexer(sourceCode);
|
||||||
|
currentLexer.performLex();
|
||||||
|
gprintln("Collected "~to!(string)(currentLexer.getTokens()));
|
||||||
|
assert(currentLexer.getTokens() == ["hello", "\"world\"","||"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Test input: `hello "world"||` */
|
||||||
|
unittest
|
||||||
|
{
|
||||||
|
import std.algorithm.comparison;
|
||||||
|
string sourceCode = "hello \"world\"||";
|
||||||
|
Lexer currentLexer = new Lexer(sourceCode);
|
||||||
|
currentLexer.performLex();
|
||||||
|
gprintln("Collected "~to!(string)(currentLexer.getTokens()));
|
||||||
|
assert(currentLexer.getTokens() == ["hello", "\"world\"","||"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Test input: ` hello` */
|
||||||
|
unittest
|
||||||
|
{
|
||||||
|
import std.algorithm.comparison;
|
||||||
|
string sourceCode = " hello";
|
||||||
|
Lexer currentLexer = new Lexer(sourceCode);
|
||||||
|
currentLexer.performLex();
|
||||||
|
gprintln("Collected "~to!(string)(currentLexer.getTokens()));
|
||||||
|
assert(currentLexer.getTokens() == ["hello"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Test input: `hello;` */
|
||||||
|
unittest
|
||||||
|
{
|
||||||
|
import std.algorithm.comparison;
|
||||||
|
string sourceCode = " hello;";
|
||||||
|
Lexer currentLexer = new Lexer(sourceCode);
|
||||||
|
currentLexer.performLex();
|
||||||
|
gprintln("Collected "~to!(string)(currentLexer.getTokens()));
|
||||||
|
assert(currentLexer.getTokens() == ["hello", ";"]);
|
||||||
|
}
|
Loading…
Reference in New Issue