Fixed bug (and added corresponding unit test) whereby the combinator check would fail if the first element was at end-of-source
parent
28ab54e852
commit
68f9bb6523
|
@ -61,12 +61,12 @@ public final class Lexer
|
||||||
|
|
||||||
/* Check if we need to do combinators (e.g. for ||, &&) */
|
/* Check if we need to do combinators (e.g. for ||, &&) */
|
||||||
/* TODO: Second operand in condition out of bounds */
|
/* TODO: Second operand in condition out of bounds */
|
||||||
if(currentChar == '|' && sourceCode[position+1] == '|')
|
if(currentChar == '|' && (position+1) != sourceCode.length && sourceCode[position+1] == '|')
|
||||||
{
|
{
|
||||||
splitterToken = "||";
|
splitterToken = "||";
|
||||||
position += 2;
|
position += 2;
|
||||||
}
|
}
|
||||||
else if(currentChar == '&' && sourceCode[position+1] == '&')
|
else if(currentChar == '&' && (position+1) != sourceCode.length && sourceCode[position+1] == '&')
|
||||||
{
|
{
|
||||||
splitterToken = "&&";
|
splitterToken = "&&";
|
||||||
position += 2;
|
position += 2;
|
||||||
|
@ -185,6 +185,17 @@ unittest
|
||||||
assert(currentLexer.getTokens() == ["hello", "\"world\"","||"]);
|
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` */
|
/* Test input: ` hello` */
|
||||||
unittest
|
unittest
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue