-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
56 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
fnc f() int { | ||
} | ||
|
||
f()(); | ||
print(f()); | ||
{ | ||
return 1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,6 +46,7 @@ class Token | |
IF, ELSE, | ||
FOR, | ||
FNC, RETURN, | ||
BREAK, CONTINUE, | ||
|
||
// Identifier | ||
IDENTIFIER | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 32 additions & 17 deletions
49
tst/parser/functions_error_test.cpp → tst/parser/parser_error_test.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,75 +1,90 @@ | ||
#include <gtest/gtest.h> | ||
#include "Parser.hpp" | ||
|
||
struct FunctionsErrorTest | ||
struct ParserErrorTest | ||
{ | ||
std::string description; | ||
std::string program; | ||
}; | ||
|
||
void testFunctionsError(const std::vector<FunctionsErrorTest> &testCases) | ||
void testParserError(const std::vector<ParserErrorTest> &testCases) | ||
{ | ||
for (const auto &tc: testCases) { | ||
std::cout << tc.description << std::endl; | ||
|
||
Parser parser; | ||
|
||
EXPECT_THROW(parser.feed(tc.program), SyntaxError); | ||
} | ||
} | ||
|
||
TEST(ParserTest, FunctionsDeclarationError) | ||
{ | ||
const std::vector<FunctionsErrorTest> testCases{ | ||
FunctionsErrorTest{ | ||
const std::vector<ParserErrorTest> testCases{ | ||
ParserErrorTest{ | ||
.description = "1. Function declaration without identifier", | ||
.program = "fnc () {}" | ||
}, | ||
FunctionsErrorTest{ | ||
ParserErrorTest{ | ||
.description = "1. Function declaration without identifier", | ||
.program = "fnc () {}" | ||
}, | ||
FunctionsErrorTest{ | ||
ParserErrorTest{ | ||
.description = "2. Function declaration without parenthesis", | ||
.program = "fnc f {}" | ||
}, | ||
FunctionsErrorTest{ | ||
ParserErrorTest{ | ||
.description = "3. Function declaration with already used parameter name", | ||
.program = "fnc f (int x, int x){}" | ||
}, | ||
FunctionsErrorTest{ | ||
ParserErrorTest{ | ||
.description = "4. Function declaration without close parenthesis", | ||
.program = "fnc f (int x, int y {}" | ||
}, | ||
FunctionsErrorTest{ | ||
ParserErrorTest{ | ||
.description = "5. Function declaration without body", | ||
.program = "fnc f (int x, int y)" | ||
}, | ||
FunctionsErrorTest{ | ||
ParserErrorTest{ | ||
.description = "6. Function declaration with return type and without body", | ||
.program = "fnc f (int x, int y) int" | ||
} | ||
}; | ||
|
||
testFunctionsError(testCases); | ||
testParserError(testCases); | ||
} | ||
|
||
TEST(ParserTest, CallError) | ||
{ | ||
const std::vector<FunctionsErrorTest> testCases{ | ||
FunctionsErrorTest{ | ||
const std::vector<ParserErrorTest> testCases{ | ||
ParserErrorTest{ | ||
.description = "1. Missing param or closed parenthesis", | ||
.program = "f(;" | ||
}, | ||
FunctionsErrorTest{ | ||
ParserErrorTest{ | ||
.description = "2. Missing closed parenthesis", | ||
.program = "f(1, 2;" | ||
}, | ||
FunctionsErrorTest{ | ||
ParserErrorTest{ | ||
.description = "3. Missing expression after comma", | ||
.program = "f(1, );" | ||
} | ||
}; | ||
|
||
testFunctionsError(testCases); | ||
testParserError(testCases); | ||
} | ||
|
||
TEST(ParserTest, BreakContinueError) | ||
{ | ||
const std::vector<ParserErrorTest> testCases{ | ||
ParserErrorTest{ | ||
.description = "1. Missing semi after break", | ||
.program = "break" | ||
}, | ||
ParserErrorTest{ | ||
.description = "2. Missing semi after continue", | ||
.program = "continue" | ||
}, | ||
}; | ||
|
||
testParserError(testCases); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters