From 28ab54e8521fbbff91a007a994fe66332913756b Mon Sep 17 00:00:00 2001 From: "Tristan B. Kildaire" Date: Tue, 2 Mar 2021 23:27:32 +0200 Subject: [PATCH] Added more uni tests --- source/tlang/commandline/lexer.d | 106 ++++++++++++++++--------------- 1 file changed, 55 insertions(+), 51 deletions(-) diff --git a/source/tlang/commandline/lexer.d b/source/tlang/commandline/lexer.d index 79083df..aa1945e 100644 --- a/source/tlang/commandline/lexer.d +++ b/source/tlang/commandline/lexer.d @@ -4,57 +4,6 @@ import std.container.slist; import gogga; 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 { /* The source to be lexed */ @@ -201,4 +150,59 @@ 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", ";"]); } \ No newline at end of file