Skip to content

Commit

Permalink
added several more specific test files
Browse files Browse the repository at this point in the history
  • Loading branch information
andreas-eberle committed Nov 9, 2014
1 parent 140720c commit ed4de2d
Show file tree
Hide file tree
Showing 21 changed files with 108 additions and 3 deletions.
3 changes: 1 addition & 2 deletions Compiler/src/compiler/parser/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,7 @@ private void parseClassMember() throws ParserException, IOException {
throw new ParserException(token, TokenType.LP);
}
token = tokenSupplier.getNextToken();
if (token.getType() != TokenType.IDENTIFIER
|| token.getSymbol().getValue().equals("String") == false) {
if (token.getType() != TokenType.IDENTIFIER || !token.getSymbol().getValue().equals("String")) {
throw new ParserException(token, TokenType.IDENTIFIER);
}
token = tokenSupplier.getNextToken();
Expand Down
14 changes: 14 additions & 0 deletions Compiler/testdata/parser5/methods/MissingBody.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* comma after last parameter
*/

class Error {

public method(int a, int b)

public method2(int a, int b) {

}


}
11 changes: 11 additions & 0 deletions Compiler/testdata/parser5/methods/MissingReturnType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* comma after last parameter
*/

class Error {

public missingReturnType(int a, int b)
{
}

}
1 change: 1 addition & 0 deletions Compiler/testdata/parser5/methods/MissingReturnType.parser
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* comma after last parameter
*/

class Error {

public void missingRightParanthesis(int a, int b
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0
11 changes: 11 additions & 0 deletions Compiler/testdata/parser5/methods/main/MissingMainName.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* comma after last parameter
*/

class Error {


public static void (String[] args{

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0
11 changes: 11 additions & 0 deletions Compiler/testdata/parser5/methods/main/MissingParameterMain.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* comma after last parameter
*/

class Error {


public static void main(){

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0
11 changes: 11 additions & 0 deletions Compiler/testdata/parser5/methods/main/MissingReturnTypeMain.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* comma after last parameter
*/

class Error {

public static main(String[] args) {

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0
11 changes: 11 additions & 0 deletions Compiler/testdata/parser5/methods/main/NoArrayParameter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* comma after last parameter
*/

class Error {


public static void main(String args{

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0
11 changes: 11 additions & 0 deletions Compiler/testdata/parser5/methods/main/WrongParameterType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* comma after last parameter
*/

class Error {


public static void main(Hans[] args{

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0
1 change: 1 addition & 0 deletions Compiler/tests/compiler/parser/ParserOutputTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public void testParserFiles() throws Exception {
}

private static void testSourceFile(Path sourceFile, Path parserFile) throws Exception {
System.out.println("Testing parsing of " + sourceFile);
// read expected output
List<String> expectedOutput = Files.readAllLines(parserFile, StandardCharsets.US_ASCII);
Parser parser = TestUtils.initParser(sourceFile);
Expand Down
9 changes: 8 additions & 1 deletion Compiler/tests/compiler/parser/ParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,18 @@ public void testParseEmptyFile() throws IOException, ParserException {
}

@Test
public void testParseWrongClassDeclarationStart() throws IOException, ParserException {
public void testParseOnlyIntToken() throws IOException, ParserException {
int errors = parseWithEof(TokenType.INT);
assertEquals(1, errors);
}

@Test
public void testParseCurlyBracketClassName() throws IOException, ParserException {
int errors = parseWithEof(TokenType.CLASS, TokenType.RCURLYBRACKET, TokenType.LCURLYBRACKET,
TokenType.RCURLYBRACKET);
assertEquals(2, errors);
}

@Test
public void testParseEmptyClass() throws IOException, ParserException {
parseWithEof( // class Class { }
Expand Down

0 comments on commit ed4de2d

Please sign in to comment.