-
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
6 changed files
with
95 additions
and
3 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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
fnc f() int { | ||
} | ||
|
||
f()(); | ||
print(f()); |
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,4 +1,3 @@ | ||
|
||
int i = 0; | ||
|
||
while (i < 0) { | ||
|
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 |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#include <gtest/gtest.h> | ||
#include "Parser.hpp" | ||
|
||
struct FunctionsErrorTest | ||
{ | ||
std::string description; | ||
std::string program; | ||
}; | ||
|
||
void testFunctionsError(const std::vector<FunctionsErrorTest> &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{ | ||
.description = "1. Function declaration without identifier", | ||
.program = "fnc () {}" | ||
}, | ||
FunctionsErrorTest{ | ||
.description = "1. Function declaration without identifier", | ||
.program = "fnc () {}" | ||
}, | ||
FunctionsErrorTest{ | ||
.description = "2. Function declaration without parenthesis", | ||
.program = "fnc f {}" | ||
}, | ||
FunctionsErrorTest{ | ||
.description = "3. Function declaration with already used parameter name", | ||
.program = "fnc f (int x, int x){}" | ||
}, | ||
FunctionsErrorTest{ | ||
.description = "4. Function declaration without close parenthesis", | ||
.program = "fnc f (int x, int y {}" | ||
}, | ||
FunctionsErrorTest{ | ||
.description = "5. Function declaration without body", | ||
.program = "fnc f (int x, int y)" | ||
}, | ||
FunctionsErrorTest{ | ||
.description = "6. Function declaration with return type and without body", | ||
.program = "fnc f (int x, int y) int" | ||
} | ||
}; | ||
|
||
testFunctionsError(testCases); | ||
} | ||
|
||
TEST(ParserTest, CallError) | ||
{ | ||
const std::vector<FunctionsErrorTest> testCases{ | ||
FunctionsErrorTest{ | ||
.description = "1. Missing param or closed parenthesis", | ||
.program = "f(;" | ||
}, | ||
FunctionsErrorTest{ | ||
.description = "2. Missing closed parenthesis", | ||
.program = "f(1, 2;" | ||
}, | ||
FunctionsErrorTest{ | ||
.description = "3. Missing expression after comma", | ||
.program = "f(1, );" | ||
} | ||
}; | ||
|
||
testFunctionsError(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