Added more unit tests

This commit is contained in:
yhirose 2022-06-08 10:25:07 -04:00
parent 1594ee5613
commit 9a9b63ac2c
2 changed files with 24 additions and 6 deletions

View File

@ -976,3 +976,21 @@ TEST(GeneralTest, ParentReferencesShouldNotBeExpired) {
EXPECT_FALSE(ast->nodes[0]->parent.expired()); EXPECT_FALSE(ast->nodes[0]->parent.expired());
} }
TEST(GeneralTest, EndOfInputTest) {
auto parser = peg::parser(R"(
S <- '[[' (!']]' .)* ']]'
)");
auto ret = parser.parse("[[]]]");
EXPECT_FALSE(ret);
}
TEST(GeneralTest, DisableEndOfInputCheckTest) {
auto parser = peg::parser(R"(
S <- '[[' (!']]' .)* ']]' !.
)");
auto ret = parser.parse("[[]]]");
EXPECT_FALSE(ret);
}

View File

@ -1228,7 +1228,7 @@ TEST(DicTest, Dictionary_invalid) {
TEST(ErrorTest, Default_error_handling_1) { TEST(ErrorTest, Default_error_handling_1) {
parser pg(R"( parser pg(R"(
S <- '@' A B S <- '@' A B !.
A <- < [a-z]+ > A <- < [a-z]+ >
B <- 'hello' | 'world' B <- 'hello' | 'world'
%whitespace <- [ ]* %whitespace <- [ ]*
@ -1253,7 +1253,7 @@ TEST(ErrorTest, Default_error_handling_1) {
TEST(ErrorTest, Default_error_handling_2) { TEST(ErrorTest, Default_error_handling_2) {
parser pg(R"( parser pg(R"(
S <- '@' A B S <- '@' A B !.
A <- < [a-z]+ > A <- < [a-z]+ >
B <- 'hello' / 'world' B <- 'hello' / 'world'
%whitespace <- ' '* %whitespace <- ' '*
@ -1279,7 +1279,7 @@ TEST(ErrorTest, Default_error_handling_2) {
TEST(ErrorTest, Default_error_handling_fiblang) { TEST(ErrorTest, Default_error_handling_fiblang) {
parser pg(R"( parser pg(R"(
# Syntax # Syntax
START STATEMENTS START STATEMENTS !.
STATEMENTS (DEFINITION / EXPRESSION)* STATEMENTS (DEFINITION / EXPRESSION)*
DEFINITION 'def' Identifier '(' Identifier ')' EXPRESSION DEFINITION 'def' Identifier '(' Identifier ')' EXPRESSION
EXPRESSION TERNARY EXPRESSION TERNARY
@ -1326,7 +1326,7 @@ for n frm 1 to 30
TEST(ErrorTest, Error_recovery_1) { TEST(ErrorTest, Error_recovery_1) {
parser pg(R"( parser pg(R"(
START <- __? SECTION* START <- __? SECTION* !.
SECTION <- HEADER __ ENTRIES __? SECTION <- HEADER __ ENTRIES __?
@ -1512,7 +1512,7 @@ TEST(ErrorTest, Error_recovery_2) {
TEST(ErrorTest, Error_recovery_3) { TEST(ErrorTest, Error_recovery_3) {
parser pg(R"~( parser pg(R"~(
# Grammar # Grammar
START <- __? SECTION* START <- __? SECTION* !.
SECTION <- HEADER __ ENTRIES __? SECTION <- HEADER __ ENTRIES __?
@ -1723,7 +1723,7 @@ sss | ttt
TEST(ErrorTest, Error_recovery_Java) { TEST(ErrorTest, Error_recovery_Java) {
parser pg(R"( parser pg(R"(
Prog PUBLIC CLASS NAME LCUR PUBLIC STATIC VOID MAIN LPAR STRING LBRA RBRA NAME RPAR BlockStmt RCUR Prog PUBLIC CLASS NAME LCUR PUBLIC STATIC VOID MAIN LPAR STRING LBRA RBRA NAME RPAR BlockStmt RCUR !.
BlockStmt LCUR (Stmt)* RCUR^rcblk BlockStmt LCUR (Stmt)* RCUR^rcblk
Stmt IfStmt / WhileStmt / PrintStmt / DecStmt / AssignStmt / BlockStmt Stmt IfStmt / WhileStmt / PrintStmt / DecStmt / AssignStmt / BlockStmt
IfStmt IF LPAR Exp RPAR Stmt (ELSE Stmt)? IfStmt IF LPAR Exp RPAR Stmt (ELSE Stmt)?