Skip to content

Commit

Permalink
Add more test cases (for whitespace, mainly)
Browse files Browse the repository at this point in the history
  • Loading branch information
merkrafter committed Nov 3, 2019
1 parent 90297f4 commit 266929c
Showing 1 changed file with 59 additions and 2 deletions.
61 changes: 59 additions & 2 deletions src/com/merkrafter/lexing/ScannerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,59 @@ void scanSingleIdentifier() {
shouldScan(programCode, expectedTokenList);
}

/**
* The scanner should be able to handle a string containing a single identifier that also has
* numbers.
*/
@org.junit.jupiter.api.Test
void scanSingleIdentifierWithNumbers() {
final String programCode = "x1";
final TokenType[] expectedTokenList = {IDENT, EOF};
shouldScan(programCode, expectedTokenList);
}

/**
* The scanner should be able to handle a string containing a single identifier that has mixed
* case letters.
*/
@org.junit.jupiter.api.Test
void scanSingleIdentifierWithMixedCase() {
final String programCode = "xXcoolNameXx";
final TokenType[] expectedTokenList = {IDENT, EOF};
shouldScan(programCode, expectedTokenList);
}

/**
* The scanner should be able to handle an assignment operation where the right side is a
* complex calculation including all four basic arithmetic operations as well as parentheses.
* The program code makes extended use of spaces around operators.
*/
@org.junit.jupiter.api.Test
void scanAssignment() {
final String programCode = "int result = a+(b-c)*d/e;";
void scanAssignmentWithSpaces() {
final String programCode = "int result = a + ( b - c ) * d / e;";
final TokenType[] expectedTokenList = {IDENT, IDENT, ASSIGN, IDENT, PLUS, L_PAREN, IDENT, MINUS, IDENT, R_PAREN, TIMES, IDENT, DIVIDE, IDENT, SEMICOLON, EOF};
shouldScan(programCode, expectedTokenList);
}

/**
* The scanner should be able to handle a simple assignment operation.
* The program code makes extended use of whitespace (spaces, tabs and newlines).
*/
@org.junit.jupiter.api.Test
void scanSimpleAssignmentWithWhitespace() {
final String programCode = "int\n\t a \n=\n5\t\t\t ;";
final TokenType[] expectedTokenList = {IDENT, IDENT, ASSIGN, NUMBER, SEMICOLON, EOF};
shouldScan(programCode, expectedTokenList);
}

/**
* The scanner should be able to handle an assignment operation where the right side is a
* complex calculation including all four basic arithmetic operations as well as parentheses.
* The program code only has mandatory whitespace.
*/
@org.junit.jupiter.api.Test
void scanAssignmentWithoutWhitespace() {
final String programCode = "int result=a+(b-c)*d/e;";
final TokenType[] expectedTokenList = {IDENT, IDENT, ASSIGN, IDENT, PLUS, L_PAREN, IDENT, MINUS, IDENT, R_PAREN, TIMES, IDENT, DIVIDE, IDENT, SEMICOLON, EOF};
shouldScan(programCode, expectedTokenList);
}
Expand All @@ -75,6 +121,17 @@ void scanAndIgnoreComments() {
shouldScan(programCode, expectedTokenList);
}

/**
* The scanner should be able to handle asterisks in comments. That is, it should not stop
* processing the comment then.
*/
@org.junit.jupiter.api.Test
void scanAndIgnoreAsterisksInComments() {
final String programCode = "/***/";
final TokenType[] expectedTokenList = {EOF};
shouldScan(programCode, expectedTokenList);
}

/**
* The scanner should be able to handle a basic main function including an array as arguments.
* This test includes the detection of square brackets and braces.
Expand Down

0 comments on commit 266929c

Please sign in to comment.